From 4d45f43effc56dc4d826400ebdd042fb2796297a Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Fri, 6 May 2016 15:14:22 +0200 Subject: [PATCH] Remove YACA_ERROR_NOT_SUPPORTED Change-Id: I3f6b9cf907fc4fb4e0dd6dd84452f1448e223e65 --- api/yaca/error.h | 7 +++--- src/crypto.c | 23 ++++++------------- src/sign.c | 68 ++++++++++++++++++-------------------------------------- 3 files changed, 32 insertions(+), 66 deletions(-) diff --git a/api/yaca/error.h b/api/yaca/error.h index eaca621..944d8a3 100644 --- a/api/yaca/error.h +++ b/api/yaca/error.h @@ -41,10 +41,9 @@ enum __yaca_error_code { YACA_ERROR_INVALID_ARGUMENT = -1, YACA_ERROR_NOT_IMPLEMENTED = -2, YACA_ERROR_INTERNAL = -3, - YACA_ERROR_NOT_SUPPORTED = -4, - YACA_ERROR_TOO_BIG_ARGUMENT = -5, - YACA_ERROR_OUT_OF_MEMORY = -6, - YACA_ERROR_SIGNATURE_INVALID = -7 + YACA_ERROR_TOO_BIG_ARGUMENT = -4, + YACA_ERROR_OUT_OF_MEMORY = -5, + YACA_ERROR_SIGNATURE_INVALID = -6 }; // TODO disable debug function in release? diff --git a/src/crypto.c b/src/crypto.c index 734dba5..650bdcf 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -84,39 +84,30 @@ API int yaca_rand_bytes(char *data, size_t data_len) return YACA_ERROR_INVALID_ARGUMENT; ret = RAND_bytes((unsigned char *)data, data_len); - if (ret == 1) - return 0; - - if (ret == -1) - ret = YACA_ERROR_NOT_SUPPORTED; - else + if (ret != 1) { ret = YACA_ERROR_INTERNAL; + ERROR_DUMP(ret); + return ret; + } - ERROR_DUMP(ret); - return ret; + return 0; } API int yaca_ctx_set_param(yaca_ctx_h ctx, yaca_ex_param_e param, const void *value, size_t value_len) { - if (ctx == YACA_CTX_NULL) + if (ctx == YACA_CTX_NULL || ctx->set_param == NULL) return YACA_ERROR_INVALID_ARGUMENT; - if (ctx->set_param == NULL) - return YACA_ERROR_NOT_SUPPORTED; - return ctx->set_param(ctx, param, value, value_len); } API int yaca_ctx_get_param(const yaca_ctx_h ctx, yaca_ex_param_e param, void **value, size_t *value_len) { - if (ctx == YACA_CTX_NULL) + if (ctx == YACA_CTX_NULL || ctx->get_param == NULL) return YACA_ERROR_INVALID_ARGUMENT; - if (ctx->get_param == NULL) - return YACA_ERROR_NOT_SUPPORTED; - return ctx->get_param(ctx, param, value, value_len); } diff --git a/src/sign.c b/src/sign.c index 0c789bc..24fe7ac 100644 --- a/src/sign.c +++ b/src/sign.c @@ -180,11 +180,6 @@ API int yaca_sign_init(yaca_ctx_h *ctx, } ret = EVP_DigestSignInit(nc->mdctx, NULL, md, NULL, pkey); - if (ret == -2) { - ret = YACA_ERROR_NOT_SUPPORTED; - ERROR_DUMP(ret); - goto ctx; - } if (ret != 1) { ret = YACA_ERROR_INTERNAL; ERROR_DUMP(ret); @@ -219,16 +214,13 @@ API int yaca_sign_update(yaca_ctx_h ctx, return YACA_ERROR_INVALID_ARGUMENT; ret = EVP_DigestSignUpdate(c->mdctx, data, data_len); - if (ret == 1) - return 0; - - if (ret == -2) - ret = YACA_ERROR_NOT_SUPPORTED; - else + if (ret != 1) { ret = YACA_ERROR_INTERNAL; + ERROR_DUMP(ret); + return ret; + } - ERROR_DUMP(ret); - return ret; + return 0; } API int yaca_sign_final(yaca_ctx_h ctx, @@ -243,16 +235,13 @@ API int yaca_sign_final(yaca_ctx_h ctx, return YACA_ERROR_INVALID_ARGUMENT; ret = EVP_DigestSignFinal(c->mdctx, (unsigned char *)mac, mac_len); - if(ret == 1) - return 0; - - if (ret == -2) - ret = YACA_ERROR_NOT_SUPPORTED; - else + if(ret != 1) { ret = YACA_ERROR_INTERNAL; + ERROR_DUMP(ret); + return ret; + } - ERROR_DUMP(ret); - return ret; + return 0; } API int yaca_verify_init(yaca_ctx_h *ctx, @@ -323,11 +312,6 @@ API int yaca_verify_init(yaca_ctx_h *ctx, goto ctx; } - if (ret == -2) { - ret = YACA_ERROR_NOT_SUPPORTED; - ERROR_DUMP(ret); - goto ctx; - } if (ret != 1) { ret = YACA_ERROR_INTERNAL; ERROR_DUMP(ret); @@ -372,16 +356,13 @@ API int yaca_verify_update(yaca_ctx_h ctx, return YACA_ERROR_INVALID_ARGUMENT; } - if (ret == 1) - return 0; - - if (ret == -2) - ret = YACA_ERROR_NOT_SUPPORTED; - else + if (ret != 1) { ret = YACA_ERROR_INTERNAL; + ERROR_DUMP(ret); + return ret; + } - ERROR_DUMP(ret); - return ret; + return 0; } API int yaca_verify_final(yaca_ctx_h ctx, @@ -402,19 +383,16 @@ API int yaca_verify_final(yaca_ctx_h ctx, ret = EVP_DigestSignFinal(c->mdctx, (unsigned char *)mac_cmp, &mac_cmp_len); - if (ret == 1) { - if (mac_len != mac_cmp_len || CRYPTO_memcmp(mac, mac_cmp, mac_len) != 0) - return YACA_ERROR_SIGNATURE_INVALID; - return 0; + if (ret != 1) { + ret = YACA_ERROR_INTERNAL; + ERROR_DUMP(ret); + return ret; } - if (ret == -2) - ret = YACA_ERROR_NOT_SUPPORTED; - else - ret = YACA_ERROR_INTERNAL; + if (mac_len != mac_cmp_len || CRYPTO_memcmp(mac, mac_cmp, mac_len) != 0) + return YACA_ERROR_SIGNATURE_INVALID; - ERROR_DUMP(ret); - return ret; + return 0; case OP_VERIFY_ASYMMETRIC: ret = EVP_DigestVerifyFinal(c->mdctx, (unsigned char *)mac, @@ -424,8 +402,6 @@ API int yaca_verify_final(yaca_ctx_h ctx, if (ret == 0) ret = YACA_ERROR_SIGNATURE_INVALID; - else if (ret == -2) - ret = YACA_ERROR_NOT_SUPPORTED; else ret = YACA_ERROR_INTERNAL; -- 2.7.4