From: Dariusz Michaluk Date: Wed, 8 Jun 2016 09:05:59 +0000 (+0200) Subject: Use C89 style for comments. X-Git-Tag: accepted/tizen/common/20160810.161523~61 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d79b648a81a8ea217105f20d3ba2bc106a2d4abc;p=platform%2Fcore%2Fsecurity%2Fyaca.git Use C89 style for comments. Minor codestyle and comments cleanup. Change-Id: I014b52d96ddc10ba9186ac0bd692b112ba10aefe --- diff --git a/examples/key_exchange.c b/examples/key_exchange.c index 4f93eff..eb9beae 100644 --- a/examples/key_exchange.c +++ b/examples/key_exchange.c @@ -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; diff --git a/examples/misc.h b/examples/misc.h index b2e1cbd..843aba2 100644 --- a/examples/misc.h +++ b/examples/misc.h @@ -26,14 +26,7 @@ #include -// 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); diff --git a/examples/sign.c b/examples/sign.c index 60057b4..a3d88ff 100644 --- a/examples/sign.c +++ b/examples/sign.c @@ -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; diff --git a/src/digest.c b/src/digest.c index d5d7278..0191e96 100644 --- a/src/digest.c +++ b/src/digest.c @@ -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); diff --git a/src/encrypt.c b/src/encrypt.c index 324e829..a53a442 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -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); diff --git a/src/key.c b/src/key.c index 2ba9b9e..8f02b3c 100644 --- 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; diff --git a/src/sign.c b/src/sign.c index 9da9385..afaaec0 100644 --- a/src/sign.c +++ b/src/sign.c @@ -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;