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 Simple-API Simple API.
37 * @remarks This is simple API.
39 * - All operations are single-shot (no streaming possible)
40 * - Context is not used
41 * - For now only digest and symmetric ciphers are supported
42 * - GCM and CCM chaining is not supported
43 * - All outputs are allocated by the library
49 * @brief Calculate a digest of a buffer.
53 * @remarks The @a digest should be freed using yaca_free()
55 * @param[in] algo Digest algorithm (select #YACA_DIGEST_SHA256 if unsure)
56 * @param[in] data Data from which the digest is to be calculated
57 * @param[in] data_len Length of the data. Can be 0.
58 * @param[out] digest Message digest, will be allocated by the library
59 * @param[out] digest_len Length of message digest (depends on algorithm)
61 * @return #YACA_ERROR_NONE on success, negative on error
62 * @retval #YACA_ERROR_NONE Successful
63 * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
65 * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
66 * @retval #YACA_ERROR_INTERNAL Internal error
68 * @see #yaca_digest_algorithm_e
71 int yaca_simple_calculate_digest(yaca_digest_algorithm_e algo,
78 * @brief Encrypt data using a symmetric cipher.
82 * @remarks The @a ciphertext should be freed using yaca_free()
84 * @param[in] algo Encryption algorithm (select #YACA_ENCRYPT_AES if unsure)
85 * @param[in] bcm Chaining mode (select #YACA_BCM_CBC if unsure)
86 * @param[in] sym_key Symmetric encryption key (see key.h for key generation functions)
87 * @param[in] iv Initialization vector
88 * @param[in] plaintext Plaintext to be encrypted
89 * @param[in] plaintext_len Length of the plaintext
90 * @param[out] ciphertext Encrypted data, will be allocated by the library
91 * @param[out] ciphertext_len Length of the encrypted data (may be larger than decrypted)
93 * @return #YACA_ERROR_NONE on success, negative on error
94 * @retval #YACA_ERROR_NONE Successful
95 * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0
96 * invalid algo, bcm, sym_key or iv)
97 * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
98 * @retval #YACA_ERROR_INTERNAL Internal error
100 * @see #yaca_encrypt_algorithm_e
101 * @see #yaca_block_cipher_mode_e
102 * @see yaca_simple_decrypt()
105 int yaca_simple_encrypt(yaca_encrypt_algorithm_e algo,
106 yaca_block_cipher_mode_e bcm,
107 const yaca_key_h sym_key,
109 const char *plaintext,
110 size_t plaintext_len,
112 size_t *ciphertext_len);
115 * @brief Decrypt data using a symmetric cipher.
119 * @remarks The @a plaintext should be freed using yaca_free()
121 * @param[in] algo Decryption algorithm that was used to encrypt the data
122 * @param[in] bcm Chaining mode that was used to encrypt the data
123 * @param[in] sym_key Symmetric encryption key that was used to encrypt the data
124 * @param[in] iv Initialization vector that was used to encrypt the data
125 * @param[in] ciphertext Ciphertext to be decrypted
126 * @param[in] ciphertext_len Length of ciphertext
127 * @param[out] plaintext Decrypted data, will be allocated by the library
128 * @param[out] plaintext_len Length of the decrypted data
130 * @return #YACA_ERROR_NONE on success, negative on error
131 * @retval #YACA_ERROR_NONE Successful
132 * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0
133 * invalid algo, bcm, sym_key or iv)
134 * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
135 * @retval #YACA_ERROR_INTERNAL Internal error
137 * @see #yaca_encrypt_algorithm_e
138 * @see #yaca_block_cipher_mode_e
139 * @see yaca_simple_encrypt()
142 int yaca_simple_decrypt(yaca_encrypt_algorithm_e algo,
143 yaca_block_cipher_mode_e bcm,
144 const yaca_key_h sym_key,
146 const char *ciphertext,
147 size_t ciphertext_len,
149 size_t *plaintext_len);
152 * @brief Create a signature using asymmetric private key.
156 * @remarks The @a signature should be freed using yaca_free()
158 * @param[in] algo Digest algorithm that will be used
159 * @param[in] key Private key that will be used, algorithm is
160 * deduced based on key type, supported key types:
161 * - #YACA_KEY_TYPE_RSA_PRIV,
162 * - #YACA_KEY_TYPE_DSA_PRIV,
163 * @param[in] data Data to be signed
164 * @param[in] data_len Length of the data
165 * @param[out] signature Message signature, will be allocated by the
166 * @param[out] signature_len Length of the signature
168 * @return #YACA_ERROR_NONE on success, negative on error
169 * @retval #YACA_ERROR_NONE Successful
170 * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0
171 * invalid algo or key)
172 * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
173 * @retval #YACA_ERROR_INTERNAL Internal error
175 * @see #yaca_key_type_e
176 * @see #yaca_digest_algorithm_e
177 * @see yaca_simple_verify_signature()
180 int yaca_simple_calculate_signature(yaca_digest_algorithm_e algo,
181 const yaca_key_h key,
185 size_t *signature_len);
188 * @brief Verify a signature using asymmetric public key.
192 * @param[in] algo Digest algorithm that will be used
193 * @param[in] key Public key that will be used, algorithm is
194 * deduced based on key type, supported key types:
195 * - #YACA_KEY_TYPE_RSA_PUB,
196 * - #YACA_KEY_TYPE_DSA_PUB,
197 * @param[in] data Signed data
198 * @param[in] data_len Length of the data
199 * @param[in] signature Message signature
200 * @param[in] signature_len Length of the signature
202 * @return #YACA_ERROR_NONE on success, negative on error
203 * @retval #YACA_ERROR_NONE Successful
204 * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0
205 * invalid algo or key)
206 * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
207 * @retval #YACA_ERROR_INTERNAL Internal error
208 * @retval #YACA_ERROR_DATA_MISMATCH The verification failed
210 * @see #yaca_key_type_e
211 * @see #yaca_digest_algorithm_e
212 * @see yaca_simple_calculate_signature()
214 int yaca_simple_verify_signature(yaca_digest_algorithm_e algo,
215 const yaca_key_h key,
218 const char *signature,
219 size_t signature_len);
222 * @brief Calculate a HMAC of given message using symmetric key.
226 * @remarks For verification, calculate message HMAC and compare with received MAC using
229 * @remarks The @a mac should be freed using yaca_free()
231 * @param[in] algo Digest algorithm that will be used
232 * @param[in] key Key that will be used, supported key types:
233 * - #YACA_KEY_TYPE_SYMMETRIC,
234 * - #YACA_KEY_TYPE_DES
235 * @param[in] data Data to calculate HMAC from
236 * @param[in] data_len Length of the data
237 * @param[out] mac MAC, will be allocated by the library
238 * @param[out] mac_len Length of the MAC
240 * @return #YACA_ERROR_NONE on success, negative on error
241 * @retval #YACA_ERROR_NONE Successful
242 * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0
243 * invalid algo or key)
244 * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
245 * @retval #YACA_ERROR_INTERNAL Internal error
247 * @see #yaca_key_type_e
248 * @see #yaca_digest_algorithm_e
252 int yaca_simple_calculate_hmac(yaca_digest_algorithm_e algo,
253 const yaca_key_h key,
260 * @brief Calculate a CMAC of given message using symmetric key.
264 * @remarks For verification, calculate message CMAC and compare with received MAC using
267 * @remarks The @a mac should be freed using yaca_free()
269 * @param[in] algo Encryption algorithm that will be used
270 * @param[in] key Key that will be used, supported key types:
271 * - #YACA_KEY_TYPE_SYMMETRIC,
272 * - #YACA_KEY_TYPE_DES
273 * @param[in] data Data to calculate CMAC from
274 * @param[in] data_len Length of the data
275 * @param[out] mac MAC, will be allocated by the library
276 * @param[out] mac_len Length of the MAC
278 * @return #YACA_ERROR_NONE on success, negative on error
279 * @retval #YACA_ERROR_NONE Successful
280 * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0
281 * invalid algo or key)
282 * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
283 * @retval #YACA_ERROR_INTERNAL Internal error
285 * @see #yaca_key_type_e
286 * @see #yaca_encrypt_algorithm_e
290 int yaca_simple_calculate_cmac(yaca_encrypt_algorithm_e algo,
291 const yaca_key_h key,
303 #endif /* YACA_SIMPLE_H */