Adjust naming convention to API. 01/76301/16
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 5 Jul 2016 07:20:41 +0000 (09:20 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 8 Jul 2016 12:14:25 +0000 (14:14 +0200)
Change-Id: I096c1df2007832e52bc797de88df3dd8c46e67aa

15 files changed:
api/yaca/yaca_key.h
examples/encrypt.c
examples/encrypt_aes_gcm_ccm.c
examples/misc.c
examples/misc.h
examples/seal.c
readme.txt
src/crypto.c
src/digest.c
src/encrypt.c
src/internal.h
src/key.c
src/seal.c
src/sign.c
src/simple.c

index b6294ad..288e6ce 100644 (file)
@@ -241,11 +241,11 @@ int yaca_key_generate(yaca_key_type_e key_type,
 int yaca_key_extract_public(const yaca_key_h prv_key, yaca_key_h *pub_key);
 
 /**
- * @brief  Frees the key created by the library. Passing YACA_KEY_NULL is allowed.
+ * @brief  Release the key created by the library. Passing YACA_KEY_NULL is allowed.
  *
  * @since_tizen 3.0
  *
- * @param[in,out] key  Key to be freed
+ * @param[in,out] key  Key to be released
  *
  * @see yaca_key_import()
  * @see yaca_key_export()
index 426c391..31c8806 100644 (file)
 
 void encrypt_simple(const yaca_encrypt_algorithm_e algo,
                     const yaca_block_cipher_mode_e bcm,
-                    const size_t key_bits)
+                    const size_t key_bit_len)
 {
        yaca_key_h key = YACA_KEY_NULL;
        yaca_key_h iv = YACA_KEY_NULL;
 
        char *enc = NULL;
        char *dec = NULL;
-       size_t enc_size;
-       size_t dec_size;
-       size_t iv_bits;
+       size_t enc_len;
+       size_t dec_len;
+       size_t iv_bit_len;
 
        printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096);
 
        /* Key generation */
        if (yaca_key_derive_pbkdf2("foo bar", "123456789", 10, 1000,
-                                  YACA_DIGEST_SHA256, key_bits, &key) != YACA_ERROR_NONE)
+                                  YACA_DIGEST_SHA256, key_bit_len, &key) != YACA_ERROR_NONE)
                return;
 
-       if (yaca_encrypt_get_iv_bit_length(algo, bcm, key_bits, &iv_bits) != YACA_ERROR_NONE)
+       if (yaca_encrypt_get_iv_bit_length(algo, bcm, key_bit_len, &iv_bit_len) != YACA_ERROR_NONE)
                goto exit;
 
-       if (iv_bits > 0 && yaca_key_generate(YACA_KEY_TYPE_IV, iv_bits, &iv) != YACA_ERROR_NONE)
+       if (iv_bit_len > 0 && yaca_key_generate(YACA_KEY_TYPE_IV, iv_bit_len, &iv) != YACA_ERROR_NONE)
                goto exit;
 
-       if (yaca_simple_encrypt(algo, bcm, key, iv, lorem4096, LOREM4096_SIZE, &enc, &enc_size) != YACA_ERROR_NONE)
+       if (yaca_simple_encrypt(algo, bcm, key, iv, lorem4096, LOREM4096_SIZE, &enc, &enc_len) != YACA_ERROR_NONE)
                goto exit;
 
-       dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size);
+       dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_len);
 
-       if (yaca_simple_decrypt(algo, bcm, key, iv, enc, enc_size, &dec, &dec_size) != YACA_ERROR_NONE)
+       if (yaca_simple_decrypt(algo, bcm, key, iv, enc, enc_len, &dec, &dec_len) != YACA_ERROR_NONE)
                goto exit;
 
-       printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_size, dec);
+       printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_len, dec);
 
 exit:
        yaca_free(enc);
@@ -79,33 +79,33 @@ exit:
 void encrypt_advanced(const yaca_encrypt_algorithm_e algo,
                       const yaca_block_cipher_mode_e bcm,
                       const yaca_key_type_e key_type,
-                      const size_t key_bits)
+                      const size_t key_bit_len)
 {
        yaca_context_h ctx = YACA_CONTEXT_NULL;
        yaca_key_h key = YACA_KEY_NULL;
        yaca_key_h iv = YACA_KEY_NULL;
-       size_t iv_bits;
+       size_t iv_bit_len;
 
        char *enc = NULL;
        char *dec = NULL;
-       size_t enc_size;
-       size_t dec_size;
+       size_t enc_len;
+       size_t dec_len;
 
        size_t block_len;
        size_t output_len;
-       size_t out_size;
+       size_t written_len;
        size_t rem;
 
        printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096);
 
        /* Key generation */
-       if (yaca_key_generate(key_type, key_bits, &key) != YACA_ERROR_NONE)
+       if (yaca_key_generate(key_type, key_bit_len, &key) != YACA_ERROR_NONE)
                return;
 
-       if (yaca_encrypt_get_iv_bit_length(algo, bcm, key_bits, &iv_bits) != YACA_ERROR_NONE)
+       if (yaca_encrypt_get_iv_bit_length(algo, bcm, key_bit_len, &iv_bit_len) != YACA_ERROR_NONE)
                goto exit;
 
-       if (iv_bits > 0 && yaca_key_generate(YACA_KEY_TYPE_IV, iv_bits, &iv) != YACA_ERROR_NONE)
+       if (iv_bit_len > 0 && yaca_key_generate(YACA_KEY_TYPE_IV, iv_bit_len, &iv) != YACA_ERROR_NONE)
                goto exit;
 
        /* Encryption */
@@ -122,21 +122,21 @@ void encrypt_advanced(const yaca_encrypt_algorithm_e algo,
                        goto exit;
 
                /* Calculate max output: size of update + final chunks */
-               enc_size = output_len + block_len;
-               if (yaca_malloc(enc_size, (void**)&enc) != YACA_ERROR_NONE)
+               enc_len = output_len + block_len;
+               if (yaca_malloc(enc_len, (void**)&enc) != YACA_ERROR_NONE)
                        goto exit;
 
-               out_size = enc_size;
-               if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != YACA_ERROR_NONE)
+               written_len = enc_len;
+               if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &written_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               rem = enc_size - out_size;
-               if (yaca_encrypt_finalize(ctx, enc + out_size, &rem) != YACA_ERROR_NONE)
+               rem = enc_len - written_len;
+               if (yaca_encrypt_finalize(ctx, enc + written_len, &rem) != YACA_ERROR_NONE)
                        goto exit;
 
-               enc_size = rem + out_size;
+               enc_len = rem + written_len;
 
-               dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size);
+               dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_len);
 
                yaca_context_destroy(ctx);
                ctx = YACA_CONTEXT_NULL;
@@ -156,21 +156,21 @@ void encrypt_advanced(const yaca_encrypt_algorithm_e algo,
                        goto exit;
 
                /* Calculate max output: size of update + final chunks */
-               dec_size = output_len + block_len;
-               if (yaca_malloc(dec_size, (void**)&dec) != YACA_ERROR_NONE)
+               dec_len = output_len + block_len;
+               if (yaca_malloc(dec_len, (void**)&dec) != YACA_ERROR_NONE)
                        goto exit;
 
-               out_size = dec_size;
-               if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != YACA_ERROR_NONE)
+               written_len = dec_len;
+               if (yaca_decrypt_update(ctx, enc, enc_len, dec, &written_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               rem = dec_size - out_size;
-               if (yaca_decrypt_finalize(ctx, dec + out_size, &rem) != YACA_ERROR_NONE)
+               rem = dec_len - written_len;
+               if (yaca_decrypt_finalize(ctx, dec + written_len, &rem) != YACA_ERROR_NONE)
                        goto exit;
 
-               dec_size = rem + out_size;
+               dec_len = rem + written_len;
 
-               printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_size, dec);
+               printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_len, dec);
        }
 
 exit:
@@ -192,41 +192,41 @@ int main()
        yaca_encrypt_algorithm_e algo = YACA_ENCRYPT_AES;
        yaca_block_cipher_mode_e bcm = YACA_BCM_ECB;
        yaca_key_type_e key_type = YACA_KEY_TYPE_SYMMETRIC;
-       size_t key_bits = YACA_KEY_LENGTH_256BIT;
+       size_t key_bit_len = YACA_KEY_LENGTH_256BIT;
 
-       encrypt_simple(algo, bcm, key_bits);
-       encrypt_advanced(algo, bcm, key_type, key_bits);
+       encrypt_simple(algo, bcm, key_bit_len);
+       encrypt_advanced(algo, bcm, key_type, key_bit_len);
 
        algo = YACA_ENCRYPT_3DES_3TDEA;
        bcm = YACA_BCM_OFB;
        key_type = YACA_KEY_TYPE_DES;
-       key_bits = YACA_KEY_LENGTH_192BIT;
+       key_bit_len = YACA_KEY_LENGTH_192BIT;
 
-       encrypt_advanced(algo, bcm, key_type, key_bits);
+       encrypt_advanced(algo, bcm, key_type, key_bit_len);
 
        algo = YACA_ENCRYPT_CAST5;
        bcm = YACA_BCM_CFB;
        key_type = YACA_KEY_TYPE_SYMMETRIC;
-       key_bits = YACA_KEY_LENGTH_UNSAFE_40BIT;
+       key_bit_len = YACA_KEY_LENGTH_UNSAFE_40BIT;
 
-       encrypt_simple(algo, bcm, key_bits);
-       encrypt_advanced(algo, bcm, key_type, key_bits);
+       encrypt_simple(algo, bcm, key_bit_len);
+       encrypt_advanced(algo, bcm, key_type, key_bit_len);
 
        algo = YACA_ENCRYPT_UNSAFE_RC2;
        bcm = YACA_BCM_CBC;
        key_type = YACA_KEY_TYPE_SYMMETRIC;
-       key_bits = YACA_KEY_LENGTH_UNSAFE_8BIT;
+       key_bit_len = YACA_KEY_LENGTH_UNSAFE_8BIT;
 
-       encrypt_simple(algo, bcm, key_bits);
-       encrypt_advanced(algo, bcm, key_type, key_bits);
+       encrypt_simple(algo, bcm, key_bit_len);
+       encrypt_advanced(algo, bcm, key_type, key_bit_len);
 
        algo = YACA_ENCRYPT_UNSAFE_RC4;
        bcm = YACA_BCM_NONE;
        key_type = YACA_KEY_TYPE_SYMMETRIC;
-       key_bits = YACA_KEY_LENGTH_2048BIT;
+       key_bit_len = YACA_KEY_LENGTH_2048BIT;
 
-       encrypt_simple(algo, bcm, key_bits);
-       encrypt_advanced(algo, bcm, key_type, key_bits);
+       encrypt_simple(algo, bcm, key_bit_len);
+       encrypt_advanced(algo, bcm, key_type, key_bit_len);
 
        yaca_cleanup();
 
index d635ded..7ac3534 100644 (file)
@@ -37,8 +37,8 @@ void encrypt_decrypt_aes_gcm(void)
        yaca_encrypt_algorithm_e algo = YACA_ENCRYPT_AES;
        yaca_block_cipher_mode_e bcm = YACA_BCM_GCM;
        yaca_key_type_e key_type = YACA_KEY_TYPE_SYMMETRIC;
-       size_t key_bits = YACA_KEY_LENGTH_256BIT;
-       size_t iv_bits = YACA_KEY_LENGTH_IV_128BIT;
+       size_t key_bit_len = YACA_KEY_LENGTH_256BIT;
+       size_t iv_bit_len = YACA_KEY_LENGTH_IV_128BIT;
 
        yaca_context_h ctx = YACA_CONTEXT_NULL;
        yaca_key_h key = YACA_KEY_NULL;
