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?
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);
}
}
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);
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,
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,
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);
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,
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,
if (ret == 0)
ret = YACA_ERROR_SIGNATURE_INVALID;
- else if (ret == -2)
- ret = YACA_ERROR_NOT_SUPPORTED;
else
ret = YACA_ERROR_INTERNAL;