From 06f7e3af90bff25122abf388f4731946a56b70a1 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Fri, 27 May 2016 13:33:07 +0200 Subject: [PATCH] Introduce YACA_ERROR_NONE according to ACR. Change-Id: Id1f479603c7c54b9e5d5f187dd632470553aac10 --- api/yaca/yaca_crypto.h | 10 +++--- api/yaca/yaca_digest.h | 6 ++-- api/yaca/yaca_encrypt.h | 14 ++++---- api/yaca/yaca_key.h | 18 +++++----- api/yaca/yaca_seal.h | 12 +++---- api/yaca/yaca_sign.h | 16 ++++----- api/yaca/yaca_simple.h | 14 ++++---- examples/digest.c | 16 ++++----- examples/encrypt.c | 38 ++++++++++----------- examples/encrypt_aes_gcm_ccm.c | 76 +++++++++++++++++++++--------------------- examples/key_exchange.c | 18 +++++----- examples/key_import_export.c | 68 ++++++++++++++++++------------------- examples/key_password.c | 16 ++++----- examples/seal.c | 26 +++++++-------- examples/sign.c | 76 +++++++++++++++++++++--------------------- src/crypto.c | 8 ++--- src/digest.c | 14 ++++---- src/encrypt.c | 24 ++++++------- src/key.c | 60 ++++++++++++++++----------------- src/seal.c | 16 ++++----- src/sign.c | 32 +++++++++--------- src/simple.c | 50 +++++++++++++-------------- 22 files changed, 314 insertions(+), 314 deletions(-) diff --git a/api/yaca/yaca_crypto.h b/api/yaca/yaca_crypto.h index 1fabf47..30c2734 100644 --- a/api/yaca/yaca_crypto.h +++ b/api/yaca/yaca_crypto.h @@ -51,7 +51,7 @@ extern "C" { * * @since_tizen 3.0 * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_exit() */ int yaca_init(void); @@ -122,7 +122,7 @@ void yaca_free(void *ptr); * @param[in,out] data Pointer to the memory to be randomized. * @param[in] data_len Length of the memory to be randomized. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. */ int yaca_rand_bytes(char *data, size_t data_len); @@ -137,7 +137,7 @@ int yaca_rand_bytes(char *data, size_t data_len); * @param[in] value Parameter value. * @param[in] value_len Length of the parameter value. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_ex_param_e, yaca_ctx_get_param() */ int yaca_ctx_set_param(yaca_ctx_h ctx, @@ -156,7 +156,7 @@ int yaca_ctx_set_param(yaca_ctx_h ctx, * @param[out] value Copy of the parameter value (must be freed with yaca_free()). * @param[out] value_len Length of the parameter value will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_ex_param_e, yaca_ctx_set_param() */ int yaca_ctx_get_param(const yaca_ctx_h ctx, @@ -220,7 +220,7 @@ int yaca_get_output_length(const yaca_ctx_h ctx, size_t input_len, size_t *outpu * @param[in] second Pointer to the second buffer. * @param[in] len Length to compare. * - * @return 0 when buffers are equal otherwise #YACA_ERROR_DATA_MISMATCH + * @return YACA_ERROR_NONE when buffers are equal otherwise #YACA_ERROR_DATA_MISMATCH */ int yaca_memcmp(const void *first, const void *second, size_t len); diff --git a/api/yaca/yaca_digest.h b/api/yaca/yaca_digest.h index cb27246..2c7be86 100644 --- a/api/yaca/yaca_digest.h +++ b/api/yaca/yaca_digest.h @@ -47,7 +47,7 @@ extern "C" { * @param[out] ctx Newly created context (must be freed with yaca_ctx_free()). * @param[in] algo Digest algorithm that will be used. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_digest_algo_e, yaca_digest_update(), yaca_digest_final() */ int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo); @@ -61,7 +61,7 @@ int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo); * @param[in] data Data from which the digest is to be calculated. * @param[in] data_len Length of the data. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_digest_init(), yaca_digest_final() */ int yaca_digest_update(yaca_ctx_h ctx, const char *data, size_t data_len); @@ -76,7 +76,7 @@ int yaca_digest_update(yaca_ctx_h ctx, const char *data, size_t data_len); * see yaca_get_digest_length()). * @param[out] digest_len Length of the digest, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_digest_init(), yaca_digest_update() */ int yaca_digest_final(yaca_ctx_h ctx, char *digest, size_t *digest_len); diff --git a/api/yaca/yaca_encrypt.h b/api/yaca/yaca_encrypt.h index 94bedff..cba5332 100644 --- a/api/yaca/yaca_encrypt.h +++ b/api/yaca/yaca_encrypt.h @@ -50,7 +50,7 @@ extern "C" { * @param[in] sym_key Symmetric key that will be used. * @param[in] iv Initialization vector that will be used. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_encrypt_update(), yaca_encrypt_final() */ int yaca_encrypt_init(yaca_ctx_h *ctx, @@ -71,7 +71,7 @@ int yaca_encrypt_init(yaca_ctx_h *ctx, * yaca_get_output_length()). * @param[out] cipher_len Length of the encrypted data, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_encrypt_init(), yaca_encrypt_final() */ int yaca_encrypt_update(yaca_ctx_h ctx, @@ -90,7 +90,7 @@ int yaca_encrypt_update(yaca_ctx_h ctx, * yaca_get_block_length()). * @param[out] cipher_len Length of the final piece, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_encrypt_init(), yaca_encrypt_update() */ int yaca_encrypt_final(yaca_ctx_h ctx, @@ -108,7 +108,7 @@ int yaca_encrypt_final(yaca_ctx_h ctx, * @param[in] sym_key Symmetric key that was used to encrypt the data. * @param[in] iv Initialization vector that was used to encrypt the data. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_decrypt_update(), yaca_decrypt_final() */ int yaca_decrypt_init(yaca_ctx_h *ctx, @@ -129,7 +129,7 @@ int yaca_decrypt_init(yaca_ctx_h *ctx, * yaca_get_output_length()). * @param[out] plain_len Length of the decrypted data, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_decrypt_init(), yaca_decrypt_final() */ int yaca_decrypt_update(yaca_ctx_h ctx, @@ -148,7 +148,7 @@ int yaca_decrypt_update(yaca_ctx_h ctx, * yaca_get_block_length()). * @param[out] plain_len Length of the final piece, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_decrypt_init(), yaca_decrypt_update() */ int yaca_decrypt_final(yaca_ctx_h ctx, @@ -168,7 +168,7 @@ int yaca_decrypt_final(yaca_ctx_h ctx, * @param[in] key_bits Key length in bits. * @param[out] iv_bits Recommended IV length in bits. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. */ int yaca_get_iv_bits(yaca_enc_algo_e algo, yaca_block_cipher_mode_e bcm, diff --git a/api/yaca/yaca_key.h b/api/yaca/yaca_key.h index 4c4642c..4786d9a 100755 --- a/api/yaca/yaca_key.h +++ b/api/yaca/yaca_key.h @@ -51,7 +51,7 @@ extern "C" { * @param[in] key Key which type we return. * @param[out] key_type Key type. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. */ int yaca_key_get_type(const yaca_key_h key, yaca_key_type_e *key_type); @@ -63,7 +63,7 @@ int yaca_key_get_type(const yaca_key_h key, yaca_key_type_e *key_type); * @param[in] key Key which length we return. * @param[out] key_bits Key length in bits. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. */ int yaca_key_get_bits(const yaca_key_h key, size_t *key_bits); @@ -94,7 +94,7 @@ int yaca_key_get_bits(const yaca_key_h key, size_t *key_bits); * @param[in] data Blob containing the key. * @param[in] data_len Size of the blob. * - * @return 0 on success, YACA_ERROR_PASSWORD_INVALID if wrong password given, + * @return YACA_ERROR_NONE on success, YACA_ERROR_PASSWORD_INVALID if wrong password given, * negative on error. * @see #yaca_key_type_e, yaca_key_export(), yaca_key_free() */ @@ -136,7 +136,7 @@ int yaca_key_import(yaca_key_h *key, * (must be freed with yaca_free()). * @param[out] data_len Size of the output data. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_fmt_e, #yaca_key_file_fmt_e, yaca_key_import(), yaca_key_free() */ int yaca_key_export(const yaca_key_h key, @@ -157,7 +157,7 @@ int yaca_key_export(const yaca_key_h key, * @param[in] key_type Type of the key to be generated. * @param[in] key_bits Length of the key (in bits) to be generated. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_key_bits_e, yaca_key_free() */ int yaca_key_gen(yaca_key_h *key, @@ -172,7 +172,7 @@ int yaca_key_gen(yaca_key_h *key, * @param[in] prv_key Private key to extract the public one from. * @param[out] pub_key Extracted public key (must be freed with yaca_key_free()). * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_key_gen(), yaca_key_import(), yaca_key_free() */ int yaca_key_extract_public(const yaca_key_h prv_key, yaca_key_h *pub_key); @@ -206,7 +206,7 @@ void yaca_key_free(yaca_key_h key); * @param[out] sym_key Shared secret, that can be used as a symmetric key * (must be freed with yaca_key_free()). * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. */ int yaca_key_derive_dh(const yaca_key_h prv_key, const yaca_key_h pub_key, @@ -224,7 +224,7 @@ int yaca_key_derive_dh(const yaca_key_h prv_key, * @param[out] sym_key Shared secret, that can be used as a symmetric key * (must be freed with yaca_key_free()). * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. */ int yaca_key_derive_kea(const yaca_key_h prv_key, const yaca_key_h pub_key, @@ -245,7 +245,7 @@ int yaca_key_derive_kea(const yaca_key_h prv_key, * @param[in] key_bits Length of a key (in bits) to be generated. * @param[out] key Newly generated key (must be freed with yaca_key_free()). * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. */ int yaca_key_derive_pbkdf2(const char *password, const char *salt, diff --git a/api/yaca/yaca_seal.h b/api/yaca/yaca_seal.h index 0b7f808..81cd401 100644 --- a/api/yaca/yaca_seal.h +++ b/api/yaca/yaca_seal.h @@ -56,7 +56,7 @@ extern "C" { * @param[out] sym_key Generated symmetric key that will be used. It is encrypted with peer's public key. * @param[out] iv Generated initialization vector that will be used. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_seal_update(), yaca_seal_final() */ int yaca_seal_init(yaca_ctx_h *ctx, @@ -79,7 +79,7 @@ int yaca_seal_init(yaca_ctx_h *ctx, * yaca_get_output_length()). * @param[out] cipher_len Length of the encrypted data, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_seal_init(), yaca_seal_final() */ int yaca_seal_update(yaca_ctx_h ctx, @@ -98,7 +98,7 @@ int yaca_seal_update(yaca_ctx_h ctx, * yaca_get_block_length()). * @param[out] cipher_len Length of the final piece, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_seal_init(), yaca_seal_update() */ int yaca_seal_final(yaca_ctx_h ctx, @@ -118,7 +118,7 @@ int yaca_seal_final(yaca_ctx_h ctx, * @param[in] sym_key Symmetric key, encrypted with the public key, that was used to encrypt the data. * @param[in] iv Initialization vector that was used for the encryption. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_open_update(), yaca_open_final() */ int yaca_open_init(yaca_ctx_h *ctx, @@ -141,7 +141,7 @@ int yaca_open_init(yaca_ctx_h *ctx, * yaca_get_output_length()). * @param[out] plain_len Length of the decrypted data, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_open_init(), yaca_open_final() */ int yaca_open_update(yaca_ctx_h ctx, @@ -160,7 +160,7 @@ int yaca_open_update(yaca_ctx_h ctx, * yaca_get_block_length()). * @param[out] plain_len Length of the final piece, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_open_init(), yaca_open_update() */ int yaca_open_final(yaca_ctx_h ctx, diff --git a/api/yaca/yaca_sign.h b/api/yaca/yaca_sign.h index 9deebec..d8098c6 100644 --- a/api/yaca/yaca_sign.h +++ b/api/yaca/yaca_sign.h @@ -56,7 +56,7 @@ extern "C" { * - #YACA_KEY_TYPE_DSA_PRIV, * - #YACA_KEY_TYPE_EC_PRIV. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_sign_update(), * yaca_sign_final(), yaca_verify_init(), yaca_verify_update(), * yaca_verify_final() @@ -79,7 +79,7 @@ int yaca_sign_init(yaca_ctx_h *ctx, * - #YACA_KEY_TYPE_SYMMETRIC, * - #YACA_KEY_TYPE_DES. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_sign_update(), * yaca_sign_final(), yaca_memcmp() */ @@ -101,7 +101,7 @@ int yaca_sign_hmac_init(yaca_ctx_h *ctx, * - #YACA_KEY_TYPE_SYMMETRIC, * - #YACA_KEY_TYPE_DES. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_enc_algo_e, yaca_sign_update(), * yaca_sign_final(), yaca_memcmp() */ @@ -119,7 +119,7 @@ int yaca_sign_cmac_init(yaca_ctx_h *ctx, * @param[in] data Data to be signed. * @param[in] data_len Length of the data. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_sign_init(), yaca_sign_final(), yaca_sign_hmac_init(), * yaca_sign_cmac_init() */ @@ -138,7 +138,7 @@ int yaca_sign_update(yaca_ctx_h ctx, * @param[out] signature_len Length of the MAC or the signature, * actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_sign_init(), yaca_sign_update(), yaca_sign_hmac_init(), * yaca_sign_cmac_init() */ @@ -159,7 +159,7 @@ int yaca_sign_final(yaca_ctx_h ctx, * - #YACA_KEY_TYPE_DSA_PUB, * - #YACA_KEY_TYPE_EC_PUB. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_verify_update(), * yaca_verify_final() */ @@ -176,7 +176,7 @@ int yaca_verify_init(yaca_ctx_h *ctx, * @param[in] data Data to be verified. * @param[in] data_len Length of the data. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_verify_init(), yaca_verify_final() */ int yaca_verify_update(yaca_ctx_h ctx, @@ -192,7 +192,7 @@ int yaca_verify_update(yaca_ctx_h ctx, * @param[in] signature Input signature (returned by yaca_sign_final()). * @param[in] signature_len Size of the signature. * - * @return 0 on success, YACA_ERROR_DATA_MISMATCH if verification fails, + * @return YACA_ERROR_NONE on success, YACA_ERROR_DATA_MISMATCH if verification fails, * negative on error. * @see yaca_verify_init(), yaca_verify_update() */ diff --git a/api/yaca/yaca_simple.h b/api/yaca/yaca_simple.h index f743de2..e50f7b2 100644 --- a/api/yaca/yaca_simple.h +++ b/api/yaca/yaca_simple.h @@ -59,7 +59,7 @@ extern "C" { * (should be freed with yaca_free()). * @param[out] digest_len Length of message digest (depends on algorithm). * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_digest_algo_e */ int yaca_digest_calc(yaca_digest_algo_e algo, @@ -83,7 +83,7 @@ int yaca_digest_calc(yaca_digest_algo_e algo, * (should be freed with yaca_free()). * @param[out] cipher_len Length of the encrypted data (may be larger than decrypted). * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_decrypt() */ int yaca_encrypt(yaca_enc_algo_e algo, @@ -110,7 +110,7 @@ int yaca_encrypt(yaca_enc_algo_e algo, * (should be freed with yaca_free()). * @param[out] plain_len Length of the decrypted data. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_encrypt() */ int yaca_decrypt(yaca_enc_algo_e algo, @@ -139,7 +139,7 @@ int yaca_decrypt(yaca_enc_algo_e algo, * library. Should be freed with yaca_free(). * @param[out] signature_len Length of the signature. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_verify(), */ int yaca_sign(yaca_digest_algo_e algo, @@ -165,7 +165,7 @@ int yaca_sign(yaca_digest_algo_e algo, * @param[in] signature Message signature. * @param[in] signature_len Length of the signature. * - * @return 0 on success, YACA_ERROR_SIGNATURE_INVALID if verification fails, + * @return YACA_ERROR_NONE on success, YACA_ERROR_SIGNATURE_INVALID if verification fails, * negative on error. * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_sign(), */ @@ -194,7 +194,7 @@ int yaca_verify(yaca_digest_algo_e algo, * with yaca_free(). * @param[out] mac_len Length of the MAC. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_memcmp() */ int yaca_hmac(yaca_digest_algo_e algo, @@ -222,7 +222,7 @@ int yaca_hmac(yaca_digest_algo_e algo, * with yaca_free(). * @param[out] mac_len Length of the MAC. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_enc_algo_e, yaca_memcmp() */ int yaca_cmac(yaca_enc_algo_e algo, diff --git a/examples/digest.c b/examples/digest.c index 685bd8a..e4699e9 100644 --- a/examples/digest.c +++ b/examples/digest.c @@ -32,14 +32,14 @@ void digest_simple(void) { - int ret = 0; + int ret = YACA_ERROR_NONE; char *digest; size_t digest_len; ret = yaca_digest_calc(YACA_DIGEST_SHA256, lorem1024, 1024, &digest, &digest_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return; dump_hex(digest, digest_len, "Message digest: "); @@ -49,27 +49,27 @@ void digest_simple(void) void digest_advanced(void) { - int ret = 0; + int ret = YACA_ERROR_NONE; yaca_ctx_h ctx; ret = yaca_digest_init(&ctx, YACA_DIGEST_SHA256); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return; ret = yaca_digest_update(ctx, lorem1024, 1024); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit_ctx; size_t digest_len; ret = yaca_get_digest_length(ctx, &digest_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit_ctx; { char digest[digest_len]; ret = yaca_digest_final(ctx, digest, &digest_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit_ctx; dump_hex(digest, digest_len, "Message digest: "); @@ -84,7 +84,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; digest_simple(); diff --git a/examples/encrypt.c b/examples/encrypt.c index 0ee5e42..ca84b1c 100644 --- a/examples/encrypt.c +++ b/examples/encrypt.c @@ -50,21 +50,21 @@ void encrypt_simple(const yaca_enc_algo_e algo, /* Key generation */ if (yaca_key_derive_pbkdf2("foo bar", "123456789", 10, 1000, - YACA_DIGEST_SHA256, key_bits, &key) != 0) + YACA_DIGEST_SHA256, key_bits, &key) != YACA_ERROR_NONE) return; - if (yaca_get_iv_bits(algo, bcm, key_bits, &iv_bits) != 0) + if (yaca_get_iv_bits(algo, bcm, key_bits, &iv_bits) != YACA_ERROR_NONE) goto exit; - if (iv_bits > 0 && yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != 0) + if (iv_bits > 0 && yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != YACA_ERROR_NONE) goto exit; - if (yaca_encrypt(algo, bcm, key, iv, lorem4096, LOREM4096_SIZE, &enc, &enc_size) != 0) + if (yaca_encrypt(algo, bcm, key, iv, lorem4096, LOREM4096_SIZE, &enc, &enc_size) != YACA_ERROR_NONE) goto exit; dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size); - if (yaca_decrypt(algo, bcm, key, iv, enc, enc_size, &dec, &dec_size) != 0) + if (yaca_decrypt(algo, bcm, key, iv, enc, enc_size, &dec, &dec_size) != YACA_ERROR_NONE) goto exit; printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_size, dec); @@ -100,24 +100,24 @@ void encrypt_advanced(const yaca_enc_algo_e algo, printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096); /* Key generation */ - if (yaca_key_gen(&key, key_type, key_bits) != 0) + if (yaca_key_gen(&key, key_type, key_bits) != YACA_ERROR_NONE) return; - if (yaca_get_iv_bits(algo, bcm, key_bits, &iv_bits) != 0) + if (yaca_get_iv_bits(algo, bcm, key_bits, &iv_bits) != YACA_ERROR_NONE) goto ex_key; - if (iv_bits > 0 && yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != 0) + if (iv_bits > 0 && yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != YACA_ERROR_NONE) goto ex_key; /* Encryption */ { - if (yaca_encrypt_init(&ctx, algo, bcm, key, iv) != 0) + if (yaca_encrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE) goto ex_iv; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto ex_ctx; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto ex_ctx; /* Calculate max output: size of update + final chunks */ @@ -126,11 +126,11 @@ void encrypt_advanced(const yaca_enc_algo_e algo, goto ex_ctx; out_size = enc_size; - if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != 0) + if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != YACA_ERROR_NONE) goto ex_of; rem = enc_size - out_size; - if (yaca_encrypt_final(ctx, enc + out_size, &rem) != 0) + if (yaca_encrypt_final(ctx, enc + out_size, &rem) != YACA_ERROR_NONE) goto ex_of; enc_size = rem + out_size; @@ -143,13 +143,13 @@ void encrypt_advanced(const yaca_enc_algo_e algo, /* Decryption */ { - if (yaca_decrypt_init(&ctx, algo, bcm, key, iv) != 0) + if (yaca_decrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE) goto ex_of; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto ex_of; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto ex_of; /* Calculate max output: size of update + final chunks */ @@ -158,11 +158,11 @@ void encrypt_advanced(const yaca_enc_algo_e algo, goto ex_of; out_size = dec_size; - if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != 0) + if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != YACA_ERROR_NONE) goto ex_in; rem = dec_size - out_size; - if (yaca_decrypt_final(ctx, dec + out_size, &rem) != 0) + if (yaca_decrypt_final(ctx, dec + out_size, &rem) != YACA_ERROR_NONE) goto ex_in; dec_size = rem + out_size; @@ -187,7 +187,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; yaca_enc_algo_e algo = YACA_ENC_AES; diff --git a/examples/encrypt_aes_gcm_ccm.c b/examples/encrypt_aes_gcm_ccm.c index 7fe5305..00cffca 100644 --- a/examples/encrypt_aes_gcm_ccm.c +++ b/examples/encrypt_aes_gcm_ccm.c @@ -63,17 +63,17 @@ void encrypt_decrypt_aes_gcm(void) printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096); /* Key generation */ - if (yaca_key_gen(&key, key_type, key_bits) != 0) + if (yaca_key_gen(&key, key_type, key_bits) != YACA_ERROR_NONE) return; /* IV generation */ - if (yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != 0) + if (yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != YACA_ERROR_NONE) goto clean; if ((aad = yaca_zalloc(aad_size)) == NULL) goto clean; - if (yaca_rand_bytes(aad, aad_size) != 0) + if (yaca_rand_bytes(aad, aad_size) != YACA_ERROR_NONE) goto clean; if ((tag = yaca_zalloc(tag_size)) == NULL) @@ -81,17 +81,17 @@ void encrypt_decrypt_aes_gcm(void) /* Encryption */ { - if (yaca_encrypt_init(&ctx, algo, bcm, key, iv) != 0) + if (yaca_encrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE) goto clean; /* Provide any AAD data */ - if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_AAD, aad, aad_size) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_AAD, aad, aad_size) != YACA_ERROR_NONE) goto clean; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto clean; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto clean; /* Calculate max output: size of update + final chunks */ @@ -100,21 +100,21 @@ void encrypt_decrypt_aes_gcm(void) goto clean; out_size = enc_size; - if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != 0) + if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != YACA_ERROR_NONE) goto clean; rem = enc_size - out_size; - if (yaca_encrypt_final(ctx, enc + out_size, &rem) != 0) + if (yaca_encrypt_final(ctx, enc + out_size, &rem) != YACA_ERROR_NONE) goto clean; enc_size = rem + out_size; /* Set the tag length and get the tag after final encryption */ if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_TAG_LEN, - (void*)&tag_size, sizeof(tag_size)) != 0) + (void*)&tag_size, sizeof(tag_size)) != YACA_ERROR_NONE) goto clean; - if (yaca_ctx_get_param(ctx, YACA_PARAM_GCM_TAG, (void**)tag, &tag_size) != 0) + if (yaca_ctx_get_param(ctx, YACA_PARAM_GCM_TAG, (void**)tag, &tag_size) != YACA_ERROR_NONE) goto clean; dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size); @@ -125,17 +125,17 @@ void encrypt_decrypt_aes_gcm(void) /* Decryption */ { - if (yaca_decrypt_init(&ctx, algo, bcm, key, iv) != 0) + if (yaca_decrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE) goto clean; /* Provide any AAD data */ - if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_AAD, aad, aad_size) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_AAD, aad, aad_size) != YACA_ERROR_NONE) goto clean; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto clean; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto clean; /* Calculate max output: size of update + final chunks */ @@ -144,16 +144,16 @@ void encrypt_decrypt_aes_gcm(void) goto clean; out_size = dec_size; - if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != 0) + if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != YACA_ERROR_NONE) goto clean; rem = dec_size - out_size; /* Set expected tag value before final decryption */ - if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_TAG, tag, tag_size) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_TAG, tag, tag_size) != YACA_ERROR_NONE) goto clean; - if (yaca_decrypt_final(ctx, dec + out_size, &rem) != 0) + if (yaca_decrypt_final(ctx, dec + out_size, &rem) != YACA_ERROR_NONE) goto clean; dec_size = rem + out_size; @@ -203,17 +203,17 @@ void encrypt_decrypt_aes_ccm(void) printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096); /* Key generation */ - if (yaca_key_gen(&key, key_type, key_bits) != 0) + if (yaca_key_gen(&key, key_type, key_bits) != YACA_ERROR_NONE) return; /* IV generation */ - if (yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != 0) + if (yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != YACA_ERROR_NONE) goto clean; if ((aad = yaca_zalloc(aad_size)) == NULL) goto clean; - if (yaca_rand_bytes(aad, aad_size) != 0) + if (yaca_rand_bytes(aad, aad_size) != YACA_ERROR_NONE) goto clean; if ((tag = yaca_zalloc(tag_size)) == NULL) @@ -221,25 +221,25 @@ void encrypt_decrypt_aes_ccm(void) /* Encryption */ { - if (yaca_encrypt_init(&ctx, algo, bcm, key, iv) != 0) + if (yaca_encrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE) goto clean; /* Set tag length (optionally) */ if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_TAG_LEN, - (void*)&tag_size, sizeof(tag_size)) != 0) + (void*)&tag_size, sizeof(tag_size)) != YACA_ERROR_NONE) goto clean; /* The total plain text length must be passed (only needed if AAD is passed) */ - if (yaca_encrypt_update(ctx, NULL, LOREM4096_SIZE , NULL, &len) != 0) + if (yaca_encrypt_update(ctx, NULL, LOREM4096_SIZE , NULL, &len) != YACA_ERROR_NONE) goto clean; - if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_AAD, aad, aad_size) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_AAD, aad, aad_size) != YACA_ERROR_NONE) goto clean; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto clean; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto clean; /* Calculate max output: size of update + final chunks */ @@ -248,17 +248,17 @@ void encrypt_decrypt_aes_ccm(void) goto clean; out_size = enc_size; - if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != 0) + if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != YACA_ERROR_NONE) goto clean; rem = enc_size - out_size; - if (yaca_encrypt_final(ctx, enc + out_size, &rem) != 0) + if (yaca_encrypt_final(ctx, enc + out_size, &rem) != YACA_ERROR_NONE) goto clean; enc_size = rem + out_size; /* Get the tag after final encryption */ - if (yaca_ctx_get_param(ctx, YACA_PARAM_CCM_TAG, (void**)tag, &tag_size) != 0) + if (yaca_ctx_get_param(ctx, YACA_PARAM_CCM_TAG, (void**)tag, &tag_size) != YACA_ERROR_NONE) goto clean; dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size); @@ -269,24 +269,24 @@ void encrypt_decrypt_aes_ccm(void) /* Decryption */ { - if (yaca_decrypt_init(&ctx, algo, bcm, key, iv) != 0) + if (yaca_decrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE) goto clean; /* Set expected tag value */ - if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_TAG, tag, tag_size) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_TAG, tag, tag_size) != YACA_ERROR_NONE) goto clean; /* The total encrypted text length must be passed (only needed if AAD is passed) */ - if (yaca_decrypt_update(ctx, NULL, enc_size , NULL, &len) != 0) + if (yaca_decrypt_update(ctx, NULL, enc_size , NULL, &len) != YACA_ERROR_NONE) goto clean; - if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_AAD, aad, aad_size) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_AAD, aad, aad_size) != YACA_ERROR_NONE) goto clean; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto clean; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto clean; /* Calculate max output: size of update + final chunks */ @@ -297,7 +297,7 @@ void encrypt_decrypt_aes_ccm(void) out_size = dec_size; /* The tag verify is performed when you call the final yaca_decrypt_update(), * there is no call to yaca_decrypt_final() */ - if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != 0) + if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != YACA_ERROR_NONE) goto clean; dec_size = out_size; @@ -320,7 +320,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; encrypt_decrypt_aes_gcm(); diff --git a/examples/key_exchange.c b/examples/key_exchange.c index 80bce46..4bcfce6 100644 --- a/examples/key_exchange.c +++ b/examples/key_exchange.c @@ -45,11 +45,11 @@ void key_exchange_dh(void) // generate private, public key ret = yaca_key_gen(&private_key, YACA_KEY_TYPE_DH_PRIV, YACA_KEY_2048BIT); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; ret = yaca_key_extract_public(private_key, &public_key); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; // get peer public key from file @@ -72,12 +72,12 @@ void key_exchange_dh(void) ret = yaca_key_import(&peer_key, YACA_KEY_TYPE_DH_PUB, NULL, buffer, size); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; // derive secret ret = yaca_key_derive_dh(private_key, peer_key, &secret); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; clean: @@ -105,11 +105,11 @@ void key_exchange_ecdh(void) // generate private, public key ret = yaca_key_gen(&private_key, YACA_KEY_TYPE_EC_PRIV, YACA_KEY_CURVE_P256); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; ret = yaca_key_extract_public(private_key, &public_key); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; // get peer public key from file @@ -131,12 +131,12 @@ void key_exchange_ecdh(void) goto clean; ret = yaca_key_import(&peer_key, YACA_KEY_TYPE_EC_PUB, NULL, buffer, size); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; // derive secret ret = yaca_key_derive_dh(private_key, peer_key, &secret); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; clean: @@ -154,7 +154,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; key_exchange_dh(); diff --git a/examples/key_import_export.c b/examples/key_import_export.c index 6b647fd..0a79fdf 100644 --- a/examples/key_import_export.c +++ b/examples/key_import_export.c @@ -46,10 +46,10 @@ int key_import_export_sym(yaca_key_h sym) /* BASE64 */ ret = yaca_key_export(sym, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_BASE64, NULL, &b64, &b64_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = yaca_key_import(&b64_imported, YACA_KEY_TYPE_SYMMETRIC, NULL, b64, b64_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\n\t***** BASE64 exported key: *****\n%.*s\n", (int)b64_len, b64); @@ -57,7 +57,7 @@ int key_import_export_sym(yaca_key_h sym) b64 = NULL; ret = yaca_key_export(b64_imported, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_BASE64, NULL, &b64, &b64_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\t***** BASE64 imported key: *****\n%.*s\n", (int)b64_len, b64); @@ -66,10 +66,10 @@ int key_import_export_sym(yaca_key_h sym) /* RAW */ ret = yaca_key_export(sym, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_RAW, NULL, &raw, &raw_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; ret = yaca_key_import(&raw_imported, YACA_KEY_TYPE_SYMMETRIC, NULL, raw, raw_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; dump_hex(raw, raw_len, "\n\t***** RAW exported key: *****"); @@ -77,12 +77,12 @@ int key_import_export_sym(yaca_key_h sym) raw = NULL; ret = yaca_key_export(raw_imported, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_RAW, NULL, &raw, &raw_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; dump_hex(raw, raw_len, "\t***** RAW imported key: *****"); - ret = 0; + ret = YACA_ERROR_NONE; free: yaca_key_free(raw_imported); @@ -118,10 +118,10 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, /* PEM private */ ret = yaca_key_export(priv, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM, NULL, &pem_prv, &pem_prv_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = yaca_key_import(&pem_prv_imported, priv_type, NULL, pem_prv, pem_prv_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\n\t***** %s PEM exported private key: *****\n%.*s", algo, (int)pem_prv_len, pem_prv); @@ -129,7 +129,7 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, pem_prv = NULL; ret = yaca_key_export(pem_prv_imported, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM, NULL, &pem_prv, &pem_prv_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\t***** %s PEM imported private key: *****\n%.*s", algo, (int)pem_prv_len, pem_prv); @@ -138,10 +138,10 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, /* DER private */ ret = yaca_key_export(priv, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_DER, NULL, &der_prv, &der_prv_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; ret = yaca_key_import(&der_prv_imported, priv_type, NULL, der_prv, der_prv_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; dump_hex(der_prv, der_prv_len, "\n\t***** %s DER exported private key: *****", algo); @@ -149,7 +149,7 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, der_prv = NULL; ret = yaca_key_export(der_prv_imported, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_DER, NULL, &der_prv, &der_prv_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; dump_hex(der_prv, der_prv_len, "\t***** %s DER imported private key: *****", algo); @@ -158,10 +158,10 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, /* PEM public */ ret = yaca_key_export(pub, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM, NULL, &pem_pub, &pem_pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; ret = yaca_key_import(&pem_pub_imported, pub_type, NULL, pem_pub, pem_pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\n\t***** %s PEM exported public key: *****\n%.*s", algo, (int)pem_pub_len, pem_pub); @@ -169,7 +169,7 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, pem_pub = NULL; ret = yaca_key_export(pem_pub_imported, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM, NULL, &pem_pub, &pem_pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\t***** %s PEM imported public key: *****\n%.*s", algo, (int)pem_pub_len, pem_pub); @@ -178,10 +178,10 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, /* DER public */ ret = yaca_key_export(pub, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_DER, NULL, &der_pub, &der_pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; ret = yaca_key_import(&der_pub_imported, pub_type, NULL, der_pub, der_pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; dump_hex(der_pub, der_pub_len, "\n\t***** %s DER exported public key: *****", algo); @@ -189,12 +189,12 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, der_pub = NULL; ret = yaca_key_export(der_pub_imported, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_DER, NULL, &der_pub, &der_pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; dump_hex(der_pub, der_pub_len, "\t***** %s DER imported public key: *****", algo); - ret = 0; + ret = YACA_ERROR_NONE; free: yaca_key_free(der_pub_imported); @@ -217,7 +217,7 @@ int key_import_x509(void) yaca_key_h rsa_pub_from_cert = YACA_KEY_NULL; ret = read_file("x509.crt", &pub, &pub_len); - if (ret != 0) { + if (ret != YACA_ERROR_NONE) { printf("Make sure you copied a x509.crt from yaca_root/examples to your current directory\n"); printf("You can also generate one with:\n"); printf("openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout x509.key -out x509.crt\n"); @@ -225,19 +225,19 @@ int key_import_x509(void) } ret = yaca_key_import(&rsa_pub_from_cert, YACA_KEY_TYPE_RSA_PUB, NULL, pub, pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; yaca_free(pub); pub = NULL; ret = yaca_key_export(rsa_pub_from_cert, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM, NULL, &pub, &pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\n\t***** RSA X509 imported public key: *****\n%.*s", (int)pub_len, pub); - ret = 0; + ret = YACA_ERROR_NONE; free: yaca_key_free(rsa_pub_from_cert); @@ -255,36 +255,36 @@ int main() int ret; ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; yaca_debug_set_error_cb(debug_func); ret = yaca_key_gen(&sym, YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_1024BIT); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; ret = yaca_key_gen(&rsa_priv, YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_1024BIT); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; ret = yaca_key_extract_public(rsa_priv, &rsa_pub); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; ret = yaca_key_gen(&dsa_priv, YACA_KEY_TYPE_DSA_PRIV, YACA_KEY_1024BIT); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; ret = yaca_key_extract_public(dsa_priv, &dsa_pub); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\t***************************************\n"); printf("\t************** SYMMETRIC **************\n"); printf("\t***************************************\n"); ret = key_import_export_sym(sym); - if (ret == 0) + if (ret == YACA_ERROR_NONE) printf("\n\t********* SYMMETRIC - success *********\n\n"); else printf("\n\t********* SYMMETRIC - failure *********\n\n"); @@ -293,7 +293,7 @@ int main() printf("\t***************** RSA *****************\n"); printf("\t***************************************\n"); ret = key_import_export_asym(rsa_priv, rsa_pub, YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_TYPE_RSA_PUB, "RSA"); - if (ret == 0) + if (ret == YACA_ERROR_NONE) printf("\n\t************ RSA - success ************\n\n"); else printf("\n\t************ RSA - failure ************\n\n"); @@ -302,7 +302,7 @@ int main() printf("\t***************** DSA *****************\n"); printf("\t***************************************\n"); ret = key_import_export_asym(dsa_priv, dsa_pub, YACA_KEY_TYPE_DSA_PRIV, YACA_KEY_TYPE_DSA_PUB, "DSA"); - if (ret == 0) + if (ret == YACA_ERROR_NONE) printf("\n\t************ DSA - success ************\n\n"); else printf("\n\t************ DSA - failure ************\n\n"); @@ -311,7 +311,7 @@ int main() printf("\t**************** X509 *****************\n"); printf("\t***************************************\n"); ret = key_import_x509(); - if (ret == 0) + if (ret == YACA_ERROR_NONE) printf("\n\t*********** X509 - success ************\n\n"); else printf("\n\t*********** X509 - failure ************\n\n"); diff --git a/examples/key_password.c b/examples/key_password.c index d76f195..5a79e15 100644 --- a/examples/key_password.c +++ b/examples/key_password.c @@ -37,19 +37,19 @@ int main(int argc, char* argv[]) char *password = NULL; ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; ret = yaca_key_gen(&key, YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_1024BIT); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; ret = read_stdin_line("encryption pass: ", &password); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; ret = yaca_key_export(key, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM, password, &k, &kl); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; yaca_free(password); @@ -60,7 +60,7 @@ int main(int argc, char* argv[]) ret = yaca_key_import(&key, YACA_KEY_TYPE_RSA_PRIV, NULL, k, kl); if (ret == YACA_ERROR_PASSWORD_INVALID) { ret = read_stdin_line("decryption pass: ", &password); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; ret = yaca_key_import(&key, YACA_KEY_TYPE_RSA_PRIV, password, k, kl); @@ -71,14 +71,14 @@ int main(int argc, char* argv[]) password = NULL; } - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; yaca_free(k); k = NULL; ret = yaca_key_export(key, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM, NULL, &k, &kl); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; printf("%.*s", (int)kl, k); @@ -90,5 +90,5 @@ exit: yaca_exit(); - return 0; + return YACA_ERROR_NONE; } diff --git a/examples/seal.c b/examples/seal.c index a2359a7..586874e 100644 --- a/examples/seal.c +++ b/examples/seal.c @@ -56,21 +56,21 @@ void encrypt_seal(void) printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096); /* Generate key pair */ - if (yaca_key_gen(&key_priv, YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_4096BIT) != 0) + if (yaca_key_gen(&key_priv, YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_4096BIT) != YACA_ERROR_NONE) return; - if (yaca_key_extract_public(key_priv, &key_pub) != 0) + if (yaca_key_extract_public(key_priv, &key_pub) != YACA_ERROR_NONE) goto ex_prvk; /* Encrypt a.k.a. seal */ { - if (yaca_seal_init(&ctx, key_pub, algo, bcm, key_bits, &aes_key, &iv) != 0) + if (yaca_seal_init(&ctx, key_pub, algo, bcm, key_bits, &aes_key, &iv) != YACA_ERROR_NONE) goto ex_pubk; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto ex_ak; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto ex_ak; /* Calculate max output: size of update + final chunks */ @@ -80,11 +80,11 @@ void encrypt_seal(void) /* Seal and finalize */ out_size = enc_size; - if (yaca_seal_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != 0) + if (yaca_seal_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != YACA_ERROR_NONE) goto ex_of; rem = enc_size - out_size; - if (yaca_seal_final(ctx, enc + out_size, &rem) != 0) + if (yaca_seal_final(ctx, enc + out_size, &rem) != YACA_ERROR_NONE) goto ex_of; enc_size = rem + out_size; @@ -97,13 +97,13 @@ void encrypt_seal(void) /* Decrypt a.k.a. open */ { - if (yaca_open_init(&ctx, key_priv, algo, bcm, key_bits, aes_key, iv) != 0) + if (yaca_open_init(&ctx, key_priv, algo, bcm, key_bits, aes_key, iv) != YACA_ERROR_NONE) goto ex_of; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto ex_of; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto ex_of; /* Calculate max output: size of update + final chunks */ @@ -113,11 +113,11 @@ void encrypt_seal(void) /* Open and finalize */ out_size = dec_size; - if (yaca_open_update(ctx, enc, enc_size, dec, &out_size) != 0) + if (yaca_open_update(ctx, enc, enc_size, dec, &out_size) != YACA_ERROR_NONE) goto ex_in; rem = dec_size - out_size; - if (yaca_open_final(ctx, dec + out_size, &rem) != 0) + if (yaca_open_final(ctx, dec + out_size, &rem) != YACA_ERROR_NONE) goto ex_in; dec_size = rem + out_size; @@ -144,7 +144,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; encrypt_seal(); diff --git a/examples/sign.c b/examples/sign.c index 48f6dca..d5f65d6 100644 --- a/examples/sign.c +++ b/examples/sign.c @@ -43,10 +43,10 @@ void simple_sign_verify_asym(yaca_key_type_e type, const char *algo) yaca_key_h pub = YACA_KEY_NULL; // GENERATE - if (yaca_key_gen(&prv, type, YACA_KEY_1024BIT) != 0) + if (yaca_key_gen(&prv, type, YACA_KEY_1024BIT) != YACA_ERROR_NONE) return; - if (yaca_key_extract_public(prv, &pub) != 0) + if (yaca_key_extract_public(prv, &pub) != YACA_ERROR_NONE) goto finish; // SIGN @@ -55,7 +55,7 @@ void simple_sign_verify_asym(yaca_key_type_e type, const char *algo) lorem4096, LOREM4096_SIZE, &signature, - &signature_len) != 0) + &signature_len) != YACA_ERROR_NONE) goto finish; dump_hex(signature, signature_len, "[Simple API] %s Signature of lorem4096:", algo); @@ -66,7 +66,7 @@ void simple_sign_verify_asym(yaca_key_type_e type, const char *algo) lorem4096, LOREM4096_SIZE, signature, - signature_len) != 0) + signature_len) != YACA_ERROR_NONE) printf("[Simple API] %s verification failed\n", algo); else printf("[Simple API] %s verification succesful\n", algo); @@ -86,7 +86,7 @@ void simple_sign_verify_hmac(void) yaca_key_h key = YACA_KEY_NULL; // GENERATE - if (yaca_key_gen(&key, YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_256BIT) != 0) + if (yaca_key_gen(&key, YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_256BIT) != YACA_ERROR_NONE) return; // SIGN @@ -95,7 +95,7 @@ void simple_sign_verify_hmac(void) lorem4096, LOREM4096_SIZE, &signature1, - &signature_len) != 0) + &signature_len) != YACA_ERROR_NONE) goto finish; dump_hex(signature1, signature_len, "[Simple API] HMAC Signature of lorem4096:"); @@ -106,10 +106,10 @@ void simple_sign_verify_hmac(void) lorem4096, LOREM4096_SIZE, &signature2, - &signature_len) != 0) + &signature_len) != YACA_ERROR_NONE) goto finish; - if (yaca_memcmp(signature1, signature2, signature_len) != 0) + if (yaca_memcmp(signature1, signature2, signature_len) != YACA_ERROR_NONE) printf("[Simple API] HMAC verification failed\n"); else printf("[Simple API] HMAC verification succesful\n"); @@ -138,7 +138,7 @@ void simple_sign_verify_cmac(void) lorem4096, LOREM4096_SIZE, &signature1, - &signature_len) != 0) + &signature_len) != YACA_ERROR_NONE) goto finish; dump_hex(signature1, signature_len, "[Simple API] CMAC Signature of lorem4096:"); @@ -150,10 +150,10 @@ void simple_sign_verify_cmac(void) lorem4096, LOREM4096_SIZE, &signature2, - &signature_len) != 0) + &signature_len) != YACA_ERROR_NONE) goto finish; - if (yaca_memcmp(signature1, signature2, signature_len) != 0) + if (yaca_memcmp(signature1, signature2, signature_len) != YACA_ERROR_NONE) printf("[Simple API] CMAC verification failed\n"); else printf("[Simple API] CMAC verification succesful\n"); @@ -176,29 +176,29 @@ void sign_verify_asym(yaca_key_type_e type, const char *algo) yaca_padding_e padding = YACA_PADDING_PKCS1_PSS; // GENERATE - if (yaca_key_gen(&prv, type, YACA_KEY_1024BIT) != 0) + if (yaca_key_gen(&prv, type, YACA_KEY_1024BIT) != YACA_ERROR_NONE) return; - if (yaca_key_extract_public(prv, &pub) != 0) + if (yaca_key_extract_public(prv, &pub) != YACA_ERROR_NONE) goto finish; // SIGN - if (yaca_sign_init(&ctx, YACA_DIGEST_SHA512, prv) != 0) + if (yaca_sign_init(&ctx, YACA_DIGEST_SHA512, prv) != YACA_ERROR_NONE) goto finish; - if (yaca_ctx_set_param(ctx, YACA_PARAM_PADDING, (char*)(&padding), sizeof(padding)) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_PADDING, (char*)(&padding), sizeof(padding)) != YACA_ERROR_NONE) goto finish; - if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != 0) + if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != YACA_ERROR_NONE) goto finish; - if (yaca_get_sign_length(ctx, &signature_len) != 0) + if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE) goto finish; if ((signature = yaca_malloc(signature_len)) == NULL) goto finish; - if (yaca_sign_final(ctx, signature, &signature_len) != 0) + if (yaca_sign_final(ctx, signature, &signature_len) != YACA_ERROR_NONE) goto finish; dump_hex(signature, signature_len, "[Advanced API] %s Signature of lorem4096:", algo); @@ -208,16 +208,16 @@ void sign_verify_asym(yaca_key_type_e type, const char *algo) ctx = YACA_CTX_NULL; // VERIFY - if (yaca_verify_init(&ctx, YACA_DIGEST_SHA512, pub) != 0) + if (yaca_verify_init(&ctx, YACA_DIGEST_SHA512, pub) != YACA_ERROR_NONE) goto finish; - if (yaca_ctx_set_param(ctx, YACA_PARAM_PADDING, (char*)(&padding), sizeof(padding)) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_PADDING, (char*)(&padding), sizeof(padding)) != YACA_ERROR_NONE) goto finish; - if (yaca_verify_update(ctx, lorem4096, LOREM4096_SIZE) != 0) + if (yaca_verify_update(ctx, lorem4096, LOREM4096_SIZE) != YACA_ERROR_NONE) goto finish; - if (yaca_verify_final(ctx, signature, signature_len) != 0) + if (yaca_verify_final(ctx, signature, signature_len) != YACA_ERROR_NONE) printf("[Advanced API] %s verification failed\n", algo); else printf("[Advanced API] %s verification succesful\n", algo); @@ -239,23 +239,23 @@ void sign_verify_hmac(void) yaca_key_h key = YACA_KEY_NULL; // GENERATE - if (yaca_key_gen(&key, YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_256BIT) != 0) + if (yaca_key_gen(&key, YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_256BIT) != YACA_ERROR_NONE) return; // SIGN - if (yaca_sign_hmac_init(&ctx, YACA_DIGEST_SHA512, key) != 0) + if (yaca_sign_hmac_init(&ctx, YACA_DIGEST_SHA512, key) != YACA_ERROR_NONE) goto finish; - if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != 0) + if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != YACA_ERROR_NONE) goto finish; - if (yaca_get_sign_length(ctx, &signature_len) != 0) + if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE) goto finish; if ((signature1 = yaca_malloc(signature_len)) == NULL) goto finish; - if (yaca_sign_final(ctx, signature1, &signature_len) != 0) + if (yaca_sign_final(ctx, signature1, &signature_len) != YACA_ERROR_NONE) goto finish; dump_hex(signature1, signature_len, "[Advanced API] HMAC Signature of lorem4096:"); @@ -265,22 +265,22 @@ void sign_verify_hmac(void) ctx = YACA_CTX_NULL; // VERIFY - if (yaca_sign_hmac_init(&ctx, YACA_DIGEST_SHA512, key) != 0) + if (yaca_sign_hmac_init(&ctx, YACA_DIGEST_SHA512, key) != YACA_ERROR_NONE) goto finish; - if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != 0) + if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != YACA_ERROR_NONE) goto finish; - if (yaca_get_sign_length(ctx, &signature_len) != 0) + if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE) goto finish; if ((signature2 = yaca_malloc(signature_len)) == NULL) goto finish; - if (yaca_sign_final(ctx, signature2, &signature_len) != 0) + if (yaca_sign_final(ctx, signature2, &signature_len) != YACA_ERROR_NONE) goto finish; - if (yaca_memcmp(signature1, signature2, signature_len) != 0) + if (yaca_memcmp(signature1, signature2, signature_len) != YACA_ERROR_NONE) printf("[Advanced API] HMAC verification failed\n"); else printf("[Advanced API] HMAC verification succesful\n"); @@ -306,13 +306,13 @@ void sign_verify_cmac(void) return; // SIGN - if (yaca_sign_cmac_init(&ctx, YACA_ENC_AES, key) != 0) + if (yaca_sign_cmac_init(&ctx, YACA_ENC_AES, key) != YACA_ERROR_NONE) goto finish; if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE)) goto finish; - if (yaca_get_sign_length(ctx, &signature_len) != 0) + if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE) goto finish; if ((signature1 = yaca_malloc(signature_len)) == NULL) @@ -328,13 +328,13 @@ void sign_verify_cmac(void) ctx = YACA_CTX_NULL; // VERIFY - if (yaca_sign_cmac_init(&ctx, YACA_ENC_AES, key) != 0) + if (yaca_sign_cmac_init(&ctx, YACA_ENC_AES, key) != YACA_ERROR_NONE) goto finish; if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE)) goto finish; - if (yaca_get_sign_length(ctx, &signature_len) != 0) + if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE) goto finish; if ((signature2 = yaca_malloc(signature_len)) == NULL) @@ -343,7 +343,7 @@ void sign_verify_cmac(void) if (yaca_sign_final(ctx, signature2, &signature_len)) goto finish; - if (yaca_memcmp(signature1, signature2, signature_len) != 0) + if (yaca_memcmp(signature1, signature2, signature_len) != YACA_ERROR_NONE) printf("[Advanced API] CMAC verification failed\n"); else printf("[Advanced API] CMAC verification succesful\n"); @@ -360,7 +360,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; simple_sign_verify_asym(YACA_KEY_TYPE_RSA_PRIV, "RSA"); diff --git a/src/crypto.c b/src/crypto.c index c0ce1f4..3622579 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -84,7 +84,7 @@ API int yaca_init(void) for (int i = 0; i < CRYPTO_num_locks(); i++) { if (pthread_mutex_init(&mutexes[i], NULL) != 0) { - int ret = 0; + int ret = YACA_ERROR_NONE; switch (errno) { case ENOMEM: ret = YACA_ERROR_OUT_OF_MEMORY; @@ -112,7 +112,7 @@ API int yaca_init(void) We should also initialize the entropy for random number generator: https://wiki.openssl.org/index.php/Random_Numbers#Initialization */ - return 0; + return YACA_ERROR_NONE; } API void yaca_exit(void) @@ -166,7 +166,7 @@ API int yaca_rand_bytes(char *data, size_t data_len) return ret; } - return 0; + return YACA_ERROR_NONE; } API int yaca_ctx_set_param(yaca_ctx_h ctx, yaca_ex_param_e param, @@ -207,7 +207,7 @@ API int yaca_get_output_length(const yaca_ctx_h ctx, size_t input_len, size_t *o API int yaca_memcmp(const void *first, const void *second, size_t len) { if (CRYPTO_memcmp(first, second, len) == 0) - return 0; + return YACA_ERROR_NONE; return YACA_ERROR_DATA_MISMATCH; } diff --git a/src/digest.c b/src/digest.c index a7e9bbe..5bb6883 100644 --- a/src/digest.c +++ b/src/digest.c @@ -60,7 +60,7 @@ static int get_digest_output_length(const yaca_ctx_h ctx, size_t input_len, size return YACA_ERROR_INVALID_ARGUMENT; *output_len = EVP_MD_CTX_size(c->mdctx); - return 0; + return YACA_ERROR_NONE; } static void destroy_digest_context(yaca_ctx_h ctx) @@ -76,7 +76,7 @@ static void destroy_digest_context(yaca_ctx_h ctx) int digest_get_algorithm(yaca_digest_algo_e algo, const EVP_MD **md) { - int ret = 0; + int ret = YACA_ERROR_NONE; if (!md) return YACA_ERROR_INVALID_ARGUMENT; @@ -108,7 +108,7 @@ int digest_get_algorithm(yaca_digest_algo_e algo, const EVP_MD **md) break; } - if (ret == 0 && *md == NULL) { + if (ret == YACA_ERROR_NONE && *md == NULL) { ret = YACA_ERROR_INTERNAL; ERROR_DUMP(ret); } @@ -134,7 +134,7 @@ API int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo) nc->ctx.get_output_length = get_digest_output_length; ret = digest_get_algorithm(algo, &md); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; nc->mdctx = EVP_MD_CTX_create(); @@ -153,7 +153,7 @@ API int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo) *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; ctx: EVP_MD_CTX_destroy(nc->mdctx); @@ -177,7 +177,7 @@ API int yaca_digest_update(yaca_ctx_h ctx, const char *data, size_t data_len) return ret; } - return 0; + return YACA_ERROR_NONE; } API int yaca_digest_final(yaca_ctx_h ctx, char *digest, size_t *digest_len) @@ -201,5 +201,5 @@ API int yaca_digest_final(yaca_ctx_h ctx, char *digest, size_t *digest_len) *digest_len = len; - return 0; + return YACA_ERROR_NONE; } diff --git a/src/encrypt.c b/src/encrypt.c index c059c7e..3d83b78 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -96,7 +96,7 @@ static int get_encrypt_output_length(const yaca_ctx_h ctx, size_t input_len, siz *output_len = block_size; } - return 0; + return YACA_ERROR_NONE; } static int set_encrypt_param(yaca_ctx_h ctx, @@ -153,7 +153,7 @@ static int set_encrypt_param(yaca_ctx_h ctx, default: return YACA_ERROR_INVALID_ARGUMENT; } - return 0; + return YACA_ERROR_NONE; } static int get_encrypt_param(const yaca_ctx_h ctx, @@ -197,7 +197,7 @@ static int get_encrypt_param(const yaca_ctx_h ctx, return YACA_ERROR_INVALID_ARGUMENT; break; } - return 0; + return YACA_ERROR_NONE; } static const char *encrypt_algo_to_str(yaca_enc_algo_e algo) @@ -309,7 +309,7 @@ int encrypt_get_algorithm(yaca_enc_algo_e algo, } *cipher = lcipher; - return 0; + return YACA_ERROR_NONE; } static int encrypt_init(yaca_ctx_h *ctx, @@ -349,11 +349,11 @@ static int encrypt_init(yaca_ctx_h *ctx, nc->tag_len = 0; ret = yaca_key_get_bits(sym_key, &key_bits); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; ret = encrypt_get_algorithm(algo, bcm, key_bits, &cipher); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; ret = EVP_CIPHER_iv_length(cipher); @@ -376,7 +376,7 @@ static int encrypt_init(yaca_ctx_h *ctx, goto err_free; } ret = yaca_key_get_bits(iv, &iv_bits_check); - if (ret != 0) { + if (ret != YACA_ERROR_NONE) { ret = YACA_ERROR_INVALID_ARGUMENT; goto err_free; } @@ -463,7 +463,7 @@ static int encrypt_init(yaca_ctx_h *ctx, } *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; err_ctx: EVP_CIPHER_CTX_free(nc->cipher_ctx); @@ -508,7 +508,7 @@ static int encrypt_update(yaca_ctx_h ctx, } *output_len = loutput_len; - return 0; + return YACA_ERROR_NONE; } static int encrypt_final(yaca_ctx_h ctx, @@ -544,7 +544,7 @@ static int encrypt_final(yaca_ctx_h ctx, } *output_len = loutput_len; - return 0; + return YACA_ERROR_NONE; } API int yaca_get_iv_bits(yaca_enc_algo_e algo, @@ -556,7 +556,7 @@ API int yaca_get_iv_bits(yaca_enc_algo_e algo, int ret; ret = encrypt_get_algorithm(algo, bcm, key_bits, &cipher); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = EVP_CIPHER_iv_length(cipher); @@ -566,7 +566,7 @@ API int yaca_get_iv_bits(yaca_enc_algo_e algo, } *iv_bits = ret * 8; - return 0; + return YACA_ERROR_NONE; } API int yaca_encrypt_init(yaca_ctx_h *ctx, diff --git a/src/key.c b/src/key.c index dd4e648..b3e2c07 100755 --- a/src/key.c +++ b/src/key.c @@ -71,7 +71,7 @@ int base64_decode_length(const char *data, size_t data_len, size_t *len) } *len = data_len / 4 * 3 - padded; - return 0; + return YACA_ERROR_NONE; } #define TMP_BUF_LEN 512 @@ -97,7 +97,7 @@ int base64_decode(const char *data, size_t data_len, BIO **output) /* First phase of correctness checking, calculate expected output length */ ret = base64_decode_length(data, data_len, &b64_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; b64 = BIO_new(BIO_f_base64()); @@ -134,7 +134,7 @@ int base64_decode(const char *data, size_t data_len, BIO **output) goto free_bio; } - if (ret == 0) + if (ret == YACA_ERROR_NONE) break; if (BIO_write(dst, tmpbuf, ret) != ret) { @@ -160,7 +160,7 @@ int base64_decode(const char *data, size_t data_len, BIO **output) *output = dst; dst = NULL; - ret = 0; + ret = YACA_ERROR_NONE; free_bio: BIO_free_all(b64); @@ -185,7 +185,7 @@ int import_simple(yaca_key_h *key, struct yaca_key_simple_s *nk = NULL; ret = base64_decode(data, data_len, &decoded); - if (ret == 0) { + if (ret == YACA_ERROR_NONE) { /* Conversion successfull, get the BASE64 */ long len = BIO_get_mem_data(decoded, &key_data); if (len <= 0 || key_data == NULL) { @@ -230,7 +230,7 @@ int import_simple(yaca_key_h *key, nk->key.type = key_type; *key = (yaca_key_h)nk; - ret = 0; + ret = YACA_ERROR_NONE; out: BIO_free_all(decoded); @@ -381,7 +381,7 @@ int import_evp(yaca_key_h *key, (*key)->type = type; pkey = NULL; - ret = 0; + ret = YACA_ERROR_NONE; free: EVP_PKEY_free(pkey); @@ -407,7 +407,7 @@ int export_simple_raw(struct yaca_key_simple_s *simple_key, memcpy(*data, simple_key->d, key_len); *data_len = key_len; - return 0; + return YACA_ERROR_NONE; } int export_simple_base64(struct yaca_key_simple_s *simple_key, @@ -472,7 +472,7 @@ int export_simple_base64(struct yaca_key_simple_s *simple_key, memcpy(*data, bio_data, bio_data_len); *data_len = bio_data_len; - ret = 0; + ret = YACA_ERROR_NONE; free_bio: BIO_free_all(b64); @@ -491,7 +491,7 @@ int export_evp(struct yaca_key_evp_s *evp_key, assert(data != NULL); assert(data_len != NULL); - int ret = 0; + int ret = YACA_ERROR_NONE; BIO *mem; const EVP_CIPHER *enc = NULL; char *bio_data; @@ -604,7 +604,7 @@ int export_evp(struct yaca_key_evp_s *evp_key, memcpy(*data, bio_data, bio_data_len); *data_len = bio_data_len; - ret = 0; + ret = YACA_ERROR_NONE; free_bio: BIO_free_all(mem); @@ -629,11 +629,11 @@ int gen_simple(struct yaca_key_simple_s **out, size_t key_bits) nk->bits = key_bits; ret = yaca_rand_bytes(nk->d, key_byte_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; *out = nk; - return 0; + return YACA_ERROR_NONE; } int gen_simple_des(struct yaca_key_simple_s **out, size_t key_bits) @@ -675,7 +675,7 @@ int gen_simple_des(struct yaca_key_simple_s **out, size_t key_bits) nk->bits = key_bits; *out = nk; - return 0; + return YACA_ERROR_NONE; free_nk: yaca_free(nk); @@ -731,7 +731,7 @@ int gen_evp_rsa(struct yaca_key_evp_s **out, size_t key_bits) *out = nk; nk = NULL; - ret = 0; + ret = YACA_ERROR_NONE; free_ctx: EVP_PKEY_CTX_free(ctx); @@ -811,7 +811,7 @@ int gen_evp_dsa(struct yaca_key_evp_s **out, size_t key_bits) *out = nk; nk = NULL; - ret = 0; + ret = YACA_ERROR_NONE; free_kctx: EVP_PKEY_CTX_free(kctx); @@ -882,7 +882,7 @@ API int yaca_key_get_type(const yaca_key_h key, yaca_key_type_e *key_type) return YACA_ERROR_INVALID_ARGUMENT; *key_type = lkey->type; - return 0; + return YACA_ERROR_NONE; } API int yaca_key_get_bits(const yaca_key_h key, size_t *key_bits) @@ -895,7 +895,7 @@ API int yaca_key_get_bits(const yaca_key_h key, size_t *key_bits) if (simple_key != NULL) { *key_bits = simple_key->bits; - return 0; + return YACA_ERROR_NONE; } if (evp_key != NULL) { @@ -910,7 +910,7 @@ API int yaca_key_get_bits(const yaca_key_h key, size_t *key_bits) } *key_bits = ret; - return 0; + return YACA_ERROR_NONE; } return YACA_ERROR_INVALID_ARGUMENT; @@ -1009,43 +1009,43 @@ API int yaca_key_gen(yaca_key_h *key, case YACA_KEY_TYPE_SYMMETRIC: case YACA_KEY_TYPE_IV: ret = gen_simple(&nk_simple, key_bits); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; nk_simple->key.type = key_type; *key = (yaca_key_h)nk_simple; - return 0; + return YACA_ERROR_NONE; case YACA_KEY_TYPE_DES: ret = gen_simple_des(&nk_simple, key_bits); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; nk_simple->key.type = key_type; *key = (yaca_key_h)nk_simple; - return 0; + return YACA_ERROR_NONE; case YACA_KEY_TYPE_RSA_PRIV: ret = gen_evp_rsa(&nk_evp, key_bits); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; nk_evp->key.type = key_type; *key = (yaca_key_h)nk_evp; - return 0; + return YACA_ERROR_NONE; case YACA_KEY_TYPE_DSA_PRIV: ret = gen_evp_dsa(&nk_evp, key_bits); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; nk_evp->key.type = key_type; *key = (yaca_key_h)nk_evp; - return 0; + return YACA_ERROR_NONE; case YACA_KEY_TYPE_DH_PRIV: case YACA_KEY_TYPE_EC_PRIV: @@ -1113,7 +1113,7 @@ API int yaca_key_extract_public(const yaca_key_h prv_key, yaca_key_h *pub_key) goto free_pkey; } - return 0; + return YACA_ERROR_NONE; free_pkey: EVP_PKEY_free(pkey); @@ -1179,7 +1179,7 @@ API int yaca_key_derive_pbkdf2(const char *password, return YACA_ERROR_TOO_BIG_ARGUMENT; ret = digest_get_algorithm(algo, &md); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; nk = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_byte_len); @@ -1199,7 +1199,7 @@ API int yaca_key_derive_pbkdf2(const char *password, } *key = (yaca_key_h)nk; - return 0; + return YACA_ERROR_NONE; err: yaca_free(nk); return ret; diff --git a/src/seal.c b/src/seal.c index 1dc583e..c17cc5d 100644 --- a/src/seal.c +++ b/src/seal.c @@ -95,7 +95,7 @@ static int get_seal_output_length(const yaca_ctx_h ctx, size_t input_len, size_t *output_len = block_size; } - return 0; + return YACA_ERROR_NONE; } static int seal_init(yaca_ctx_h *ctx, @@ -154,7 +154,7 @@ static int seal_init(yaca_ctx_h *ctx, } ret = encrypt_get_algorithm(algo, bcm, sym_key_bits, &cipher); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_key; ret = EVP_CIPHER_iv_length(cipher); @@ -198,7 +198,7 @@ static int seal_init(yaca_ctx_h *ctx, *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; err_iv: yaca_free(liv); @@ -250,7 +250,7 @@ static int open_init(yaca_ctx_h *ctx, nc->op_type = OP_OPEN; ret = encrypt_get_algorithm(algo, bcm, sym_key_bits, &cipher); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; ret = EVP_CIPHER_iv_length(cipher); @@ -275,7 +275,7 @@ static int open_init(yaca_ctx_h *ctx, // TODO: handling of algorithms with variable IV length ret = yaca_key_get_bits(iv, &iv_bits_check); - if (ret != 0) { + if (ret != YACA_ERROR_NONE) { ret = YACA_ERROR_INVALID_ARGUMENT; goto err_free; } @@ -303,7 +303,7 @@ static int open_init(yaca_ctx_h *ctx, } *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; err_ctx: EVP_CIPHER_CTX_free(nc->cipher_ctx); @@ -343,7 +343,7 @@ static int seal_update(yaca_ctx_h ctx, return ret; } - return 0; + return YACA_ERROR_NONE; } static int seal_final(yaca_ctx_h ctx, @@ -374,7 +374,7 @@ static int seal_final(yaca_ctx_h ctx, return ret; } - return 0; + return YACA_ERROR_NONE; } API int yaca_seal_init(yaca_ctx_h *ctx, diff --git a/src/sign.c b/src/sign.c index bc9b137..6b76062 100644 --- a/src/sign.c +++ b/src/sign.c @@ -92,7 +92,7 @@ static int get_sign_output_length(const yaca_ctx_h ctx, } *output_len = len; - return 0; + return YACA_ERROR_NONE; } static void destroy_sign_context(yaca_ctx_h ctx) @@ -165,7 +165,7 @@ int set_sign_param(yaca_ctx_h ctx, return ret; } - return 0; + return YACA_ERROR_NONE; } int get_sign_param(const yaca_ctx_h ctx, @@ -232,7 +232,7 @@ int get_sign_param(const yaca_ctx_h ctx, memcpy(*value, &padding, sizeof(yaca_padding_e)); *value_len = sizeof(yaca_padding_e); - return 0; + return YACA_ERROR_NONE; } API int yaca_sign_init(yaca_ctx_h *ctx, @@ -271,7 +271,7 @@ API int yaca_sign_init(yaca_ctx_h *ctx, nc->ctx.get_param = get_sign_param; ret = digest_get_algorithm(algo, &md); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free_ctx; nc->mdctx = EVP_MD_CTX_create(); @@ -290,7 +290,7 @@ API int yaca_sign_init(yaca_ctx_h *ctx, *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; free_ctx: yaca_ctx_free((yaca_ctx_h)nc); @@ -333,7 +333,7 @@ API int yaca_sign_hmac_init(yaca_ctx_h *ctx, } ret = digest_get_algorithm(algo, &md); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free_pkey; nc->mdctx = EVP_MD_CTX_create(); @@ -351,7 +351,7 @@ API int yaca_sign_hmac_init(yaca_ctx_h *ctx, } *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; free_pkey: EVP_PKEY_free(pkey); @@ -387,7 +387,7 @@ API int yaca_sign_cmac_init(yaca_ctx_h *ctx, nc->ctx.get_output_length = get_sign_output_length; ret = encrypt_get_algorithm(algo, YACA_BCM_CBC, simple_key->bits, &cipher); - if (ret != 0) { + if (ret != YACA_ERROR_NONE) { goto free_ctx; } @@ -436,7 +436,7 @@ API int yaca_sign_cmac_init(yaca_ctx_h *ctx, // TODO refactor error handling: set mdctx to NULL, set pkey to NULL *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; free_pkey: EVP_PKEY_free(pkey); @@ -466,7 +466,7 @@ API int yaca_sign_update(yaca_ctx_h ctx, return ret; } - return 0; + return YACA_ERROR_NONE; } API int yaca_sign_final(yaca_ctx_h ctx, @@ -487,7 +487,7 @@ API int yaca_sign_final(yaca_ctx_h ctx, return ret; } - return 0; + return YACA_ERROR_NONE; } API int yaca_verify_init(yaca_ctx_h *ctx, @@ -525,7 +525,7 @@ API int yaca_verify_init(yaca_ctx_h *ctx, nc->ctx.get_param = get_sign_param; ret = digest_get_algorithm(algo, &md); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free_ctx; nc->mdctx = EVP_MD_CTX_create(); @@ -544,7 +544,7 @@ API int yaca_verify_init(yaca_ctx_h *ctx, *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; free_ctx: yaca_ctx_free((yaca_ctx_h)nc); @@ -569,7 +569,7 @@ API int yaca_verify_update(yaca_ctx_h ctx, return ret; } - return 0; + return YACA_ERROR_NONE; } API int yaca_verify_final(yaca_ctx_h ctx, @@ -587,9 +587,9 @@ API int yaca_verify_final(yaca_ctx_h ctx, signature_len); if (ret == 1) - return 0; + return YACA_ERROR_NONE; - if (ret == 0) { + if (ret == YACA_ERROR_NONE) { ERROR_CLEAR(); return YACA_ERROR_DATA_MISMATCH; } diff --git a/src/simple.c b/src/simple.c index 04db0fa..3ba93f8 100644 --- a/src/simple.c +++ b/src/simple.c @@ -48,15 +48,15 @@ API int yaca_digest_calc(yaca_digest_algo_e algo, return YACA_ERROR_INVALID_ARGUMENT; ret = yaca_digest_init(&ctx, algo); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = yaca_digest_update(ctx, data, data_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err; ret = yaca_get_digest_length(ctx, &ldigest_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err; ldigest = yaca_malloc(ldigest_len); @@ -64,14 +64,14 @@ API int yaca_digest_calc(yaca_digest_algo_e algo, goto err; ret = yaca_digest_final(ctx, ldigest, &ldigest_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; yaca_ctx_free(ctx); *digest_len = ldigest_len; *digest = ldigest; - return 0; + return YACA_ERROR_NONE; err_free: yaca_free(ldigest); @@ -100,15 +100,15 @@ API int yaca_encrypt(yaca_enc_algo_e algo, return YACA_ERROR_INVALID_ARGUMENT; ret = yaca_encrypt_init(&ctx, algo, bcm, sym_key, iv); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = yaca_get_block_length(ctx, &lcipher_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err; ret = yaca_get_output_length(ctx, plain_len, &out_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err; if (out_len > SIZE_MAX - lcipher_len) { @@ -124,7 +124,7 @@ API int yaca_encrypt(yaca_enc_algo_e algo, out_len = lcipher_len; ret = yaca_encrypt_update(ctx, plain, plain_len, lcipher, &out_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; assert (out_len <= lcipher_len); @@ -132,7 +132,7 @@ API int yaca_encrypt(yaca_enc_algo_e algo, written = out_len; out_len = lcipher_len - written; ret = yaca_encrypt_final(ctx, lcipher + written, &out_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; written += out_len; @@ -148,7 +148,7 @@ API int yaca_encrypt(yaca_enc_algo_e algo, *cipher = rcipher; *cipher_len = written; - return 0; + return YACA_ERROR_NONE; err_free: yaca_free(lcipher); @@ -177,15 +177,15 @@ API int yaca_decrypt(yaca_enc_algo_e algo, return YACA_ERROR_INVALID_ARGUMENT; ret = yaca_decrypt_init(&ctx, algo, bcm, sym_key, iv); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = yaca_get_block_length(ctx, &lplain_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err; ret = yaca_get_output_length(ctx, cipher_len, &out_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err; if (out_len > SIZE_MAX - lplain_len) { @@ -201,7 +201,7 @@ API int yaca_decrypt(yaca_enc_algo_e algo, out_len = lplain_len; ret = yaca_decrypt_update(ctx, cipher, cipher_len, lplain, &out_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; assert(out_len <= lplain_len); @@ -209,7 +209,7 @@ API int yaca_decrypt(yaca_enc_algo_e algo, written = out_len; out_len = lplain_len - written; ret = yaca_decrypt_final(ctx, lplain + written, &out_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; written += out_len; @@ -225,7 +225,7 @@ API int yaca_decrypt(yaca_enc_algo_e algo, *plain = rplain; *plain_len = written; - return 0; + return YACA_ERROR_NONE; err_free: yaca_free(lplain); @@ -243,11 +243,11 @@ static int sign(const yaca_ctx_h ctx, const char *data, size_t data_len, assert(signature_len != NULL); ret = yaca_sign_update(ctx, data, data_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = yaca_get_sign_length(ctx, signature_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; *signature = yaca_malloc(*signature_len); @@ -255,7 +255,7 @@ static int sign(const yaca_ctx_h ctx, const char *data, size_t data_len, return YACA_ERROR_OUT_OF_MEMORY; ret = yaca_sign_final(ctx, *signature, signature_len); - if (ret != 0) { + if (ret != YACA_ERROR_NONE) { yaca_free(*signature); *signature = NULL; } @@ -274,7 +274,7 @@ API int yaca_sign(yaca_digest_algo_e algo, yaca_ctx_h ctx = YACA_CTX_NULL; ret = yaca_sign_init(&ctx, algo, key); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = sign(ctx, data, data_len, signature, signature_len); @@ -295,11 +295,11 @@ API int yaca_verify(yaca_digest_algo_e algo, yaca_ctx_h ctx = YACA_CTX_NULL; ret = yaca_verify_init(&ctx, algo, key); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = yaca_verify_update(ctx, data, data_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free_ctx; ret = yaca_verify_final(ctx, signature, signature_len); @@ -321,7 +321,7 @@ API int yaca_hmac(yaca_digest_algo_e algo, yaca_ctx_h ctx = YACA_CTX_NULL; ret = yaca_sign_hmac_init(&ctx, algo, key); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = sign(ctx, data, data_len, mac, mac_len); @@ -342,7 +342,7 @@ API int yaca_cmac(yaca_enc_algo_e algo, yaca_ctx_h ctx = YACA_CTX_NULL; ret = yaca_sign_cmac_init(&ctx, algo, key); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = sign(ctx, data, data_len, mac, mac_len); -- 2.7.4