@@ -46,37 +46,37 @@ void encrypt_decrypt_aes_gcm(void)
 
        char *enc = NULL;
        char *dec = NULL;
-       size_t enc_size;
-       size_t dec_size;
+       size_t enc_len;
+       size_t dec_len;
 
        char *aad = NULL;
        char *tag = NULL;
-       size_t aad_size = 16;
-       size_t tag_size = 16;
+       size_t aad_len = 16;
+       size_t tag_len = 16;
 
        size_t block_len;
        size_t output_len;
-       size_t out_size;
+       size_t written_len;
        size_t rem;
 
        printf("AES GCM 256bit key encryption/decryption\n");
        printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096);
 
        /* Key generation */
-       if (yaca_key_generate(key_type, key_bits, &key) != YACA_ERROR_NONE)
+       if (yaca_key_generate(key_type, key_bit_len, &key) != YACA_ERROR_NONE)
                return;
 
        /* IV generation */
-       if (yaca_key_generate(YACA_KEY_TYPE_IV, iv_bits, &iv) != YACA_ERROR_NONE)
+       if (yaca_key_generate(YACA_KEY_TYPE_IV, iv_bit_len, &iv) != YACA_ERROR_NONE)
                goto exit;
 
-       if (yaca_zalloc(aad_size, (void**)&aad) != YACA_ERROR_NONE)
+       if (yaca_zalloc(aad_len, (void**)&aad) != YACA_ERROR_NONE)
                goto exit;
 
-       if (yaca_randomize_bytes(aad, aad_size) != YACA_ERROR_NONE)
+       if (yaca_randomize_bytes(aad, aad_len) != YACA_ERROR_NONE)
                goto exit;
 
-       if (yaca_zalloc(tag_size, (void**)&tag) != YACA_ERROR_NONE)
+       if (yaca_zalloc(tag_len, (void**)&tag) != YACA_ERROR_NONE)
                goto exit;
 
        /* Encryption */
@@ -85,7 +85,7 @@ void encrypt_decrypt_aes_gcm(void)
                        goto exit;
 
                /* Provide any AAD data */
-               if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_AAD, aad, aad_size) != YACA_ERROR_NONE)
+               if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_AAD, aad, aad_len) != YACA_ERROR_NONE)
                        goto exit;
 
                /* For the update */
@@ -97,29 +97,29 @@ void encrypt_decrypt_aes_gcm(void)
                        goto exit;
 
                /* Calculate max output: size of update + final chunks */
-               enc_size = output_len + block_len;
-               if (yaca_malloc(enc_size, (void**)&enc) != YACA_ERROR_NONE)
+               enc_len = output_len + block_len;
+               if (yaca_malloc(enc_len, (void**)&enc) != YACA_ERROR_NONE)
                        goto exit;
 
-               out_size = enc_size;
-               if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != YACA_ERROR_NONE)
+               written_len = enc_len;
+               if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &written_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               rem = enc_size - out_size;
-               if (yaca_encrypt_finalize(ctx, enc + out_size, &rem) != YACA_ERROR_NONE)
+               rem = enc_len - written_len;
+               if (yaca_encrypt_finalize(ctx, enc + written_len, &rem) != YACA_ERROR_NONE)
                        goto exit;
 
-               enc_size = rem + out_size;
+               enc_len = rem + written_len;
 
                /* Set the tag length and get the tag after final encryption */
                if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_TAG_LEN,
-                                      (void*)&tag_size, sizeof(tag_size)) != YACA_ERROR_NONE)
+                                      (void*)&tag_len, sizeof(tag_len)) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_context_get_property(ctx, YACA_PROPERTY_GCM_TAG, (void**)tag, &tag_size) != YACA_ERROR_NONE)
+               if (yaca_context_get_property(ctx, YACA_PROPERTY_GCM_TAG, (void**)tag, &tag_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size);
+               dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_len);
 
                yaca_context_destroy(ctx);
                ctx = YACA_CONTEXT_NULL;
@@ -131,7 +131,7 @@ void encrypt_decrypt_aes_gcm(void)
                        goto exit;
 
                /* Provide any AAD data */
-               if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_AAD, aad, aad_size) != YACA_ERROR_NONE)
+               if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_AAD, aad, aad_len) != YACA_ERROR_NONE)
                        goto exit;
 
                /* For the update */
@@ -143,26 +143,26 @@ void encrypt_decrypt_aes_gcm(void)
                        goto exit;
 
                /* Calculate max output: size of update + final chunks */
-               dec_size = output_len + block_len;
-               if (yaca_malloc(dec_size, (void**)&dec) != YACA_ERROR_NONE)
+               dec_len = output_len + block_len;
+               if (yaca_malloc(dec_len, (void**)&dec) != YACA_ERROR_NONE)
                        goto exit;
 
-               out_size = dec_size;
-               if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != YACA_ERROR_NONE)
+               written_len = dec_len;
+               if (yaca_decrypt_update(ctx, enc, enc_len, dec, &written_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               rem = dec_size - out_size;
+               rem = dec_len - written_len;
 
                /* Set expected tag value before final decryption */
-               if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_TAG, tag, tag_size) != YACA_ERROR_NONE)
+               if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_TAG, tag, tag_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_decrypt_finalize(ctx, dec + out_size, &rem) != YACA_ERROR_NONE)
+               if (yaca_decrypt_finalize(ctx, dec + written_len, &rem) != YACA_ERROR_NONE)
                        goto exit;
 
-               dec_size = rem + out_size;
+               dec_len = rem + written_len;
 
-               printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_size, dec);
+               printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_len, dec);
        }
 
 exit:
@@ -180,8 +180,8 @@ void encrypt_decrypt_aes_ccm(void)
        yaca_encrypt_algorithm_e algo = YACA_ENCRYPT_AES;
        yaca_block_cipher_mode_e bcm = YACA_BCM_CCM;
        yaca_key_type_e key_type = YACA_KEY_TYPE_SYMMETRIC;
-       size_t key_bits = YACA_KEY_LENGTH_256BIT;
-       size_t iv_bits = YACA_KEY_LENGTH_IV_64BIT;
+       size_t key_bit_len = YACA_KEY_LENGTH_256BIT;
+       size_t iv_bit_len = YACA_KEY_LENGTH_IV_64BIT;
 
        yaca_context_h ctx = YACA_CONTEXT_NULL;
        yaca_key_h key = YACA_KEY_NULL;
@@ -189,17 +189,17 @@ void encrypt_decrypt_aes_ccm(void)
 
        char *enc = NULL;
        char *dec = NULL;
-       size_t enc_size;
-       size_t dec_size;
+       size_t enc_len;
+       size_t dec_len;
 
        char *aad = NULL;
        char *tag = NULL;
-       size_t aad_size = 16;
-       size_t tag_size = 12;
+       size_t aad_len = 16;
+       size_t tag_len = 12;
 
        size_t block_len;
        size_t output_len;
-       size_t out_size;
+       size_t written_len;
        size_t rem;
        size_t len;
 
@@ -207,20 +207,20 @@ void encrypt_decrypt_aes_ccm(void)
        printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096);
 
        /* Key generation */
-       if (yaca_key_generate(key_type, key_bits, &key) != YACA_ERROR_NONE)
+       if (yaca_key_generate(key_type, key_bit_len, &key) != YACA_ERROR_NONE)
                return;
 
        /* IV generation */
-       if (yaca_key_generate(YACA_KEY_TYPE_IV, iv_bits, &iv) != YACA_ERROR_NONE)
+       if (yaca_key_generate(YACA_KEY_TYPE_IV, iv_bit_len, &iv) != YACA_ERROR_NONE)
                goto exit;
 
-       if (yaca_zalloc(aad_size, (void**)&aad) != YACA_ERROR_NONE)
+       if (yaca_zalloc(aad_len, (void**)&aad) != YACA_ERROR_NONE)
                goto exit;
 
-       if (yaca_randomize_bytes(aad, aad_size) != YACA_ERROR_NONE)
+       if (yaca_randomize_bytes(aad, aad_len) != YACA_ERROR_NONE)
                goto exit;
 
-       if (yaca_zalloc(tag_size, (void**)&tag) != YACA_ERROR_NONE)
+       if (yaca_zalloc(tag_len, (void**)&tag) != YACA_ERROR_NONE)
                goto exit;
 
        /* Encryption */
@@ -230,14 +230,14 @@ void encrypt_decrypt_aes_ccm(void)
 
                /* Set tag length (optionally) */
                if (yaca_context_set_property(ctx, YACA_PROPERTY_CCM_TAG_LEN,
-                                      (void*)&tag_size, sizeof(tag_size)) != YACA_ERROR_NONE)
+                                      (void*)&tag_len, sizeof(tag_len)) != YACA_ERROR_NONE)
                        goto exit;
 
                /* The total plain text length must be passed (only needed if AAD is passed) */
                if (yaca_encrypt_update(ctx, NULL, LOREM4096_SIZE , NULL, &len) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_context_set_property(ctx, YACA_PROPERTY_CCM_AAD, aad, aad_size) != YACA_ERROR_NONE)
+               if (yaca_context_set_property(ctx, YACA_PROPERTY_CCM_AAD, aad, aad_len) != YACA_ERROR_NONE)
                        goto exit;
 
                /* For the update */
@@ -249,25 +249,25 @@ void encrypt_decrypt_aes_ccm(void)
                        goto exit;
 
                /* Calculate max output: size of update + final chunks */
-               enc_size = output_len + block_len;
-               if (yaca_malloc(enc_size, (void**)&enc) != YACA_ERROR_NONE)
+               enc_len = output_len + block_len;
+               if (yaca_malloc(enc_len, (void**)&enc) != YACA_ERROR_NONE)
                        goto exit;
 
-               out_size = enc_size;
-               if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != YACA_ERROR_NONE)
+               written_len = enc_len;
+               if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &written_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               rem = enc_size - out_size;
-               if (yaca_encrypt_finalize(ctx, enc + out_size, &rem) != YACA_ERROR_NONE)
+               rem = enc_len - written_len;
+               if (yaca_encrypt_finalize(ctx, enc + written_len, &rem) != YACA_ERROR_NONE)
                        goto exit;
 
-               enc_size = rem + out_size;
+               enc_len = rem + written_len;
 
                /* Get the tag after final encryption */
-               if (yaca_context_get_property(ctx, YACA_PROPERTY_CCM_TAG, (void**)tag, &tag_size) != YACA_ERROR_NONE)
+               if (yaca_context_get_property(ctx, YACA_PROPERTY_CCM_TAG, (void**)tag, &tag_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size);
+               dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_len);
 
                yaca_context_destroy(ctx);
                ctx = YACA_CONTEXT_NULL;
@@ -279,14 +279,14 @@ void encrypt_decrypt_aes_ccm(void)
                        goto exit;
 
                /* Set expected tag value */
-               if (yaca_context_set_property(ctx, YACA_PROPERTY_CCM_TAG, tag, tag_size) != YACA_ERROR_NONE)
+               if (yaca_context_set_property(ctx, YACA_PROPERTY_CCM_TAG, tag, tag_len) != YACA_ERROR_NONE)
                        goto exit;
 
                /* The total encrypted text length must be passed (only needed if AAD is passed) */
-               if (yaca_decrypt_update(ctx, NULL, enc_size , NULL, &len) != YACA_ERROR_NONE)
+               if (yaca_decrypt_update(ctx, NULL, enc_len , NULL, &len) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_context_set_property(ctx, YACA_PROPERTY_CCM_AAD, aad, aad_size) != YACA_ERROR_NONE)
+               if (yaca_context_set_property(ctx, YACA_PROPERTY_CCM_AAD, aad, aad_len) != YACA_ERROR_NONE)
                        goto exit;
 
                /* For the update */
