From: Krzysztof Jackiewicz Date: Mon, 23 May 2016 10:33:52 +0000 (+0200) Subject: Use "!= 0" instead of "< 0" when handling yaca errors X-Git-Tag: accepted/tizen/common/20160810.161523~129 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6c04ec20579c2ca54ef70aa422b12b6bc8171c49;p=platform%2Fcore%2Fsecurity%2Fyaca.git Use "!= 0" instead of "< 0" when handling yaca errors Change-Id: I8b298d9125d84b85c36cbde9ada9dc48af4e9402 --- diff --git a/examples/digest.c b/examples/digest.c index 68c6bcb..9c68be3 100644 --- a/examples/digest.c +++ b/examples/digest.c @@ -39,7 +39,7 @@ void digest_simple(void) ret = yaca_digest_calc(YACA_DIGEST_SHA256, lorem1024, 1024, &digest, &digest_len); - if (ret < 0) + if (ret != 0) return; dump_hex(digest, digest_len, "Message digest: "); @@ -53,11 +53,11 @@ void digest_advanced(void) yaca_ctx_h ctx; ret = yaca_digest_init(&ctx, YACA_DIGEST_SHA256); - if (ret < 0) + if (ret != 0) return; ret = yaca_digest_update(ctx, lorem1024, 1024); - if (ret < 0) + if (ret != 0) goto exit_ctx; size_t digest_len; @@ -69,7 +69,7 @@ void digest_advanced(void) char digest[digest_len]; ret = yaca_digest_final(ctx, digest, &digest_len); - if (ret < 0) + if (ret != 0) goto exit_ctx; dump_hex(digest, digest_len, "Message digest: "); @@ -84,7 +84,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret < 0) + if (ret != 0) return ret; digest_simple(); diff --git a/examples/encrypt.c b/examples/encrypt.c index c01ab04..d436f52 100644 --- a/examples/encrypt.c +++ b/examples/encrypt.c @@ -186,7 +186,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret < 0) + if (ret != 0) return ret; yaca_enc_algo_e algo = YACA_ENC_AES; diff --git a/examples/encrypt_aes_gcm.c b/examples/encrypt_aes_gcm.c index 1e61bc3..c89127e 100644 --- a/examples/encrypt_aes_gcm.c +++ b/examples/encrypt_aes_gcm.c @@ -58,22 +58,22 @@ void encrypt_decrypt_aes_gcm(void) /// Key generation ret = yaca_key_gen(&key, YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_256BIT); // key_type, key_len, *key ? looks imo much better - if (ret < 0) + if (ret != 0) goto clean; // use YACA_KEY_IV_128BIT & YACA_KEY_TYPE_IV or maybe YACA_KEY_128BIT & YACA_KEY_TYPE_SYMMETRIC ? ret = yaca_key_gen(&iv, YACA_KEY_TYPE_IV, YACA_KEY_IV_128BIT); - if (ret < 0) + if (ret != 0) goto clean; // use YACA_KEY_128BIT & YACA_KEY_TYPE_SYMMETRIC or maybe add YACA_KEY_AAD_128BIT & YACA_KEY_TYPE_AAD ? ret = yaca_key_gen(&aad_key, YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_UNSAFE_128BIT); - if (ret < 0) + if (ret != 0) goto clean; // generate and export aad? ret = yaca_key_export(aad_key, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_RAW, NULL, &aad, &aad_len); - if (ret < 0) + if (ret != 0) goto clean; /// Encryption @@ -81,11 +81,11 @@ void encrypt_decrypt_aes_gcm(void) size_t len; ret = yaca_encrypt_init(&ctx, YACA_ENC_AES, YACA_BCM_GCM, key, iv); - if (ret < 0) + if (ret != 0) goto clean; ret = yaca_ctx_set_param(ctx, YACA_PARAM_GCM_AAD, aad, aad_len); - if (ret < 0) + if (ret != 0) goto clean; ret = yaca_get_output_length(ctx, LOREM4096_SIZE, &ciphertext_len); @@ -102,19 +102,19 @@ void encrypt_decrypt_aes_gcm(void) goto clean; ret = yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, ciphertext, &len); - if (ret < 0) + if (ret != 0) goto clean; ciphertext_len = len; ret = yaca_encrypt_final(ctx, ciphertext + len, &len); - if (ret < 0) + if (ret != 0) goto clean; ciphertext_len += len; ret = yaca_ctx_get_param(ctx, YACA_PARAM_GCM_TAG, (void*)&tag, &tag_len); - if (ret < 0) + if (ret != 0) goto clean; dump_hex(ciphertext, 16, "Encrypted data (16 of %zu bytes): ", ciphertext_len); @@ -127,11 +127,11 @@ void encrypt_decrypt_aes_gcm(void) size_t len; ret = yaca_decrypt_init(&ctx, YACA_ENC_AES, YACA_BCM_GCM, key, iv); - if (ret < 0) + if (ret != 0) goto clean; ret = yaca_ctx_set_param(ctx, YACA_PARAM_GCM_AAD, aad, aad_len); - if (ret < 0) + if (ret != 0) goto clean; ret = yaca_get_output_length(ctx, ciphertext_len, &plaintext_len); @@ -148,17 +148,17 @@ void encrypt_decrypt_aes_gcm(void) goto clean; ret = yaca_decrypt_update(ctx, ciphertext, ciphertext_len, plaintext, &len); - if (ret < 0) + if (ret != 0) goto clean; plaintext_len = len; ret = yaca_ctx_set_param(ctx, YACA_PARAM_GCM_TAG, tag, tag_len); - if (ret < 0) + if (ret != 0) goto clean; ret = yaca_encrypt_final(ctx, plaintext + len, &len); - if (ret < 0) + if (ret != 0) goto clean; plaintext_len += len; @@ -184,7 +184,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret < 0) + if (ret != 0) return ret; encrypt_decrypt_aes_gcm(); diff --git a/examples/key_exchange.c b/examples/key_exchange.c index 7d2bf78..90c0cd3 100644 --- a/examples/key_exchange.c +++ b/examples/key_exchange.c @@ -45,11 +45,11 @@ void key_exchange_dh(void) // generate private, public key ret = yaca_key_gen(&private_key, YACA_KEY_TYPE_DH_PRIV, YACA_KEY_2048BIT); - if (ret < 0) + if (ret != 0) goto clean; ret = yaca_key_extract_public(private_key, &public_key); - if (ret < 0) + if (ret != 0) goto clean; // get peer public key from file @@ -72,12 +72,12 @@ void key_exchange_dh(void) ret = yaca_key_import(&peer_key, YACA_KEY_TYPE_DH_PUB, NULL, buffer, size); - if (ret < 0) + if (ret != 0) goto clean; // derive secret ret = yaca_key_derive_dh(private_key, peer_key, &secret); - if (ret < 0) + if (ret != 0) goto clean; clean: @@ -105,11 +105,11 @@ void key_exchange_ecdh(void) // generate private, public key ret = yaca_key_gen(&private_key, YACA_KEY_TYPE_EC_PRIV, YACA_KEY_CURVE_P256); - if (ret < 0) + if (ret != 0) goto clean; ret = yaca_key_extract_public(private_key, &public_key); - if (ret < 0) + if (ret != 0) goto clean; // get peer public key from file @@ -131,12 +131,12 @@ void key_exchange_ecdh(void) goto clean; ret = yaca_key_import(&peer_key, YACA_KEY_TYPE_EC_PUB, NULL, buffer, size); - if (ret < 0) + if (ret != 0) goto clean; // derive secret ret = yaca_key_derive_dh(private_key, peer_key, &secret); - if (ret < 0) + if (ret != 0) goto clean; clean: @@ -154,7 +154,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret < 0) + if (ret != 0) return ret; key_exchange_dh(); diff --git a/examples/seal.c b/examples/seal.c index 5d34da1..2f47074 100644 --- a/examples/seal.c +++ b/examples/seal.c @@ -143,7 +143,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret < 0) + if (ret != 0) return ret; encrypt_seal(); diff --git a/examples/sign.c b/examples/sign.c index 1981b27..8555f8c 100644 --- a/examples/sign.c +++ b/examples/sign.c @@ -216,7 +216,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret < 0) + if (ret != 0) return ret; // TODO simple? diff --git a/src/digest.c b/src/digest.c index 09fbd34..71f928a 100644 --- a/src/digest.c +++ b/src/digest.c @@ -131,7 +131,7 @@ API int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo) nc->ctx.get_output_length = get_digest_output_length; ret = digest_get_algorithm(algo, &md); - if (ret < 0) + if (ret != 0) goto free; nc->mdctx = EVP_MD_CTX_create(); diff --git a/src/encrypt.c b/src/encrypt.c index 86572e2..0237af9 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -429,7 +429,7 @@ API int yaca_get_iv_bits(yaca_enc_algo_e algo, int ret; ret = encrypt_get_algorithm(algo, bcm, key_bits, &cipher); - if (ret < 0) + if (ret != 0) return ret; ret = EVP_CIPHER_iv_length(cipher); diff --git a/src/key.c b/src/key.c index d8580a8..4c3b8a5 100644 --- a/src/key.c +++ b/src/key.c @@ -1111,7 +1111,7 @@ API int yaca_key_derive_pbkdf2(const char *password, return YACA_ERROR_TOO_BIG_ARGUMENT; ret = digest_get_algorithm(algo, &md); - if (ret < 0) + if (ret != 0) return ret; nk = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_byte_len); diff --git a/src/sign.c b/src/sign.c index 4e119be..d36155b 100644 --- a/src/sign.c +++ b/src/sign.c @@ -511,7 +511,7 @@ API int yaca_verify_init(yaca_ctx_h *ctx, } ret = digest_get_algorithm(algo, &md); - if (ret < 0) + if (ret != 0) goto free_ctx; nc->mdctx = EVP_MD_CTX_create(); diff --git a/src/simple.c b/src/simple.c index d82d4f2..e55aea1 100644 --- a/src/simple.c +++ b/src/simple.c @@ -46,11 +46,11 @@ API int yaca_digest_calc(yaca_digest_algo_e algo, return YACA_ERROR_INVALID_ARGUMENT; ret = yaca_digest_init(&ctx, algo); - if (ret < 0) + if (ret != 0) return ret; ret = yaca_digest_update(ctx, data, data_len); - if (ret < 0) + if (ret != 0) goto err; ret = yaca_get_digest_length(ctx, &ldigest_len); @@ -62,7 +62,7 @@ API int yaca_digest_calc(yaca_digest_algo_e algo, goto err; ret = yaca_digest_final(ctx, ldigest, &ldigest_len); - if (ret < 0) + if (ret != 0) goto err_free; yaca_ctx_free(ctx);