Use C89 style for comments. 99/73499/7
authorDariusz Michaluk <d.michaluk@samsung.com>
Wed, 8 Jun 2016 09:05:59 +0000 (11:05 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Wed, 8 Jun 2016 12:32:02 +0000 (14:32 +0200)
Minor codestyle and comments cleanup.

Change-Id: I014b52d96ddc10ba9186ac0bd692b112ba10aefe

examples/key_exchange.c
examples/misc.h
examples/sign.c
src/digest.c
src/encrypt.c
src/key.c
src/sign.c

index 4f93eff..eb9beae 100644 (file)
@@ -45,7 +45,7 @@ void key_exchange_dh(void)
        char *buffer = NULL;
        long size;
 
-       // generate  private, public key
+       /* generate  private, public key */
        ret = yaca_key_generate(YACA_KEY_TYPE_DH_PRIV, YACA_KEY_LENGTH_2048BIT, &private_key);
        if (ret != YACA_ERROR_NONE)
                goto exit;
@@ -54,8 +54,8 @@ void key_exchange_dh(void)
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       // get peer public key from file
-       // add helper to read key from file to buffer?
+       /* get peer public key */
+       // TODO: read key from file to buffer can be replaced with read_file() from misc.h
        fp = fopen("key.pub", "r");
        if (!fp) goto exit;
 
@@ -76,7 +76,7 @@ void key_exchange_dh(void)
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       // derive secret
+       /* derive secret */
        ret = yaca_key_derive_dh(private_key, peer_key, &secret);
        if (ret != YACA_ERROR_NONE)
                goto exit;
@@ -107,7 +107,7 @@ void key_exchange_ecdh(void)
        char *buffer = NULL;
        long size;
 
-       // generate  private, public key
+       /* generate  private, public key */
        ret = yaca_key_generate(YACA_KEY_TYPE_EC_PRIV, YACA_KEY_CURVE_P256, &private_key);
        if (ret != YACA_ERROR_NONE)
                goto exit;
@@ -116,7 +116,8 @@ void key_exchange_ecdh(void)
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       // get peer public key from file
+       /* get peer public key */
+       // TODO: read key from file to buffer can be replaced with read_file() from misc.h
        fp = fopen("key.pub", "r");
        if (fp == NULL)
                goto exit;
@@ -137,7 +138,7 @@ void key_exchange_ecdh(void)
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       // derive secret
+       /* derive secret */
        ret = yaca_key_derive_dh(private_key, peer_key, &secret);
        if (ret != YACA_ERROR_NONE)
                goto exit;
index b2e1cbd..843aba2 100644 (file)
 
 #include <stddef.h>
 
-// Various helper functions
-
-
-// Dumps dump_size of buf.
-// As a "heading" displays fmt message (formatted like printf)
-void dump_hex(const char *buf,
-              size_t dump_size,
-              const char *fmt, ...);
+void dump_hex(const char *buf, size_t dump_size, const char *fmt, ...);
 
 void debug_func(const char *buf);
 
index 60057b4..a3d88ff 100644 (file)
@@ -33,7 +33,7 @@
 #include "misc.h"
 #include "../src/debug.h"
 
-// Signature creation and verification using simple API
+/* Signature creation and verification using simple API */
 void simple_sign_verify_asym(yaca_key_type_e type, const char *algo)
 {
        char *signature = NULL;
@@ -42,14 +42,14 @@ void simple_sign_verify_asym(yaca_key_type_e type, const char *algo)
        yaca_key_h prv = YACA_KEY_NULL;
        yaca_key_h pub = YACA_KEY_NULL;
 
-       // GENERATE
+       /* GENERATE */
        if (yaca_key_generate(type, YACA_KEY_LENGTH_1024BIT, &prv) != YACA_ERROR_NONE)
                return;
 
        if (yaca_key_extract_public(prv, &pub) != YACA_ERROR_NONE)
                goto exit;
 
-       // SIGN
+       /* SIGN */
        if (yaca_simple_calculate_signature(YACA_DIGEST_SHA512,
                      prv,
                      lorem4096,
@@ -60,7 +60,7 @@ void simple_sign_verify_asym(yaca_key_type_e type, const char *algo)
 
        dump_hex(signature, signature_len, "[Simple API] %s Signature of lorem4096:", algo);
 
-       // VERIFY
+       /* VERIFY */
        if (yaca_simple_verify_signature(YACA_DIGEST_SHA512,
                        pub,
                        lorem4096,
@@ -85,11 +85,11 @@ void simple_sign_verify_hmac(void)
 
        yaca_key_h key = YACA_KEY_NULL;
 
-       // GENERATE
+       /* GENERATE */
        if (yaca_key_generate(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_LENGTH_256BIT, &key) != YACA_ERROR_NONE)
                return;
 
-       // SIGN
+       /* SIGN */
        if (yaca_simple_calculate_hmac(YACA_DIGEST_SHA512,
                      key,
                      lorem4096,
@@ -100,7 +100,7 @@ void simple_sign_verify_hmac(void)
 
        dump_hex(signature1, signature_len, "[Simple API] HMAC Signature of lorem4096:");
 
-       // VERIFY
+       /* VERIFY */
        if (yaca_simple_calculate_hmac(YACA_DIGEST_SHA512,
                      key,
                      lorem4096,
@@ -128,11 +128,11 @@ void simple_sign_verify_cmac(void)
 
        yaca_key_h key = YACA_KEY_NULL;
 
-       // GENERATE
+       /* GENERATE */
        if (yaca_key_generate(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_LENGTH_256BIT, &key))
                return;
 
-       // SIGN
+       /* SIGN */
        if (yaca_simple_calculate_cmac(YACA_ENCRYPT_AES,
                      key,
                      lorem4096,
@@ -144,7 +144,7 @@ void simple_sign_verify_cmac(void)
        dump_hex(signature1, signature_len, "[Simple API] CMAC Signature of lorem4096:");
 
 
-       // VERIFY
+       /* VERIFY */
        if (yaca_simple_calculate_cmac(YACA_ENCRYPT_AES,
                      key,
                      lorem4096,
@@ -164,7 +164,7 @@ exit:
        yaca_key_destroy(key);
 }
 
-// Signature creation and verification using advanced API
+/* Signature creation and verification using advanced API */
 void sign_verify_asym(yaca_key_type_e type, const char *algo)
 {
        char *signature = NULL;
@@ -175,14 +175,14 @@ void sign_verify_asym(yaca_key_type_e type, const char *algo)
        yaca_key_h pub = YACA_KEY_NULL;
        yaca_padding_e padding = YACA_PADDING_PKCS1_PSS;
 
-       // GENERATE
+       /* GENERATE */
        if (yaca_key_generate(type, YACA_KEY_LENGTH_1024BIT, &prv) != YACA_ERROR_NONE)
                return;
 
        if (yaca_key_extract_public(prv, &pub) != YACA_ERROR_NONE)
                goto exit;
 
-       // SIGN
+       /* SIGN */
        if (yaca_sign_initialize(&ctx, YACA_DIGEST_SHA512, prv) != YACA_ERROR_NONE)
                goto exit;
 
@@ -203,11 +203,11 @@ void sign_verify_asym(yaca_key_type_e type, const char *algo)
 
        dump_hex(signature, signature_len, "[Advanced API] %s Signature of lorem4096:", algo);
 
-       // CLEANUP
+       /* CLEANUP */
        yaca_context_destroy(ctx);
        ctx = YACA_CONTEXT_NULL;
 
-       // VERIFY
+       /* VERIFY */
        if (yaca_verify_initialize(&ctx, YACA_DIGEST_SHA512, pub) != YACA_ERROR_NONE)
                goto exit;
 
@@ -238,11 +238,11 @@ void sign_verify_hmac(void)
        yaca_context_h ctx = YACA_CONTEXT_NULL;
        yaca_key_h key = YACA_KEY_NULL;
 
-       // GENERATE
+       /* GENERATE */
        if (yaca_key_generate(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_LENGTH_256BIT, &key) != YACA_ERROR_NONE)
                return;
 
-       // SIGN
+       /* SIGN */
        if (yaca_sign_initialize_hmac(&ctx, YACA_DIGEST_SHA512, key) != YACA_ERROR_NONE)
                goto exit;
 
@@ -260,11 +260,11 @@ void sign_verify_hmac(void)
 
        dump_hex(signature1, signature_len, "[Advanced API] HMAC Signature of lorem4096:");
 
-       // CLEANUP
+       /* CLEANUP */
        yaca_context_destroy(ctx);
        ctx = YACA_CONTEXT_NULL;
 
-       // VERIFY
+       /* VERIFY */
        if (yaca_sign_initialize_hmac(&ctx, YACA_DIGEST_SHA512, key) != YACA_ERROR_NONE)
                goto exit;
 
@@ -301,11 +301,11 @@ void sign_verify_cmac(void)
        yaca_context_h ctx = YACA_CONTEXT_NULL;
        yaca_key_h key = YACA_KEY_NULL;
 
-       // GENERATE
+       /* GENERATE */
        if (yaca_key_generate(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_LENGTH_256BIT, &key))
                return;
 
-       // SIGN
+       /* SIGN */
        if (yaca_sign_initialize_cmac(&ctx, YACA_ENCRYPT_AES, key) != YACA_ERROR_NONE)
                goto exit;
 
@@ -323,11 +323,11 @@ void sign_verify_cmac(void)
 
        dump_hex(signature1, signature_len, "[Advanced API] CMAC Signature of lorem4096:");
 
-       // CLEANUP
+       /* CLEANUP */
        yaca_context_destroy(ctx);
        ctx = YACA_CONTEXT_NULL;
 
-       // VERIFY
+       /* VERIFY */
        if (yaca_sign_initialize_cmac(&ctx, YACA_ENCRYPT_AES, key) != YACA_ERROR_NONE)
                goto exit;
 
index d5d7278..0191e96 100644 (file)
@@ -190,7 +190,7 @@ API int yaca_digest_finalize(yaca_context_h ctx, char *digest, size_t *digest_le
        if (c == NULL || digest == NULL || digest_len == NULL)
                return YACA_ERROR_INVALID_PARAMETER;
 
-       if (*digest_len == 0 || *digest_len > UINT_MAX) // DigestFinal accepts uint
+       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);
index 324e829..a53a442 100644 (file)
@@ -291,7 +291,7 @@ int encrypt_get_algorithm(yaca_encrypt_algorithm_e algo,
 
        if (ret < 0)
                return YACA_ERROR_INVALID_PARAMETER;
-       if ((unsigned)ret >= sizeof(cipher_name)) // output was truncated
+       if ((unsigned)ret >= sizeof(cipher_name)) /* output was truncated */
                return YACA_ERROR_INVALID_PARAMETER;
 
        lcipher = EVP_get_cipherbyname(cipher_name);
index 2ba9b9e..8f02b3c 100644 (file)
--- a/src/key.c
+++ b/src/key.c
@@ -846,7 +846,7 @@ int gen_evp_dsa(struct yaca_key_evp_s **out, size_t key_bits)
 
        /* 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_bits < 512 || key_bits % 64 != 0)
                return YACA_ERROR_INVALID_PARAMETER;
 
        int ret;
index 9da9385..afaaec0 100644 (file)
@@ -386,7 +386,7 @@ API int yaca_sign_initialize_cmac(yaca_context_h *ctx,
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       // create and initialize low level CMAC context
+       /* create and initialize low level CMAC context */
        cmac_ctx = CMAC_CTX_new();
        if (cmac_ctx == NULL) {
                ret = YACA_ERROR_INTERNAL;
@@ -400,7 +400,7 @@ API int yaca_sign_initialize_cmac(yaca_context_h *ctx,
                goto exit;
        }
 
-       // create key and assign CMAC context to it
+       /* create key and assign CMAC context to it */
        pkey = EVP_PKEY_new();
        if (pkey == NULL) {
                ret = YACA_ERROR_INTERNAL;