2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
28 #include <yaca_types.h>
35 * @defgroup Advanced-Integrity Advanced API for the integrity handling - HMAC, CMAC and digital signature.
42 * @brief Initializes a signature context for asymmetric signatures.
46 * @remarks For verification use yaca_verify_initialize(), yaca_verify_update() and
47 * yaca_verify_finalize() functions with matching public key.
49 * @remarks The @a ctx should be released using yaca_context_destroy()
51 * @param[out] ctx Newly created context
52 * @param[in] algo Digest algorithm that will be used
53 * @param[in] key Private key that will be used, algorithm is deduced based
54 * on key type, supported key types:
55 * - #YACA_KEY_TYPE_RSA_PRIV,
56 * - #YACA_KEY_TYPE_DSA_PRIV,
58 * @return #YACA_ERROR_NONE on success, negative on error
59 * @retval #YACA_ERROR_NONE Successful
60 * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
61 * invalid algo or key)
62 * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
63 * @retval #YACA_ERROR_INTERNAL Internal error
65 * @see #yaca_key_type_e
66 * @see #yaca_digest_algorithm_e
67 * @see yaca_sign_update()
68 * @see yaca_sign_finalize()
69 * @see yaca_verify_initialize()
70 * @see yaca_verify_update()
71 * @see yaca_verify_finalize()
72 * @see yaca_context_destroy()
74 int yaca_sign_initialize(yaca_context_h *ctx,
75 yaca_digest_algorithm_e algo,
76 const yaca_key_h key);
79 * @brief Initializes a signature context for HMAC.
83 * @remarks For verification, calculate message HMAC and compare with received MAC using
86 * @remarks The @a ctx should be released using yaca_context_destroy()
88 * @param[out] ctx Newly created context
89 * @param[in] algo Digest algorithm that will be used
90 * @param[in] key Symmetric key that will be used, supported key types:
91 * - #YACA_KEY_TYPE_SYMMETRIC,
92 * - #YACA_KEY_TYPE_DES
94 * @return #YACA_ERROR_NONE on success, negative on error
95 * @retval #YACA_ERROR_NONE Successful
96 * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
97 * invalid algo or key)
98 * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
99 * @retval #YACA_ERROR_INTERNAL Internal error
101 * @see #yaca_key_type_e
102 * @see #yaca_digest_algorithm_e
103 * @see yaca_sign_update()
104 * @see yaca_sign_finalize()
106 * @see yaca_context_destroy()
108 int yaca_sign_initialize_hmac(yaca_context_h *ctx,
109 yaca_digest_algorithm_e algo,
110 const yaca_key_h key);
113 * @brief Initializes a signature context for CMAC.
117 * @remarks For verification, calculate message CMAC and compare with received MAC using
120 * @remarks The @a ctx should be released using yaca_context_destroy()
122 * @param[out] ctx Newly created context
123 * @param[in] algo Encryption algorithm that will be used
124 * @param[in] key Symmetric key that will be used, supported key types:
125 * - #YACA_KEY_TYPE_SYMMETRIC,
126 * - #YACA_KEY_TYPE_DES
128 * @return #YACA_ERROR_NONE on success, negative on error
129 * @retval #YACA_ERROR_NONE Successful
130 * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
131 * invalid algo or key)
132 * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
133 * @retval #YACA_ERROR_INTERNAL Internal error
135 * @see #yaca_key_type_e
136 * @see #yaca_encrypt_algorithm_e
137 * @see yaca_sign_update()
138 * @see yaca_sign_finalize()
140 * @see yaca_context_destroy()
142 int yaca_sign_initialize_cmac(yaca_context_h *ctx,
143 yaca_encrypt_algorithm_e algo,
144 const yaca_key_h key);
147 * @brief Feeds the data into the digital signature or MAC algorithm.
151 * @param[in,out] ctx Context created by yaca_sign_initialize(),
152 * yaca_sign_initialize_hmac() or yaca_sign_initialize_cmac()
153 * @param[in] data Data to be signed
154 * @param[in] data_len Length of the data
156 * @return #YACA_ERROR_NONE on success, negative on error
157 * @retval #YACA_ERROR_NONE Successful
158 * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0,
160 * @retval #YACA_ERROR_INTERNAL Internal error
162 * @see yaca_sign_initialize()
163 * @see yaca_sign_finalize()
164 * @see yaca_sign_initialize_hmac()
165 * @see yaca_sign_initialize_cmac()
167 int yaca_sign_update(yaca_context_h ctx,
172 * @brief Calculates the final signature or MAC.
176 * @param[in,out] ctx A valid sign context
177 * @param[out] signature Buffer for the MAC or the signature
178 * (must be allocated by client, see yaca_context_get_output_length())
179 * @param[out] signature_len Length of the MAC or the signature,
180 * actual number of bytes written will be returned here
182 * @return #YACA_ERROR_NONE on success, negative on error
183 * @retval #YACA_ERROR_NONE Successful
184 * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
186 * @retval #YACA_ERROR_INTERNAL Internal error
188 * @see yaca_sign_initialize()
189 * @see yaca_sign_update()
190 * @see yaca_sign_initialize_hmac()
191 * @see yaca_sign_initialize_cmac()
192 * @see yaca_context_get_output_length()
194 int yaca_sign_finalize(yaca_context_h ctx,
196 size_t *signature_len);
199 * @brief Initializes a signature verification context for asymmetric signatures
203 * @remarks The @a ctx should be released using yaca_context_destroy()
205 * @param[out] ctx Newly created context
206 * @param[in] algo Digest algorithm that will be used
207 * @param[in] key Public key that will be used, algorithm is deduced based on
208 * key type, supported key types:
209 * - #YACA_KEY_TYPE_RSA_PUB,
210 * - #YACA_KEY_TYPE_DSA_PUB,
212 * @return #YACA_ERROR_NONE on success, negative on error
213 * @retval #YACA_ERROR_NONE Successful
214 * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
215 * invalid algo or key)
216 * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
217 * @retval #YACA_ERROR_INTERNAL Internal error
219 * @see #yaca_key_type_e
220 * @see #yaca_digest_algorithm_e
221 * @see yaca_verify_update()
222 * @see yaca_verify_finalize()
223 * @see yaca_context_destroy()
225 int yaca_verify_initialize(yaca_context_h *ctx,
226 yaca_digest_algorithm_e algo,
227 const yaca_key_h key);
230 * @brief Feeds the data into the digital signature verification algorithm.
234 * @param[in,out] ctx Context created by yaca_verify_initialize()
235 * @param[in] data Data to be verified
236 * @param[in] data_len Length of the data
238 * @return #YACA_ERROR_NONE on success, negative on error
239 * @retval #YACA_ERROR_NONE Successful
240 * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0,
242 * @retval #YACA_ERROR_INTERNAL Internal error
244 * @see yaca_verify_initialize()
245 * @see yaca_verify_finalize()
247 int yaca_verify_update(yaca_context_h ctx,
252 * @brief Performs the verification.
256 * @param[in,out] ctx A valid verify context
257 * @param[in] signature Input signature (returned by yaca_sign_finalize())
258 * @param[in] signature_len Size of the signature
260 * @return #YACA_ERROR_NONE on success, negative on error
261 * @retval #YACA_ERROR_NONE Successful
262 * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
264 * @retval #YACA_ERROR_INTERNAL Internal error
265 * @retval #YACA_ERROR_DATA_MISMATCH The verification failed
267 * @see yaca_verify_initialize()
268 * @see yaca_verify_update()
269 * @see yaca_sign_finalize()
271 int yaca_verify_finalize(yaca_context_h ctx,
272 const char *signature,
273 size_t signature_len);
281 #endif /* YACA_SIGN_H */