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.
37 * TODO: extended description and examples.
38 * TODO: add documentation how to set padding etc
44 * @brief Initializes a signature context for asymmetric signatures.
48 * @remarks For verification use yaca_verify_init(), yaca_verify_update() and
49 * yaca_verify_final() functions with matching public key.
51 * @param[out] ctx Newly created context (must be freed with yaca_ctx_free())
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,
57 * - #YACA_KEY_TYPE_EC_PRIV
59 * @return #YACA_ERROR_NONE on success, negative on error
60 * @retval #YACA_ERROR_NONE Successful
61 * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL,
62 * incorrect algo, invalid key)
63 * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
64 * @retval #YACA_ERROR_INTERNAL Internal error
66 * @see #yaca_key_type_e
67 * @see #yaca_digest_algo_e
68 * @see yaca_sign_update()
69 * @see yaca_sign_final()
70 * @see yaca_verify_init()
71 * @see yaca_verify_update()
72 * @see yaca_verify_final()
74 int yaca_sign_init(yaca_ctx_h *ctx,
75 yaca_digest_algo_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 * @param[out] ctx Newly created context (must be freed with yaca_ctx_free())
87 * @param[in] algo Digest algorithm that will be used
88 * @param[in] key Symmetric key that will be used, supported key types:
89 * - #YACA_KEY_TYPE_SYMMETRIC,
90 * - #YACA_KEY_TYPE_DES
92 * @return #YACA_ERROR_NONE on success, negative on error
93 * @retval #YACA_ERROR_NONE Successful
94 * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL,
95 * incorrect algo, invalid key)
96 * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
97 * @retval #YACA_ERROR_INTERNAL Internal error
99 * @see #yaca_key_type_e
100 * @see #yaca_digest_algo_e
101 * @see yaca_sign_update()
102 * @see yaca_sign_final()
105 int yaca_sign_hmac_init(yaca_ctx_h *ctx,
106 yaca_digest_algo_e algo,
107 const yaca_key_h key);
110 * @brief Initializes a signature context for CMAC.
114 * @remarks For verification, calculate message CMAC and compare with received MAC using
117 * @param[out] ctx Newly created context (must be freed with yaca_ctx_free())
118 * @param[in] algo Encryption algorithm that will be used
119 * @param[in] key Symmetric key that will be used, supported key types:
120 * - #YACA_KEY_TYPE_SYMMETRIC,
121 * - #YACA_KEY_TYPE_DES
123 * @return #YACA_ERROR_NONE on success, negative on error
124 * @retval #YACA_ERROR_NONE Successful
125 * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL,
126 * incorrect algo, invalid key)
127 * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
128 * @retval #YACA_ERROR_INTERNAL Internal error
130 * @see #yaca_key_type_e
131 * @see #yaca_enc_algo_e
132 * @see yaca_sign_update()
133 * @see yaca_sign_final()
136 int yaca_sign_cmac_init(yaca_ctx_h *ctx,
137 yaca_enc_algo_e algo,
138 const yaca_key_h key);
141 * @brief Feeds the data into the digital signature or MAC algorithm.
145 * @param[in,out] ctx Context created by yaca_sign_init(),
146 * yaca_sign_hmac_init() or yaca_sign_cmac_init()
147 * @param[in] data Data to be signed
148 * @param[in] data_len Length of the data
150 * @return #YACA_ERROR_NONE on success, negative on error
151 * @retval #YACA_ERROR_NONE Successful
152 * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, 0,
154 * @retval #YACA_ERROR_INTERNAL Internal error
156 * @see yaca_sign_init()
157 * @see yaca_sign_final()
158 * @see yaca_sign_hmac_init()
159 * @see yaca_sign_cmac_init()
161 int yaca_sign_update(yaca_ctx_h ctx,
166 * @brief Calculates the final signature or MAC.
170 * @param[in,out] ctx A valid sign context
171 * @param[out] signature Buffer for the MAC or the signature
172 * (must be allocated by client, see yaca_get_sign_length())
173 * @param[out] signature_len Length of the MAC or the signature,
174 * actual number of bytes written will be returned here
176 * @return #YACA_ERROR_NONE on success, negative on error
177 * @retval #YACA_ERROR_NONE Successful
178 * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL,
180 * @retval #YACA_ERROR_INTERNAL Internal error
182 * @see yaca_sign_init()
183 * @see yaca_sign_update()
184 * @see yaca_sign_hmac_init()
185 * @see yaca_sign_cmac_init()
187 int yaca_sign_final(yaca_ctx_h ctx,
189 size_t *signature_len);
192 * @brief Initializes a signature verification context for asymmetric signatures
196 * @param[out] ctx Newly created context (must be freed with yaca_ctx_free())
197 * @param[in] algo Digest algorithm that will be used
198 * @param[in] key Public key that will be used, algorithm is deduced based on
199 * key type, supported key types:
200 * - #YACA_KEY_TYPE_RSA_PUB,
201 * - #YACA_KEY_TYPE_DSA_PUB,
202 * - #YACA_KEY_TYPE_EC_PUB
204 * @return #YACA_ERROR_NONE on success, negative on error
205 * @retval #YACA_ERROR_NONE Successful
206 * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL,
207 * incorrect algo, invalid key)
208 * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
209 * @retval #YACA_ERROR_INTERNAL Internal error
211 * @see #yaca_key_type_e
212 * @see #yaca_digest_algo_e
213 * @see yaca_verify_update()
214 * @see yaca_verify_final()
216 int yaca_verify_init(yaca_ctx_h *ctx,
217 yaca_digest_algo_e algo,
218 const yaca_key_h key);
221 * @brief Feeds the data into the digital signature verification algorithm.
225 * @param[in,out] ctx Context created by yaca_verify_init()
226 * @param[in] data Data to be verified
227 * @param[in] data_len Length of the data
229 * @return #YACA_ERROR_NONE on success, negative on error
230 * @retval #YACA_ERROR_NONE Successful
231 * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, 0,
233 * @retval #YACA_ERROR_INTERNAL Internal error
235 * @see yaca_verify_init()
236 * @see yaca_verify_final()
238 int yaca_verify_update(yaca_ctx_h ctx,
243 * @brief Performs the verification.
247 * @param[in,out] ctx A valid verify context
248 * @param[in] signature Input signature (returned by yaca_sign_final())
249 * @param[in] signature_len Size of the signature
251 * @return #YACA_ERROR_NONE on success, negative on error
252 * @retval #YACA_ERROR_NONE Successful
253 * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL,
255 * @retval #YACA_ERROR_INTERNAL Internal error
256 * @retval #YACA_ERROR_DATA_MISMATCH The verification failed
258 * @see yaca_verify_init()
259 * @see yaca_verify_update()
261 int yaca_verify_final(yaca_ctx_h ctx,
262 const char *signature,
263 size_t signature_len);
271 #endif /* YACA_SIGN_H */