@@ -298,19 +298,19 @@ void encrypt_decrypt_aes_ccm(void)
                        goto exit;
 
                /* Calculate max output: size of update + final chunks */
-               dec_size = output_len + block_len;
-               if (yaca_malloc(dec_size, (void**)&dec) != YACA_ERROR_NONE)
+               dec_len = output_len + block_len;
+               if (yaca_malloc(dec_len, (void**)&dec) != YACA_ERROR_NONE)
                        goto exit;
 
-               out_size = dec_size;
+               written_len = dec_len;
                /* The tag verify is performed when you call the final yaca_decrypt_update(),
                 * there is no call to yaca_decrypt_finalize() */
-               if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != YACA_ERROR_NONE)
+               if (yaca_decrypt_update(ctx, enc, enc_len, dec, &written_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               dec_size = out_size;
+               dec_len = written_len;
 
-               printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_size, dec);
+               printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_len, dec);
        }
 
 exit:
index fe3711f..07784d7 100644 (file)
@@ -34,7 +34,7 @@
 
 #include "misc.h"
 
-void dump_hex(const char *buf, size_t dump_size, const char *fmt, ...)
+void dump_hex(const char *buf, size_t dump_len, const char *fmt, ...)
 {
        va_list ap;
 
@@ -42,7 +42,7 @@ void dump_hex(const char *buf, size_t dump_size, const char *fmt, ...)
        vprintf(fmt, ap);
        va_end(ap);
        putchar('\n');
-       BIO_dump_fp(stdout, buf, dump_size);
+       BIO_dump_fp(stdout, buf, dump_len);
 }
 
 void debug_func(const char *buf)
index bf8a8e0..33c50bb 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <stddef.h>
 
-void dump_hex(const char *buf, size_t dump_size, const char *fmt, ...);
+void dump_hex(const char *buf, size_t dump_len, const char *fmt, ...);
 
 void debug_func(const char *buf);
 
index 96e5888..a7774eb 100644 (file)
@@ -34,7 +34,7 @@
 
 void encrypt_seal(const yaca_encrypt_algorithm_e algo,
                   const yaca_block_cipher_mode_e bcm,
-                  const size_t key_bits)
+                  const size_t key_bit_len)
 {
        yaca_context_h ctx = YACA_CONTEXT_NULL;
        yaca_key_h key_pub = YACA_KEY_NULL;
@@ -49,7 +49,7 @@ void encrypt_seal(const yaca_encrypt_algorithm_e algo,
 
        size_t block_len;
        size_t output_len;
-       size_t out_len;
+       size_t written_len;
        size_t rem;
 
        printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096);
@@ -63,7 +63,7 @@ void encrypt_seal(const yaca_encrypt_algorithm_e algo,
 
        /* Encrypt a.k.a. seal */
        {
-               if (yaca_seal_initialize(&ctx, key_pub, algo, bcm, key_bits, &sym_key, &iv) != YACA_ERROR_NONE)
+               if (yaca_seal_initialize(&ctx, key_pub, algo, bcm, key_bit_len, &sym_key, &iv) != YACA_ERROR_NONE)
                        goto exit;
 
                /* For the update */
@@ -80,15 +80,15 @@ void encrypt_seal(const yaca_encrypt_algorithm_e algo,
                        goto exit;
 
                /* Seal and finalize */
-               out_len = enc_len;
-               if (yaca_seal_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_len) != YACA_ERROR_NONE)
+               written_len = enc_len;
+               if (yaca_seal_update(ctx, lorem4096, LOREM4096_SIZE, enc, &written_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               rem = enc_len - out_len;
-               if (yaca_seal_finalize(ctx, enc + out_len, &rem) != YACA_ERROR_NONE)
+               rem = enc_len - written_len;
+               if (yaca_seal_finalize(ctx, enc + written_len, &rem) != YACA_ERROR_NONE)
                        goto exit;
 
-               enc_len = rem + out_len;
+               enc_len = rem + written_len;
 
                dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_len);
 
@@ -98,7 +98,7 @@ void encrypt_seal(const yaca_encrypt_algorithm_e algo,
 
        /* Decrypt a.k.a. open */
        {
-               if (yaca_open_initialize(&ctx, key_priv, algo, bcm, key_bits, sym_key, iv) != YACA_ERROR_NONE)
+               if (yaca_open_initialize(&ctx, key_priv, algo, bcm, key_bit_len, sym_key, iv) != YACA_ERROR_NONE)
                        goto exit;
 
                /* For the update */
@@ -115,15 +115,15 @@ void encrypt_seal(const yaca_encrypt_algorithm_e algo,
                        goto exit;
 
                /* Open and finalize */
-               out_len = dec_len;
-               if (yaca_open_update(ctx, enc, enc_len, dec, &out_len) != YACA_ERROR_NONE)
+               written_len = dec_len;
+               if (yaca_open_update(ctx, enc, enc_len, dec, &written_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               rem = dec_len - out_len;
-               if (yaca_open_finalize(ctx, dec + out_len, &rem) != YACA_ERROR_NONE)
+               rem = dec_len - written_len;
+               if (yaca_open_finalize(ctx, dec + written_len, &rem) != YACA_ERROR_NONE)
                        goto exit;
 
-               dec_len = rem + out_len;
+               dec_len = rem + written_len;
 
                printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_len, dec);
        }
@@ -142,7 +142,7 @@ void encrypt_seal_aes_gcm(void)
 {
        yaca_encrypt_algorithm_e algo = YACA_ENCRYPT_AES;
        yaca_block_cipher_mode_e bcm = YACA_BCM_GCM;
-       size_t key_bits = YACA_KEY_LENGTH_256BIT;
+       size_t key_bit_len = YACA_KEY_LENGTH_256BIT;
 
        yaca_context_h ctx = YACA_CONTEXT_NULL;
        yaca_key_h key_pub = YACA_KEY_NULL;
@@ -162,7 +162,7 @@ void encrypt_seal_aes_gcm(void)
 
        size_t block_len;
        size_t output_len;
-       size_t out_len;
+       size_t written_len;
        size_t rem;
 
        printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096);
@@ -185,7 +185,7 @@ void encrypt_seal_aes_gcm(void)
 
        /* Encryption */
        {
-               if (yaca_seal_initialize(&ctx, key_pub, algo, bcm, key_bits, &sym_key, &iv) != YACA_ERROR_NONE)
+               if (yaca_seal_initialize(&ctx, key_pub, algo, bcm, key_bit_len, &sym_key, &iv) != YACA_ERROR_NONE)
                        goto exit;
 
                /* Provide any AAD data */
@@ -205,15 +205,15 @@ void encrypt_seal_aes_gcm(void)
                if (yaca_malloc(enc_len, (void**)&enc) != YACA_ERROR_NONE)
                        goto exit;
 
-               out_len = enc_len;
-               if (yaca_seal_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_len) != YACA_ERROR_NONE)
+               written_len = enc_len;
+               if (yaca_seal_update(ctx, lorem4096, LOREM4096_SIZE, enc, &written_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               rem = enc_len - out_len;
-               if (yaca_seal_finalize(ctx, enc + out_len, &rem) != YACA_ERROR_NONE)
+               rem = enc_len - written_len;
+               if (yaca_seal_finalize(ctx, enc + written_len, &rem) != YACA_ERROR_NONE)
                        goto exit;
 
-               enc_len = rem + out_len;
+               enc_len = rem + written_len;
 
                /* Set the tag length and get the tag after final encryption */
                if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_TAG_LEN,
@@ -231,7 +231,7 @@ void encrypt_seal_aes_gcm(void)
 
        /* Decryption */
        {
-               if (yaca_open_initialize(&ctx, key_priv, algo, bcm, key_bits, sym_key, iv) != YACA_ERROR_NONE)
+               if (yaca_open_initialize(&ctx, key_priv, algo, bcm, key_bit_len, sym_key, iv) != YACA_ERROR_NONE)
                        goto exit;
 
                /* Provide any AAD data */
@@ -251,20 +251,20 @@ void encrypt_seal_aes_gcm(void)
                if (yaca_malloc(dec_len, (void**)&dec) != YACA_ERROR_NONE)
                        goto exit;
 
-               out_len = dec_len;
-               if (yaca_open_update(ctx, enc, enc_len, dec, &out_len) != YACA_ERROR_NONE)
+               written_len = dec_len;
+               if (yaca_open_update(ctx, enc, enc_len, dec, &written_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               rem = dec_len - out_len;
+               rem = dec_len - written_len;
 
                /* Set expected tag value before final decryption */
                if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_TAG, tag, tag_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_open_finalize(ctx, dec + out_len, &rem) != YACA_ERROR_NONE)
+               if (yaca_open_finalize(ctx, dec + written_len, &rem) != YACA_ERROR_NONE)
                        goto exit;
 
-               dec_len = rem + out_len;
+               dec_len = rem + written_len;
 
                printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_len, dec);
        }
@@ -283,7 +283,7 @@ void encrypt_seal_aes_ccm(void)
 {
        yaca_encrypt_algorithm_e algo = YACA_ENCRYPT_AES;
        yaca_block_cipher_mode_e bcm = YACA_BCM_CCM;
-       size_t key_bits = YACA_KEY_LENGTH_192BIT;
+       size_t key_bit_len = YACA_KEY_LENGTH_192BIT;
 
        yaca_context_h ctx = YACA_CONTEXT_NULL;
        yaca_key_h key_pub = YACA_KEY_NULL;
@@ -303,7 +303,7 @@ void encrypt_seal_aes_ccm(void)
 
        size_t block_len;
        size_t output_len;
-       size_t out_len;
+       size_t written_len;
        size_t rem;
        size_t len;
 
@@ -327,7 +327,7 @@ void encrypt_seal_aes_ccm(void)
 
        /* Encryption */
        {
-               if (yaca_seal_initialize(&ctx, key_pub, algo, bcm, key_bits, &sym_key, &iv) != YACA_ERROR_NONE)
+               if (yaca_seal_initialize(&ctx, key_pub, algo, bcm, key_bit_len, &sym_key, &iv) != YACA_ERROR_NONE)
                        goto exit;
 
                /* Set tag length (optionally) */
@@ -356,15 +356,15 @@ void encrypt_seal_aes_ccm(void)
                if (yaca_malloc(enc_len, (void**)&enc) != YACA_ERROR_NONE)
                        goto exit;
 
-               out_len = enc_len;
-               if (yaca_seal_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_len) != YACA_ERROR_NONE)
+               written_len = enc_len;
+               if (yaca_seal_update(ctx, lorem4096, LOREM4096_SIZE, enc, &written_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               rem = enc_len - out_len;
-               if (yaca_seal_finalize(ctx, enc + out_len, &rem) != YACA_ERROR_NONE)
+               rem = enc_len - written_len;
+               if (yaca_seal_finalize(ctx, enc + written_len, &rem) != YACA_ERROR_NONE)
                        goto exit;
 
-               enc_len = rem + out_len;
+               enc_len = rem + written_len;
 
                /* Get the tag after final encryption */
                if (yaca_context_get_property(ctx, YACA_PROPERTY_CCM_TAG, (void**)tag, &tag_len) != YACA_ERROR_NONE)
@@ -378,7 +378,7 @@ void encrypt_seal_aes_ccm(void)
 
        /* Decryption */
        {
-               if (yaca_open_initialize(&ctx, key_priv, algo, bcm, key_bits, sym_key, iv) != YACA_ERROR_NONE)
+               if (yaca_open_initialize(&ctx, key_priv, algo, bcm, key_bit_len, sym_key, iv) != YACA_ERROR_NONE)
                        goto exit;
 
                /* Set expected tag value */
@@ -406,13 +406,13 @@ void encrypt_seal_aes_ccm(void)
                if (yaca_malloc(dec_len, (void**)&dec) != YACA_ERROR_NONE)
                        goto exit;
 
-               out_len = dec_len;
+               written_len = dec_len;
                /* The tag verify is performed when you call the final yaca_open_update(),
                 * there is no call to yaca_open_finalize() */
-               if (yaca_open_update(ctx, enc, enc_len, dec, &out_len) != YACA_ERROR_NONE)
+               if (yaca_open_update(ctx, enc, enc_len, dec, &written_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               dec_len = out_len;
+               dec_len = written_len;
 
                printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_len, dec);
        }
@@ -438,20 +438,20 @@ int main()
        printf("AES CBC 256bit key seal/open\n");
        yaca_encrypt_algorithm_e algo = YACA_ENCRYPT_AES;
        yaca_block_cipher_mode_e bcm = YACA_BCM_CBC;
-       size_t key_bits = YACA_KEY_LENGTH_256BIT;
-       encrypt_seal(algo, bcm, key_bits);
+       size_t key_bit_len = YACA_KEY_LENGTH_256BIT;
+       encrypt_seal(algo, bcm, key_bit_len);
 
        printf("3DES 192bit key seal/open\n");
        algo = YACA_ENCRYPT_3DES_3TDEA;
        bcm = YACA_BCM_CFB;
-       key_bits = YACA_KEY_LENGTH_192BIT;
-       encrypt_seal(algo, bcm, key_bits);
-
-       printf("RC4 40bit key seal/open\n");
-       algo = YACA_ENCRYPT_UNSAFE_RC4;
-       bcm = YACA_BCM_NONE;
-       key_bits = YACA_KEY_LENGTH_UNSAFE_40BIT;
-       encrypt_seal(algo, bcm, key_bits);
+       key_bit_len = YACA_KEY_LENGTH_192BIT;
+       encrypt_seal(algo, bcm, key_bit_len);
+
+       printf("RC2 40bit key seal/open\n");
+       algo = YACA_ENCRYPT_UNSAFE_RC2;
+       bcm = YACA_BCM_OFB;
+       key_bit_len = YACA_KEY_LENGTH_UNSAFE_40BIT;
+       encrypt_seal(algo, bcm, key_bit_len);
 
        printf("AES GCM 256bit key seal/open\n");
        encrypt_seal_aes_gcm();
index 664632f..26518b2 100644 (file)
@@ -14,7 +14,7 @@ Project structure:
 
 General design:
        - All memory allocated by API should be freed with yaca_free()
-       - Contexts and keys should be freed with yaca_context_destroy()/yaca_key_destroy()
+       - Contexts and keys should be released with yaca_context_destroy()/yaca_key_destroy()
        - Function names: yaca_<operation/object>_<function>; Ex: yaca_verify_initialize()
        - Simplified/Simple functions don't have <operation/object> part, but have <simple> prefix
        - Enums: YACA_<concept>_<value>; Ex: YACA_KEY_LENGTH_256BIT
index 158bcf8..2714120 100644 (file)
@@ -77,7 +77,7 @@ API int yaca_initialize(void)
 {
        int ret = YACA_ERROR_NONE;
 
-       /* no calling yaca_initalize() twice on the same thread */
+       /* no calling yaca_initialize() twice on the same thread */
        if (current_thread_initialized)
                return YACA_ERROR_INTERNAL;
 
@@ -142,7 +142,7 @@ API int yaca_initialize(void)
                        /*
                         * TODO:
                         * - We should also decide on Openssl config.
-                        * - Here's a good tutorial for initalization and cleanup:
+                        * - Here's a good tutorial for initialization and cleanup:
                         *   https://wiki.openssl.org/index.php/Library_Initialization
                         * - We should also initialize the entropy for random number generator:
                         *   https://wiki.openssl.org/index.php/Random_Numbers#Initialization
@@ -260,26 +260,26 @@ API int yaca_randomize_bytes(char *data, size_t data_len)
 API int yaca_context_set_property(yaca_context_h ctx, yaca_property_e property,
                                   const void *value, size_t value_len)
 {
-       if (ctx == YACA_CONTEXT_NULL || ctx->set_param == NULL)
+       if (ctx == YACA_CONTEXT_NULL || ctx->set_property == NULL)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       return ctx->set_param(ctx, property, value, value_len);
+       return ctx->set_property(ctx, property, value, value_len);
 }
 
 API int yaca_context_get_property(const yaca_context_h ctx, yaca_property_e property,
                                   void **value, size_t *value_len)
 {
-       if (ctx == YACA_CONTEXT_NULL || ctx->get_param == NULL)
+       if (ctx == YACA_CONTEXT_NULL || ctx->get_property == NULL)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       return ctx->get_param(ctx, property, value, value_len);
+       return ctx->get_property(ctx, property, value, value_len);
 }
 
 API void yaca_context_destroy(yaca_context_h ctx)
 {
        if (ctx != YACA_CONTEXT_NULL) {
-               assert(ctx->ctx_destroy != NULL);
-               ctx->ctx_destroy(ctx);
+               assert(ctx->context_destroy != NULL);
+               ctx->context_destroy(ctx);
                yaca_free(ctx);
        }
 }
index b003e97..fa342bb 100644 (file)
 
 #include "internal.h"
 
-struct yaca_digest_ctx_s {
+struct yaca_digest_context_s {
        struct yaca_context_s ctx;
 
-       EVP_MD_CTX *mdctx;
+       EVP_MD_CTX *md_ctx;
 };
 
-static struct yaca_digest_ctx_s *get_digest_ctx(const yaca_context_h ctx)
+static struct yaca_digest_context_s *get_digest_context(const yaca_context_h ctx)
 {
        if (ctx == YACA_CONTEXT_NULL)
                return NULL;
 
        switch (ctx->type) {
-       case YACA_CTX_DIGEST:
-               return (struct yaca_digest_ctx_s *)ctx;
+       case YACA_CONTEXT_DIGEST:
+               return (struct yaca_digest_context_s *)ctx;
        default:
                return NULL;
        }
@@ -56,12 +56,12 @@ static int get_digest_output_length(const yaca_context_h ctx,
 {
        assert(output_len != NULL);
 
-       struct yaca_digest_ctx_s *c = get_digest_ctx(ctx);
+       struct yaca_digest_context_s *c = get_digest_context(ctx);
 
        if (c == NULL || input_len != 0)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       int md_size = EVP_MD_CTX_size(c->mdctx);
+       int md_size = EVP_MD_CTX_size(c->md_ctx);
        if (md_size <= 0)
                return YACA_ERROR_INTERNAL;
 
@@ -72,13 +72,13 @@ static int get_digest_output_length(const yaca_context_h ctx,
 
 static void destroy_digest_context(yaca_context_h ctx)
 {
-       struct yaca_digest_ctx_s *c = get_digest_ctx(ctx);
+       struct yaca_digest_context_s *c = get_digest_context(ctx);
 
        if (c == NULL)
                return;
 
-       EVP_MD_CTX_destroy(c->mdctx);
-       c->mdctx = NULL;
+       EVP_MD_CTX_destroy(c->md_ctx);
+       c->md_ctx = NULL;
 }
 
 int digest_get_algorithm(yaca_digest_algorithm_e algo, const EVP_MD **md)
@@ -125,32 +125,32 @@ int digest_get_algorithm(yaca_digest_algorithm_e algo, const EVP_MD **md)
 API int yaca_digest_initialize(yaca_context_h *ctx, yaca_digest_algorithm_e algo)
 {
        int ret;
-       struct yaca_digest_ctx_s *nc = NULL;
+       struct yaca_digest_context_s *nc = NULL;
        const EVP_MD *md;
 
        if (ctx == NULL)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       ret = yaca_zalloc(sizeof(struct yaca_digest_ctx_s), (void**)&nc);
+       ret = yaca_zalloc(sizeof(struct yaca_digest_context_s), (void**)&nc);
        if (ret != YACA_ERROR_NONE)
                return ret;
 
-       nc->ctx.type = YACA_CTX_DIGEST;
-       nc->ctx.ctx_destroy = destroy_digest_context;
+       nc->ctx.type = YACA_CONTEXT_DIGEST;
+       nc->ctx.context_destroy = destroy_digest_context;
        nc->ctx.get_output_length = get_digest_output_length;
 
        ret = digest_get_algorithm(algo, &md);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       nc->mdctx = EVP_MD_CTX_create();
-       if (nc->mdctx == NULL) {
+       nc->md_ctx = EVP_MD_CTX_create();
+       if (nc->md_ctx == NULL) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
                goto exit;
        }
 
-       ret = EVP_DigestInit(nc->mdctx, md);
+       ret = EVP_DigestInit(nc->md_ctx, md);
        if (ret != 1) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
@@ -169,13 +169,13 @@ exit:
 
 API int yaca_digest_update(yaca_context_h ctx, const char *data, size_t data_len)
 {
-       struct yaca_digest_ctx_s *c = get_digest_ctx(ctx);
+       struct yaca_digest_context_s *c = get_digest_context(ctx);
        int ret;
 
        if (c == NULL || data == NULL || data_len == 0)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       ret = EVP_DigestUpdate(c->mdctx, data, data_len);
+       ret = EVP_DigestUpdate(c->md_ctx, data, data_len);
        if (ret != 1) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
@@ -187,7 +187,7 @@ API int yaca_digest_update(yaca_context_h ctx, const char *data, size_t data_len
 
 API int yaca_digest_finalize(yaca_context_h ctx, char *digest, size_t *digest_len)
 {
-       struct yaca_digest_ctx_s *c = get_digest_ctx(ctx);
+       struct yaca_digest_context_s *c = get_digest_context(ctx);
        int ret;
        unsigned len = 0;
 
@@ -197,7 +197,7 @@ API int yaca_digest_finalize(yaca_context_h ctx, char *digest, size_t *digest_le
        if (*digest_len == 0 || *digest_len > UINT_MAX) /* DigestFinal accepts UINT */
                return YACA_ERROR_INVALID_PARAMETER;
 
-       ret = EVP_DigestFinal_ex(c->mdctx, (unsigned char*)digest, &len);
+       ret = EVP_DigestFinal_ex(c->md_ctx, (unsigned char*)digest, &len);
        if (ret != 1) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
index b248896..6dc4527 100644 (file)
@@ -39,7 +39,7 @@ struct yaca_encrypt_context_s *get_encrypt_context(const yaca_context_h ctx)
                return NULL;
 
        switch (ctx->type) {
-       case YACA_CTX_ENCRYPT:
+       case YACA_CONTEXT_ENCRYPT:
                return (struct yaca_encrypt_context_s *)ctx;
        default:
                return NULL;
@@ -257,7 +257,7 @@ static const char *bcm_to_str(yaca_block_cipher_mode_e bcm)
 
 int encrypt_get_algorithm(yaca_encrypt_algorithm_e algo,
                           yaca_block_cipher_mode_e bcm,
-                          size_t key_bits,
+                          size_t key_bit_len,
                           const EVP_CIPHER **cipher)
 {
        char cipher_name[32];
@@ -266,14 +266,13 @@ int encrypt_get_algorithm(yaca_encrypt_algorithm_e algo,
        const EVP_CIPHER *lcipher;
        int ret;
 
-       if (algo_name == NULL || bcm_name == NULL || key_bits == 0 ||
-           cipher == NULL)
+       if (algo_name == NULL || bcm_name == NULL || key_bit_len == 0 || cipher == NULL)
                return YACA_ERROR_INVALID_PARAMETER;
 
        switch (algo) {
        case YACA_ENCRYPT_AES:
                ret = snprintf(cipher_name, sizeof(cipher_name), "%s-%zu-%s",
-                              algo_name, key_bits, bcm_name);
+                              algo_name, key_bit_len, bcm_name);
                break;
        case YACA_ENCRYPT_UNSAFE_DES:
        case YACA_ENCRYPT_UNSAFE_RC2:
@@ -317,16 +316,16 @@ static int encrypt_initialize(yaca_context_h *ctx,
                               yaca_block_cipher_mode_e bcm,
                               const yaca_key_h sym_key,
                               const yaca_key_h iv,
-                              enum encrypt_op_type op_type)
+                              enum encrypt_op_type_e op_type)
 {
        const struct yaca_key_simple_s *lkey;
        const struct yaca_key_simple_s *liv;
        struct yaca_encrypt_context_s *nc;
        const EVP_CIPHER *cipher;
-       size_t key_bits;
+       size_t key_bit_len;
        unsigned char *iv_data = NULL;
-       size_t iv_bits;
-       size_t iv_bits_check;
+       size_t iv_bit_len;
+       size_t iv_bit_len_check;
        int ret;
 
        if (ctx == NULL || sym_key == YACA_KEY_NULL)
@@ -340,19 +339,19 @@ static int encrypt_initialize(yaca_context_h *ctx,
        if (ret != YACA_ERROR_NONE)
                return ret;
 
-       nc->ctx.type = YACA_CTX_ENCRYPT;
-       nc->ctx.ctx_destroy = destroy_encrypt_context;
+       nc->ctx.type = YACA_CONTEXT_ENCRYPT;
+       nc->ctx.context_destroy = destroy_encrypt_context;
        nc->ctx.get_output_length = get_encrypt_output_length;
-       nc->ctx.set_param = set_encrypt_property;
-       nc->ctx.get_param = get_encrypt_property;
+       nc->ctx.set_property = set_encrypt_property;
+       nc->ctx.get_property = get_encrypt_property;
        nc->op_type = op_type;
        nc->tag_len = 0;
 
-       ret = yaca_key_get_bit_length(sym_key, &key_bits);
+       ret = yaca_key_get_bit_length(sym_key, &key_bit_len);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       ret = encrypt_get_algorithm(algo, bcm, key_bits, &cipher);
+       ret = encrypt_get_algorithm(algo, bcm, key_bit_len, &cipher);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
@@ -363,25 +362,25 @@ static int encrypt_initialize(yaca_context_h *ctx,
                goto exit;
        }
 
-       iv_bits = ret * 8;
-       if (iv_bits == 0 && iv != NULL) { /* 0 -> cipher doesn't use iv, but it was provided */
+       iv_bit_len = ret * 8;
+       if (iv_bit_len == 0 && iv != NULL) { /* 0 -> cipher doesn't use iv, but it was provided */
                ret = YACA_ERROR_INVALID_PARAMETER;
                goto exit;
        }
 
-       if (iv_bits != 0) { /* cipher requires iv*/
+       if (iv_bit_len != 0) { /* cipher requires iv*/
                liv = key_get_simple(iv);
                if (liv == NULL) { /* iv was not provided */
                        ret = YACA_ERROR_INVALID_PARAMETER;
                        goto exit;
                }
-               ret = yaca_key_get_bit_length(iv, &iv_bits_check);
+               ret = yaca_key_get_bit_length(iv, &iv_bit_len_check);
                if (ret != YACA_ERROR_NONE) {
                        ret = YACA_ERROR_INVALID_PARAMETER;
                        goto exit;
                }
                /* IV length doesn't match cipher (GCM & CCM supports variable IV length) */
-               if (iv_bits != iv_bits_check &&
+               if (iv_bit_len != iv_bit_len_check &&
                    bcm != YACA_BCM_GCM &&
                    bcm != YACA_BCM_CCM) {
                        ret = YACA_ERROR_INVALID_PARAMETER;
@@ -416,7 +415,7 @@ static int encrypt_initialize(yaca_context_h *ctx,
        }
 
        /* Handling of algorithms with variable key length */
-       ret = EVP_CIPHER_CTX_set_key_length(nc->cipher_ctx, key_bits / 8);
+       ret = EVP_CIPHER_CTX_set_key_length(nc->cipher_ctx, key_bit_len / 8);
        if (ret != 1) {
                ret = YACA_ERROR_INVALID_PARAMETER;
                ERROR_DUMP(ret);
@@ -424,14 +423,14 @@ static int encrypt_initialize(yaca_context_h *ctx,
        }
 
        /* Handling of algorithms with variable IV length */
-       if (iv_bits != iv_bits_check) {
+       if (iv_bit_len != iv_bit_len_check) {
                if (bcm == YACA_BCM_GCM)
                        ret = EVP_CIPHER_CTX_ctrl(nc->cipher_ctx, EVP_CTRL_GCM_SET_IVLEN,
-                                                 iv_bits_check / 8, NULL);
+                                                 iv_bit_len_check / 8, NULL);
 
                if (bcm == YACA_BCM_CCM)
                        ret = EVP_CIPHER_CTX_ctrl(nc->cipher_ctx, EVP_CTRL_CCM_SET_IVLEN,
-                                                 iv_bits_check / 8, NULL);
+                                                 iv_bit_len_check / 8, NULL);
 
                if (ret != 1) {
                        ret = YACA_ERROR_INVALID_PARAMETER;
@@ -475,7 +474,7 @@ exit:
 int encrypt_update(yaca_context_h ctx,
                    const unsigned char *input, size_t input_len,
                    unsigned char *output, size_t *output_len,
-                   enum encrypt_op_type op_type)
+                   enum encrypt_op_type_e op_type)
 {
        struct yaca_encrypt_context_s *c = get_encrypt_context(ctx);
        int ret;
@@ -513,7 +512,7 @@ int encrypt_update(yaca_context_h ctx,
 
 int encrypt_finalize(yaca_context_h ctx,
                      unsigned char *output, size_t *output_len,
-                     enum encrypt_op_type op_type)
+                     enum encrypt_op_type_e op_type)
 {
        struct yaca_encrypt_context_s *c = get_encrypt_context(ctx);
        int ret;
index dce0a61..762c019 100644 (file)
 #define API __attribute__ ((visibility("default")))
 #define UNUSED __attribute__((unused))
 
-enum yaca_ctx_type_e {
-       YACA_CTX_INVALID = 0,
-       YACA_CTX_DIGEST,
-       YACA_CTX_SIGN,
-       YACA_CTX_ENCRYPT
+enum yaca_context_type_e {
+       YACA_CONTEXT_INVALID = 0,
+       YACA_CONTEXT_DIGEST,
+       YACA_CONTEXT_SIGN,
+       YACA_CONTEXT_ENCRYPT
 };
 
-enum encrypt_op_type {
+enum encrypt_op_type_e {
        OP_ENCRYPT = 0,
        OP_DECRYPT = 1,
        OP_SEAL    = 2,
@@ -50,21 +50,21 @@ enum encrypt_op_type {
 
 /* Base structure for crypto contexts - to be inherited */
 struct yaca_context_s {
-       enum yaca_ctx_type_e type;
+       enum yaca_context_type_e type;
 
-       void (*ctx_destroy)(const yaca_context_h ctx);
+       void (*context_destroy)(const yaca_context_h ctx);
        int (*get_output_length)(const yaca_context_h ctx, size_t input_len, size_t *output_len);
-       int (*set_param)(yaca_context_h ctx, yaca_property_e param,
-                        const void *value, size_t value_len);
-       int (*get_param)(const yaca_context_h ctx, yaca_property_e param,
-                        void **value, size_t *value_len);
+       int (*set_property)(yaca_context_h ctx, yaca_property_e property,
+                           const void *value, size_t value_len);
+       int (*get_property)(const yaca_context_h ctx, yaca_property_e property,
+                           void **value, size_t *value_len);
 };
 
 struct yaca_encrypt_context_s {
        struct yaca_context_s ctx;
 
        EVP_CIPHER_CTX *cipher_ctx;
-       enum encrypt_op_type op_type; /* Operation context was created for */
+       enum encrypt_op_type_e op_type; /* Operation context was created for */
        size_t tag_len;
 };
 
@@ -82,7 +82,7 @@ struct yaca_key_s {
 struct yaca_key_simple_s {
        struct yaca_key_s key;
 
-       size_t bits;
+       size_t bit_len;
        char d[];
 };
 
@@ -116,17 +116,17 @@ int get_encrypt_property(const yaca_context_h ctx, yaca_property_e property,
 
 int encrypt_get_algorithm(yaca_encrypt_algorithm_e algo,
                           yaca_block_cipher_mode_e bcm,
-                          size_t key_bits,
+                          size_t key_bit_len,
                           const EVP_CIPHER **cipher);
 
 int encrypt_update(yaca_context_h ctx,
                    const unsigned char *input, size_t input_len,
                    unsigned char *output, size_t *output_len,
-                   enum encrypt_op_type op_type);
+                   enum encrypt_op_type_e op_type);
 
 int encrypt_finalize(yaca_context_h ctx,
                      unsigned char *output, size_t *output_len,
-                     enum encrypt_op_type op_type);
+                     enum encrypt_op_type_e op_type);
 
 struct yaca_key_simple_s *key_get_simple(const yaca_key_h key);
 struct yaca_key_evp_s *key_get_evp(const yaca_key_h key);
index 4153434..e018d14 100644 (file)
--- a/src/key.c
+++ b/src/key.c
@@ -32,7 +32,6 @@
 #include <openssl/bio.h>
 #include <openssl/pem.h>
 #include <openssl/des.h>
-#include <openssl/crypto.h>
 
 #include <yaca_crypto.h>
 #include <yaca_error.h>
@@ -219,7 +218,7 @@ int import_simple(yaca_key_h *key,
                return ret;
        }
 
-       /* key_bits has to fit in size_t */
+       /* key_bit_len has to fit in size_t */
        if (key_data_len > SIZE_MAX / 8) {
                ret = YACA_ERROR_INVALID_PARAMETER;
                goto exit;
@@ -227,10 +226,10 @@ int import_simple(yaca_key_h *key,
 
        /* DES key length verification */
        if (key_type == YACA_KEY_TYPE_DES) {
-               size_t key_bits = key_data_len * 8;
-               if (key_bits != YACA_KEY_LENGTH_UNSAFE_64BIT &&
-                   key_bits != YACA_KEY_LENGTH_UNSAFE_128BIT &&
-                   key_bits != YACA_KEY_LENGTH_192BIT) {
+               size_t key_bit_len = key_data_len * 8;
+               if (key_bit_len != YACA_KEY_LENGTH_UNSAFE_64BIT &&
+                   key_bit_len != YACA_KEY_LENGTH_UNSAFE_128BIT &&
+                   key_bit_len != YACA_KEY_LENGTH_192BIT) {
                        ret = YACA_ERROR_INVALID_PARAMETER;
                        goto exit;
                }
@@ -241,7 +240,7 @@ int import_simple(yaca_key_h *key,
                goto exit;
 
        memcpy(nk->d, key_data, key_data_len);
-       nk->bits = key_data_len * 8;
+       nk->bit_len = key_data_len * 8;
        nk->key.type = key_type;
 
        *key = (yaca_key_h)nk;
@@ -426,7 +425,7 @@ int export_simple_raw(struct yaca_key_simple_s *simple_key,
        assert(data != NULL);
        assert(data_len != NULL);
 
-       size_t key_len = simple_key->bits / 8;
+       size_t key_len = simple_key->bit_len / 8;
 
        assert(key_len > 0);
 
@@ -449,7 +448,7 @@ int export_simple_base64(struct yaca_key_simple_s *simple_key,
        assert(data_len != NULL);
 
        int ret;
-       size_t key_len = simple_key->bits / 8;
+       size_t key_len = simple_key->bit_len / 8;
        BIO *b64;
        BIO *mem;
        char *bio_data;
@@ -735,19 +734,19 @@ exit:
        return ret;
 }
 
-int gen_simple(struct yaca_key_simple_s **out, size_t key_bits)
+int generate_simple(struct yaca_key_simple_s **out, size_t key_bit_len)
 {
        assert(out != NULL);
 
        int ret;
        struct yaca_key_simple_s *nk;
-       size_t key_byte_len = key_bits / 8;
+       size_t key_byte_len = key_bit_len / 8;
 
        ret = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_byte_len, (void**)&nk);
        if (ret != YACA_ERROR_NONE)
                return ret;
 
-       nk->bits = key_bits;
+       nk->bit_len = key_bit_len;
 
        ret = yaca_randomize_bytes(nk->d, key_byte_len);
        if (ret != YACA_ERROR_NONE)
@@ -757,18 +756,18 @@ int gen_simple(struct yaca_key_simple_s **out, size_t key_bits)
        return YACA_ERROR_NONE;
 }
 
-int gen_simple_des(struct yaca_key_simple_s **out, size_t key_bits)
+int generate_simple_des(struct yaca_key_simple_s **out, size_t key_bit_len)
 {
        assert(out != NULL);
 
-       if (key_bits != YACA_KEY_LENGTH_UNSAFE_64BIT &&
-           key_bits != YACA_KEY_LENGTH_UNSAFE_128BIT &&
-           key_bits != YACA_KEY_LENGTH_192BIT)
+       if (key_bit_len != YACA_KEY_LENGTH_UNSAFE_64BIT &&
+           key_bit_len != YACA_KEY_LENGTH_UNSAFE_128BIT &&
+           key_bit_len != YACA_KEY_LENGTH_192BIT)
                return YACA_ERROR_INVALID_PARAMETER;
 
        int ret;
        struct yaca_key_simple_s *nk;
-       size_t key_byte_len = key_bits / 8;
+       size_t key_byte_len = key_bit_len / 8;
 
        ret = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_byte_len, (void**)&nk);
        if (ret != YACA_ERROR_NONE)
@@ -800,7 +799,7 @@ int gen_simple_des(struct yaca_key_simple_s **out, size_t key_bits)
                }
        }
 
-       nk->bits = key_bits;
+       nk->bit_len = key_bit_len;
        *out = nk;
        nk = NULL;
        ret = YACA_ERROR_NONE;
@@ -811,12 +810,12 @@ exit:
        return ret;
 }
 
-// TODO: consider merging gen_evp_*, they share awful lot of common code
-int gen_evp_rsa(struct yaca_key_evp_s **out, size_t key_bits)
+// TODO: consider merging generate_evp_*, they share awful lot of common code
+int generate_evp_rsa(struct yaca_key_evp_s **out, size_t key_bit_len)
 {
        assert(out != NULL);
-       assert(key_bits > 0);
-       assert(key_bits % 8 == 0);
+       assert(key_bit_len > 0);
+       assert(key_bit_len % 8 == 0);
 
        int ret;
        struct yaca_key_evp_s *nk;
@@ -841,7 +840,7 @@ int gen_evp_rsa(struct yaca_key_evp_s **out, size_t key_bits)
                goto exit;
        }
 
-       ret = EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, key_bits);
+       ret = EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, key_bit_len);
        if (ret != 1) {
                ret = ERROR_HANDLE();
                goto exit;
@@ -868,15 +867,15 @@ exit:
        return ret;
 }
 
-int gen_evp_dsa(struct yaca_key_evp_s **out, size_t key_bits)
+int generate_evp_dsa(struct yaca_key_evp_s **out, size_t key_bit_len)
 {
        assert(out != NULL);
-       assert(key_bits > 0);
-       assert(key_bits % 8 == 0);
+       assert(key_bit_len > 0);
+       assert(key_bit_len % 8 == 0);
 
        /* Openssl generates 512-bit key for key lengths smaller than 512. It also
         * rounds key size to multiplication of 64. */
-       if (key_bits < 512 || key_bits % 64 != 0)
+       if (key_bit_len < 512 || key_bit_len % 64 != 0)
                return YACA_ERROR_INVALID_PARAMETER;
 
        int ret;
@@ -904,7 +903,7 @@ int gen_evp_dsa(struct yaca_key_evp_s **out, size_t key_bits)
                goto exit;
        }
 
-       ret = EVP_PKEY_CTX_set_dsa_paramgen_bits(pctx, key_bits);
+       ret = EVP_PKEY_CTX_set_dsa_paramgen_bits(pctx, key_bit_len);
        if (ret != 1) {
                ret = ERROR_HANDLE();
                goto exit;
@@ -968,8 +967,8 @@ struct yaca_key_simple_s *key_get_simple(const yaca_key_h key)
                k = (struct yaca_key_simple_s *)key;
 
                /* sanity check */
-               assert(k->bits != 0);
-               assert(k->bits % 8 == 0);
+               assert(k->bit_len != 0);
+               assert(k->bit_len % 8 == 0);
                assert(k->d != NULL);
 
                return k;
@@ -1007,7 +1006,7 @@ static yaca_key_h key_copy_simple(const struct yaca_key_simple_s *key)
        assert(key != NULL);
 
        struct yaca_key_simple_s *copy;
-       size_t size = sizeof(struct yaca_key_simple_s) + key->bits / 8;
+       size_t size = sizeof(struct yaca_key_simple_s) + key->bit_len / 8;
 
        ret = yaca_zalloc(size, (void**)&copy);
        if (ret != YACA_ERROR_NONE)
@@ -1068,7 +1067,7 @@ API int yaca_key_get_bit_length(const yaca_key_h key, size_t *key_bit_len)
                return YACA_ERROR_INVALID_PARAMETER;
 
        if (simple_key != NULL) {
-               *key_bit_len = simple_key->bits;
+               *key_bit_len = simple_key->bit_len;
                return YACA_ERROR_NONE;
        }
 
@@ -1176,16 +1175,16 @@ API int yaca_key_generate(yaca_key_type_e key_type,
        switch (key_type) {
        case YACA_KEY_TYPE_SYMMETRIC:
        case YACA_KEY_TYPE_IV:
-               ret = gen_simple(&nk_simple, key_bit_len);
+               ret = generate_simple(&nk_simple, key_bit_len);
                break;
        case YACA_KEY_TYPE_DES:
-               ret = gen_simple_des(&nk_simple, key_bit_len);
+               ret = generate_simple_des(&nk_simple, key_bit_len);
                break;
        case YACA_KEY_TYPE_RSA_PRIV:
-               ret = gen_evp_rsa(&nk_evp, key_bit_len);
+               ret = generate_evp_rsa(&nk_evp, key_bit_len);
                break;
        case YACA_KEY_TYPE_DSA_PRIV:
-               ret = gen_evp_dsa(&nk_evp, key_bit_len);
+               ret = generate_evp_dsa(&nk_evp, key_bit_len);
                break;
 //     case YACA_KEY_TYPE_DH_PRIV:
 //     case YACA_KEY_TYPE_EC_PRIV:
@@ -1309,7 +1308,7 @@ API int yaca_key_derive_pbkdf2(const char *password,
            iterations == 0 || key_bit_len == 0 || key == NULL)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       if (key_bit_len % 8) /* Key length must be multiple of 8-bits */
+       if (key_bit_len % 8) /* Key length must be multiple of 8-bit_len */
                return YACA_ERROR_INVALID_PARAMETER;
 
        if (iterations > INT_MAX) /* OpenSSL limitation */
@@ -1323,7 +1322,7 @@ API int yaca_key_derive_pbkdf2(const char *password,
        if (ret != YACA_ERROR_NONE)
                return ret;
 
-       nk->bits = key_bit_len;
+       nk->bit_len = key_bit_len;
        nk->key.type = YACA_KEY_TYPE_SYMMETRIC; // TODO: how to handle other keys?
 
        ret = PKCS5_PBKDF2_HMAC(password, -1, (const unsigned char*)salt,
index 9f30bd8..7ff74d1 100644 (file)
@@ -65,11 +65,11 @@ API int yaca_seal_initialize(yaca_context_h *ctx,
        if (ret != YACA_ERROR_NONE)
                return ret;
 
-       nc->ctx.type = YACA_CTX_ENCRYPT;
-       nc->ctx.ctx_destroy = destroy_encrypt_context;
+       nc->ctx.type = YACA_CONTEXT_ENCRYPT;
+       nc->ctx.context_destroy = destroy_encrypt_context;
        nc->ctx.get_output_length = get_encrypt_output_length;
-       nc->ctx.set_param = set_encrypt_property;
-       nc->ctx.get_param = get_encrypt_property;
+       nc->ctx.set_property = set_encrypt_property;
+       nc->ctx.get_property = get_encrypt_property;
        nc->op_type = OP_SEAL;
        nc->tag_len = 0;
 
@@ -126,13 +126,13 @@ API int yaca_seal_initialize(yaca_context_h *ctx,
                goto exit;
        }
 
-       lkey->bits = key_data_length * 8;
+       lkey->bit_len = key_data_length * 8;
        lkey->key.type = YACA_KEY_TYPE_SYMMETRIC;
        *sym_key = (yaca_key_h)lkey;
        lkey = NULL;
 
        if (iv_length > 0) {
-               liv->bits = iv_length * 8;
+               liv->bit_len = iv_length * 8;
                liv->key.type = YACA_KEY_TYPE_IV;
                *iv = (yaca_key_h)liv;
                liv = NULL;
@@ -182,8 +182,8 @@ API int yaca_open_initialize(yaca_context_h *ctx,
        struct yaca_encrypt_context_s *nc;
        const EVP_CIPHER *cipher;
        unsigned char *iv_data = NULL;
-       size_t iv_bits;
-       size_t iv_bits_check;
+       size_t iv_bit_len;
+       size_t iv_bit_len_check;
        int ret;
 
        if (ctx == NULL || prv_key == YACA_KEY_NULL || sym_key == YACA_KEY_NULL)
@@ -202,11 +202,11 @@ API int yaca_open_initialize(yaca_context_h *ctx,
        if (ret != YACA_ERROR_NONE)
                return ret;
 
-       nc->ctx.type = YACA_CTX_ENCRYPT;
-       nc->ctx.ctx_destroy = destroy_encrypt_context;
+       nc->ctx.type = YACA_CONTEXT_ENCRYPT;
+       nc->ctx.context_destroy = destroy_encrypt_context;
        nc->ctx.get_output_length = get_encrypt_output_length;
-       nc->ctx.set_param = set_encrypt_property;
-       nc->ctx.get_param = get_encrypt_property;
+       nc->ctx.set_property = set_encrypt_property;
+       nc->ctx.get_property = get_encrypt_property;
        nc->op_type = OP_OPEN;
        nc->tag_len = 0;
 
@@ -221,25 +221,25 @@ API int yaca_open_initialize(yaca_context_h *ctx,
                goto exit;
        }
 
-       iv_bits = ret * 8;
-       if (iv_bits == 0 && iv != NULL) { /* 0 -> cipher doesn't use iv, but it was provided */
+       iv_bit_len = ret * 8;
+       if (iv_bit_len == 0 && iv != NULL) { /* 0 -> cipher doesn't use iv, but it was provided */
                ret = YACA_ERROR_INVALID_PARAMETER;
                goto exit;
        }
 
-       if (iv_bits > 0) { /* cipher requires iv*/
+       if (iv_bit_len > 0) { /* cipher requires iv*/
                liv = key_get_simple(iv);
                if (liv == NULL || liv->key.type != YACA_KEY_TYPE_IV) { /* iv was not provided */
                        ret = YACA_ERROR_INVALID_PARAMETER;
                        goto exit;
                }
-               ret = yaca_key_get_bit_length(iv, &iv_bits_check);
+               ret = yaca_key_get_bit_length(iv, &iv_bit_len_check);
                if (ret != YACA_ERROR_NONE) {
                        ret = YACA_ERROR_INVALID_PARAMETER;
                        goto exit;
                }
                /* IV length doesn't match cipher */
-               if (iv_bits != iv_bits_check) {
+               if (iv_bit_len != iv_bit_len_check) {
                        ret = YACA_ERROR_INVALID_PARAMETER;
                        goto exit;
                }
index acb0392..a159e50 100644 (file)
@@ -43,21 +43,21 @@ enum sign_op_type {
        OP_VERIFY = 1
 };
 
-struct yaca_sign_ctx_s {
+struct yaca_sign_context_s {
        struct yaca_context_s ctx;
 
-       EVP_MD_CTX *mdctx;
+       EVP_MD_CTX *md_ctx;
        enum sign_op_type op_type;
 };
 
-static struct yaca_sign_ctx_s *get_sign_ctx(const yaca_context_h ctx)
+static struct yaca_sign_context_s *get_sign_context(const yaca_context_h ctx)
 {
        if (ctx == YACA_CONTEXT_NULL)
                return NULL;
 
        switch (ctx->type) {
-       case YACA_CTX_SIGN:
-               return (struct yaca_sign_ctx_s *)ctx;
+       case YACA_CONTEXT_SIGN:
+               return (struct yaca_sign_context_s *)ctx;
        default:
                return NULL;
        }
@@ -69,17 +69,17 @@ static int get_sign_output_length(const yaca_context_h ctx,
 {
        assert(output_len != NULL);
 
-       struct yaca_sign_ctx_s *c = get_sign_ctx(ctx);
+       struct yaca_sign_context_s *c = get_sign_context(ctx);
 
        if (c == NULL || input_len != 0)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       assert(c->mdctx != NULL);
+       assert(c->md_ctx != NULL);
 
-       if (c->mdctx->pctx == NULL)
+       if (c->md_ctx->pctx == NULL)
                return YACA_ERROR_INTERNAL;
 
-       EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(c->mdctx->pctx);
+       EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(c->md_ctx->pctx);
        if (pkey == NULL) {
                ERROR_DUMP(YACA_ERROR_INTERNAL);
                return YACA_ERROR_INTERNAL;
@@ -97,22 +97,22 @@ static int get_sign_output_length(const yaca_context_h ctx,
 
 static void destroy_sign_context(yaca_context_h ctx)
 {
-       struct yaca_sign_ctx_s *c = get_sign_ctx(ctx);
+       struct yaca_sign_context_s *c = get_sign_context(ctx);
 
        if (c == NULL)
                return;
 
-       EVP_MD_CTX_destroy(c->mdctx);
-       c->mdctx = NULL;
+       EVP_MD_CTX_destroy(c->md_ctx);
+       c->md_ctx = NULL;
 }
 
-int set_sign_param(yaca_context_h ctx,
-                   yaca_property_e param,
-                   const void *value,
-                   size_t value_len)
+int set_sign_property(yaca_context_h ctx,
+                      yaca_property_e property,
+                      const void *value,
+                      size_t value_len)
 {
        int ret;
-       struct yaca_sign_ctx_s *c = get_sign_ctx(ctx);
+       struct yaca_sign_context_s *c = get_sign_context(ctx);
        yaca_padding_e padding;
        int pad;
        EVP_PKEY *pkey;
@@ -120,13 +120,13 @@ int set_sign_param(yaca_context_h ctx,
        if (c == NULL || value == NULL)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       assert(c->mdctx != NULL);
+       assert(c->md_ctx != NULL);
 
-       if (c->mdctx->pctx == NULL)
+       if (c->md_ctx->pctx == NULL)
                return YACA_ERROR_INTERNAL;
 
        /* this function only supports padding */
-       if (param != YACA_PROPERTY_PADDING || value_len != sizeof(yaca_padding_e))
+       if (property != YACA_PROPERTY_PADDING || value_len != sizeof(yaca_padding_e))
                return YACA_ERROR_INVALID_PARAMETER;
 
        padding = *(yaca_padding_e *)(value);
@@ -147,7 +147,7 @@ int set_sign_param(yaca_context_h ctx,
                return YACA_ERROR_INVALID_PARAMETER;
        }
 
-       pkey = EVP_PKEY_CTX_get0_pkey(c->mdctx->pctx);
+       pkey = EVP_PKEY_CTX_get0_pkey(c->md_ctx->pctx);
        if (pkey == NULL) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
@@ -158,7 +158,7 @@ int set_sign_param(yaca_context_h ctx,
        if (pkey->type != EVP_PKEY_RSA)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       ret = EVP_PKEY_CTX_set_rsa_padding(c->mdctx->pctx, pad);
+       ret = EVP_PKEY_CTX_set_rsa_padding(c->md_ctx->pctx, pad);
        if (ret <= 0) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
@@ -168,13 +168,13 @@ int set_sign_param(yaca_context_h ctx,
        return YACA_ERROR_NONE;
 }
 
-int get_sign_param(const yaca_context_h ctx,
-                   yaca_property_e param,
-                   void **value,
-                   size_t *value_len)
+int get_sign_property(const yaca_context_h ctx,
+                      yaca_property_e property,
+                      void **value,
+                      size_t *value_len)
 {
        int ret;
-       struct yaca_sign_ctx_s *c = get_sign_ctx(ctx);
+       struct yaca_sign_context_s *c = get_sign_context(ctx);
        EVP_PKEY *pkey;
        int pad;
        yaca_padding_e padding;
@@ -182,16 +182,16 @@ int get_sign_param(const yaca_context_h ctx,
        if (c == NULL || value == NULL)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       assert(c->mdctx != NULL);
+       assert(c->md_ctx != NULL);
 
-       if (c->mdctx->pctx == NULL)
+       if (c->md_ctx->pctx == NULL)
                return YACA_ERROR_INTERNAL;
 
        /* this function only supports padding */
-       if (param != YACA_PROPERTY_PADDING)
+       if (property != YACA_PROPERTY_PADDING)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       pkey = EVP_PKEY_CTX_get0_pkey(c->mdctx->pctx);
+       pkey = EVP_PKEY_CTX_get0_pkey(c->md_ctx->pctx);
        if (pkey == NULL) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
@@ -202,7 +202,7 @@ int get_sign_param(const yaca_context_h ctx,
        if (pkey->type != EVP_PKEY_RSA)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       ret = EVP_PKEY_CTX_get_rsa_padding(c->mdctx->pctx, &pad);
+       ret = EVP_PKEY_CTX_get_rsa_padding(c->md_ctx->pctx, &pad);
        if (ret <= 0) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
@@ -240,7 +240,7 @@ API int yaca_sign_initialize(yaca_context_h *ctx,
                              yaca_digest_algorithm_e algo,
                              const yaca_key_h key)
 {
-       struct yaca_sign_ctx_s *nc = NULL;
+       struct yaca_sign_context_s *nc = NULL;
        const EVP_MD *md = NULL;
        int ret;
        const struct yaca_key_evp_s *evp_key = key_get_evp(key);
@@ -258,29 +258,29 @@ API int yaca_sign_initialize(yaca_context_h *ctx,
                return YACA_ERROR_INVALID_PARAMETER;
        }
 
-       ret = yaca_zalloc(sizeof(struct yaca_sign_ctx_s), (void**)&nc);
+       ret = yaca_zalloc(sizeof(struct yaca_sign_context_s), (void**)&nc);
        if (ret != YACA_ERROR_NONE)
                return ret;
 
        nc->op_type = OP_SIGN;
-       nc->ctx.type = YACA_CTX_SIGN;
-       nc->ctx.ctx_destroy = destroy_sign_context;
+       nc->ctx.type = YACA_CONTEXT_SIGN;
+       nc->ctx.context_destroy = destroy_sign_context;
        nc->ctx.get_output_length = get_sign_output_length;
-       nc->ctx.set_param = set_sign_param;
-       nc->ctx.get_param = get_sign_param;
+       nc->ctx.set_property = set_sign_property;
+       nc->ctx.get_property = get_sign_property;
 
        ret = digest_get_algorithm(algo, &md);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       nc->mdctx = EVP_MD_CTX_create();
-       if (nc->mdctx == NULL) {
+       nc->md_ctx = EVP_MD_CTX_create();
+       if (nc->md_ctx == NULL) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
                goto exit;
        }
 
-       ret = EVP_DigestSignInit(nc->mdctx, NULL, md, NULL, evp_key->evp);
+       ret = EVP_DigestSignInit(nc->md_ctx, NULL, md, NULL, evp_key->evp);
        if (ret != 1) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
@@ -301,7 +301,7 @@ API int yaca_sign_initialize_hmac(yaca_context_h *ctx,
                                   yaca_digest_algorithm_e algo,
                                   const yaca_key_h key)
 {
-       struct yaca_sign_ctx_s *nc = NULL;
+       struct yaca_sign_context_s *nc = NULL;
        EVP_PKEY *pkey = NULL;
        const EVP_MD *md;
        int ret;
@@ -311,19 +311,19 @@ API int yaca_sign_initialize_hmac(yaca_context_h *ctx,
            (key->type != YACA_KEY_TYPE_SYMMETRIC && key->type != YACA_KEY_TYPE_DES))
                return YACA_ERROR_INVALID_PARAMETER;
 
-       ret = yaca_zalloc(sizeof(struct yaca_sign_ctx_s), (void**)&nc);
+       ret = yaca_zalloc(sizeof(struct yaca_sign_context_s), (void**)&nc);
        if (ret != YACA_ERROR_NONE)
                return ret;
 
        nc->op_type = OP_SIGN;
-       nc->ctx.type = YACA_CTX_SIGN;
-       nc->ctx.ctx_destroy = destroy_sign_context;
+       nc->ctx.type = YACA_CONTEXT_SIGN;
+       nc->ctx.context_destroy = destroy_sign_context;
        nc->ctx.get_output_length = get_sign_output_length;
 
        pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC,
                                    NULL,
                                    (unsigned char *)simple_key->d,
-                                   simple_key->bits / 8);
+                                   simple_key->bit_len / 8);
        if (pkey == NULL) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
@@ -334,14 +334,14 @@ API int yaca_sign_initialize_hmac(yaca_context_h *ctx,
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       nc->mdctx = EVP_MD_CTX_create();
-       if (nc->mdctx == NULL) {
+       nc->md_ctx = EVP_MD_CTX_create();
+       if (nc->md_ctx == NULL) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
                goto exit;
        }
 
-       ret = EVP_DigestSignInit(nc->mdctx, NULL, md, NULL, pkey);
+       ret = EVP_DigestSignInit(nc->md_ctx, NULL, md, NULL, pkey);
        if (ret != 1) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
@@ -365,7 +365,7 @@ API int yaca_sign_initialize_cmac(yaca_context_h *ctx,
                                   yaca_encrypt_algorithm_e algo,
                                   const yaca_key_h key)
 {
-       struct yaca_sign_ctx_s *nc = NULL;
+       struct yaca_sign_context_s *nc = NULL;
        CMAC_CTX* cmac_ctx = NULL;
        const EVP_CIPHER* cipher = NULL;
        EVP_PKEY *pkey = NULL;
@@ -376,16 +376,16 @@ API int yaca_sign_initialize_cmac(yaca_context_h *ctx,
            (key->type != YACA_KEY_TYPE_SYMMETRIC && key->type != YACA_KEY_TYPE_DES))
                return YACA_ERROR_INVALID_PARAMETER;
 
-       ret = yaca_zalloc(sizeof(struct yaca_sign_ctx_s), (void**)&nc);
+       ret = yaca_zalloc(sizeof(struct yaca_sign_context_s), (void**)&nc);
        if (ret != YACA_ERROR_NONE)
                return ret;
 
        nc->op_type = OP_SIGN;
-       nc->ctx.type = YACA_CTX_SIGN;
-       nc->ctx.ctx_destroy = destroy_sign_context;
+       nc->ctx.type = YACA_CONTEXT_SIGN;
+       nc->ctx.context_destroy = destroy_sign_context;
        nc->ctx.get_output_length = get_sign_output_length;
 
-       ret = encrypt_get_algorithm(algo, YACA_BCM_CBC, simple_key->bits, &cipher);
+       ret = encrypt_get_algorithm(algo, YACA_BCM_CBC, simple_key->bit_len, &cipher);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
@@ -397,7 +397,7 @@ API int yaca_sign_initialize_cmac(yaca_context_h *ctx,
                goto exit;
        }
 
-       if (CMAC_Init(cmac_ctx, simple_key->d, simple_key->bits / 8, cipher, NULL) != 1) {
+       if (CMAC_Init(cmac_ctx, simple_key->d, simple_key->bit_len / 8, cipher, NULL) != 1) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
                goto exit;
@@ -419,14 +419,14 @@ API int yaca_sign_initialize_cmac(yaca_context_h *ctx,
 
        cmac_ctx = NULL;
 
-       nc->mdctx = EVP_MD_CTX_create();
-       if (nc->mdctx == NULL) {
+       nc->md_ctx = EVP_MD_CTX_create();
+       if (nc->md_ctx == NULL) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
                goto exit;
        }
 
-       if (EVP_DigestSignInit(nc->mdctx, NULL, NULL, NULL, pkey) != 1) {
+       if (EVP_DigestSignInit(nc->md_ctx, NULL, NULL, NULL, pkey) != 1) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
                goto exit;
@@ -450,14 +450,14 @@ API int yaca_sign_update(yaca_context_h ctx,
                          const char *data,
                          size_t data_len)
 {
-       struct yaca_sign_ctx_s *c = get_sign_ctx(ctx);
+       struct yaca_sign_context_s *c = get_sign_context(ctx);
        int ret;
 
        if (c == NULL || c->op_type != OP_SIGN ||
            data == NULL || data_len == 0)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       ret = EVP_DigestSignUpdate(c->mdctx, data, data_len);
+       ret = EVP_DigestSignUpdate(c->md_ctx, data, data_len);
        if (ret != 1) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
@@ -471,14 +471,14 @@ API int yaca_sign_finalize(yaca_context_h ctx,
                            char *signature,
                            size_t *signature_len)
 {
-       struct yaca_sign_ctx_s *c = get_sign_ctx(ctx);
+       struct yaca_sign_context_s *c = get_sign_context(ctx);
        int ret;
 
        if (c == NULL ||  c->op_type != OP_SIGN ||
            signature == NULL || signature_len == NULL || *signature_len == 0)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       ret = EVP_DigestSignFinal(c->mdctx, (unsigned char *)signature, signature_len);
+       ret = EVP_DigestSignFinal(c->md_ctx, (unsigned char *)signature, signature_len);
        if (ret != 1) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
@@ -492,7 +492,7 @@ API int yaca_verify_initialize(yaca_context_h *ctx,
                                yaca_digest_algorithm_e algo,
                                const yaca_key_h key)
 {
-       struct yaca_sign_ctx_s *nc = NULL;
+       struct yaca_sign_context_s *nc = NULL;
        const EVP_MD *md = NULL;
        int ret;
        const struct yaca_key_evp_s *evp_key = key_get_evp(key);
@@ -510,29 +510,29 @@ API int yaca_verify_initialize(yaca_context_h *ctx,
                return YACA_ERROR_INVALID_PARAMETER;
        }
 
-       ret = yaca_zalloc(sizeof(struct yaca_sign_ctx_s), (void**)&nc);
+       ret = yaca_zalloc(sizeof(struct yaca_sign_context_s), (void**)&nc);
        if (ret != YACA_ERROR_NONE)
                return ret;
 
        nc->op_type = OP_VERIFY;
-       nc->ctx.type = YACA_CTX_SIGN;
-       nc->ctx.ctx_destroy = destroy_sign_context;
+       nc->ctx.type = YACA_CONTEXT_SIGN;
+       nc->ctx.context_destroy = destroy_sign_context;
        nc->ctx.get_output_length = NULL;
-       nc->ctx.set_param = set_sign_param;
-       nc->ctx.get_param = get_sign_param;
+       nc->ctx.set_property = set_sign_property;
+       nc->ctx.get_property = get_sign_property;
 
        ret = digest_get_algorithm(algo, &md);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       nc->mdctx = EVP_MD_CTX_create();
-       if (nc->mdctx == NULL) {
+       nc->md_ctx = EVP_MD_CTX_create();
+       if (nc->md_ctx == NULL) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
                goto exit;
        }
 
-       ret = EVP_DigestVerifyInit(nc->mdctx, NULL, md, NULL, evp_key->evp);
+       ret = EVP_DigestVerifyInit(nc->md_ctx, NULL, md, NULL, evp_key->evp);
        if (ret != 1) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
@@ -553,13 +553,13 @@ API int yaca_verify_update(yaca_context_h ctx,
                            const char *data,
                            size_t data_len)
 {
-       struct yaca_sign_ctx_s *c = get_sign_ctx(ctx);
+       struct yaca_sign_context_s *c = get_sign_context(ctx);
        int ret;
 
        if (c == NULL || data == NULL || data_len == 0 || c->op_type != OP_VERIFY)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       ret = EVP_DigestVerifyUpdate(c->mdctx, data, data_len);
+       ret = EVP_DigestVerifyUpdate(c->md_ctx, data, data_len);
        if (ret != 1) {
                ret = YACA_ERROR_INTERNAL;
                ERROR_DUMP(ret);
@@ -573,13 +573,13 @@ API int yaca_verify_finalize(yaca_context_h ctx,
                              const char *signature,
                              size_t signature_len)
 {
-       struct yaca_sign_ctx_s *c = get_sign_ctx(ctx);
+       struct yaca_sign_context_s *c = get_sign_context(ctx);
        int ret;
 
        if (c == NULL || signature == NULL || signature_len == 0 || c->op_type != OP_VERIFY)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       ret = EVP_DigestVerifyFinal(c->mdctx,
+       ret = EVP_DigestVerifyFinal(c->md_ctx,
                                    (unsigned char *)signature,
                                    signature_len);
 
index f1ee20a..101822d 100644 (file)
@@ -94,8 +94,8 @@ API int yaca_simple_encrypt(yaca_encrypt_algorithm_e algo,
 {
        yaca_context_h ctx;
        int ret;
-       char *lcipher = NULL;
-       size_t out_len, lcipher_len, written;
+       char *lciphertext = NULL;
+       size_t out_len, lciphertext_len, written;
 
        if (plaintext == NULL || plaintext_len == 0 ||
            ciphertext == NULL || ciphertext_len == NULL ||
@@ -110,50 +110,50 @@ API int yaca_simple_encrypt(yaca_encrypt_algorithm_e algo,
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       ret = yaca_context_get_output_length(ctx, 0, &lcipher_len);
+       ret = yaca_context_get_output_length(ctx, 0, &lciphertext_len);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       if (out_len > SIZE_MAX - lcipher_len) {
+       if (out_len > SIZE_MAX - lciphertext_len) {
                ret = YACA_ERROR_INVALID_PARAMETER;
                goto exit;
        }
 
-       lcipher_len += out_len;
+       lciphertext_len += out_len;
 
-       assert(lcipher_len > 0);
+       assert(lciphertext_len > 0);
 
-       ret = yaca_malloc(lcipher_len, (void**)&lcipher);
+       ret = yaca_malloc(lciphertext_len, (void**)&lciphertext);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       out_len = lcipher_len;
-       ret = yaca_encrypt_update(ctx, plaintext, plaintext_len, lcipher, &out_len);
+       out_len = lciphertext_len;
+       ret = yaca_encrypt_update(ctx, plaintext, plaintext_len, lciphertext, &out_len);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       assert(out_len <= lcipher_len);
+       assert(out_len <= lciphertext_len);
 
        written = out_len;
-       out_len = lcipher_len - written;
-       ret = yaca_encrypt_finalize(ctx, lcipher + written, &out_len);
+       out_len = lciphertext_len - written;
+       ret = yaca_encrypt_finalize(ctx, lciphertext + written, &out_len);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
        written += out_len;
-       assert(written <= lcipher_len && written > 0);
+       assert(written <= lciphertext_len && written > 0);
 
-       ret = yaca_realloc(written, (void**)&lcipher);
+       ret = yaca_realloc(written, (void**)&lciphertext);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       *ciphertext = lcipher;
+       *ciphertext = lciphertext;
        *ciphertext_len = written;
-       lcipher = NULL;
+       lciphertext = NULL;
        ret = YACA_ERROR_NONE;
 
 exit:
-       yaca_free(lcipher);
+       yaca_free(lciphertext);
        yaca_context_destroy(ctx);
 
        return ret;
@@ -170,8 +170,8 @@ API int yaca_simple_decrypt(yaca_encrypt_algorithm_e algo,
 {
        yaca_context_h ctx;
        int ret;
-       char *lplain = NULL;
-       size_t out_len, lplain_len, written;
+       char *lplaintext = NULL;
+       size_t out_len, lplaintext_len, written;
 
        if (ciphertext == NULL || ciphertext_len == 0 ||
            plaintext == NULL || plaintext_len == NULL ||
@@ -186,49 +186,49 @@ API int yaca_simple_decrypt(yaca_encrypt_algorithm_e algo,
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       ret = yaca_context_get_output_length(ctx, 0, &lplain_len);
+       ret = yaca_context_get_output_length(ctx, 0, &lplaintext_len);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       if (out_len > SIZE_MAX - lplain_len) {
+       if (out_len > SIZE_MAX - lplaintext_len) {
                ret = YACA_ERROR_INVALID_PARAMETER;
                goto exit;
        }
 
-       lplain_len += out_len;
-       assert(lplain_len > 0);
+       lplaintext_len += out_len;
+       assert(lplaintext_len > 0);
 
-       ret = yaca_malloc(lplain_len, (void**)&lplain);
+       ret = yaca_malloc(lplaintext_len, (void**)&lplaintext);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       out_len = lplain_len;
-       ret = yaca_decrypt_update(ctx, ciphertext, ciphertext_len, lplain, &out_len);
+       out_len = lplaintext_len;
+       ret = yaca_decrypt_update(ctx, ciphertext, ciphertext_len, lplaintext, &out_len);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       assert(out_len <= lplain_len);
+       assert(out_len <= lplaintext_len);
 
        written = out_len;
-       out_len = lplain_len - written;
-       ret = yaca_decrypt_finalize(ctx, lplain + written, &out_len);
+       out_len = lplaintext_len - written;
+       ret = yaca_decrypt_finalize(ctx, lplaintext + written, &out_len);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
        written += out_len;
-       assert(written <= lplain_len && written > 0);
+       assert(written <= lplaintext_len && written > 0);
 
-       ret = yaca_realloc(written, (void**)&lplain);
+       ret = yaca_realloc(written, (void**)&lplaintext);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       *plaintext = lplain;
+       *plaintext = lplaintext;
        *plaintext_len = written;
-       lplain = NULL;
+       lplaintext = NULL;
        ret = YACA_ERROR_NONE;
 
 exit:
-       yaca_free(lplain);
+       yaca_free(lplaintext);
        yaca_context_destroy(ctx);
 
        return ret;