block_size = EVP_CIPHER_CTX_block_size(c->cipher_ctx);
if (block_size <= 0) {
- ERROR_DUMP(YACA_ERROR_INTERNAL);
- return YACA_ERROR_INTERNAL;
+ const int ret = YACA_ERROR_INTERNAL;
+ ERROR_DUMP(ret);
+ return ret;
}
if (input_len > 0) {
assert(key != YACA_KEY_NULL);
const EVP_CIPHER *cipher = EVP_CIPHER_CTX_cipher(c->cipher_ctx);
- if (cipher == NULL)
- return YACA_ERROR_INTERNAL;
+ if (cipher == NULL) {
+ ret = YACA_ERROR_INTERNAL;
+ ERROR_DUMP(ret);
+ return ret;
+ }
lkey = key_get_simple(key);
assert(lkey != NULL);
return YACA_ERROR_INVALID_PARAMETER;
if (EVP_CipherUpdate(c->cipher_ctx, NULL, &len, value, value_len) != 1) {
- ERROR_DUMP(YACA_ERROR_INTERNAL);
- return YACA_ERROR_INTERNAL;
+ ret = YACA_ERROR_INTERNAL;
+ ERROR_DUMP(ret);
+ return ret;
}
c->state = ENC_CTX_AAD_UPDATED;
break;
return YACA_ERROR_INVALID_PARAMETER;
if (EVP_CipherUpdate(c->cipher_ctx, NULL, &len, value, value_len) != 1) {
- ERROR_DUMP(YACA_ERROR_INTERNAL);
- return YACA_ERROR_INTERNAL;
+ ret = YACA_ERROR_INTERNAL;
+ ERROR_DUMP(ret);
+ return ret;
}
c->state = ENC_CTX_AAD_UPDATED;
break;
return YACA_ERROR_INVALID_PARAMETER;
if (EVP_CIPHER_CTX_ctrl(c->cipher_ctx, EVP_CTRL_GCM_SET_TAG, value_len, (void*)value) != 1) {
- ERROR_DUMP(YACA_ERROR_INTERNAL);
- return YACA_ERROR_INTERNAL;
+ ret = YACA_ERROR_INTERNAL;
+ ERROR_DUMP(ret);
+ return ret;
}
c->state = ENC_CTX_TAG_SET;
break;
int padding = *(yaca_padding_e*)value == YACA_PADDING_NONE ? 0 : 1;
if (EVP_CIPHER_CTX_set_padding(c->cipher_ctx, padding) != 1) {
- ERROR_DUMP(YACA_ERROR_INTERNAL);
- return YACA_ERROR_INTERNAL;
+ ret = YACA_ERROR_INTERNAL;
+ ERROR_DUMP(ret);
+ return ret;
}
if (c->backup_ctx != NULL)
c->backup_ctx->padding = padding;
EVP_CTRL_GCM_GET_TAG,
c->tag_len,
tag) != 1) {
- yaca_free(tag);
- ERROR_DUMP(YACA_ERROR_INTERNAL);
- return YACA_ERROR_INTERNAL;
+ ret = YACA_ERROR_INTERNAL;
+ ERROR_DUMP(ret);
+ goto err;
}
*value = tag;
*value_len = c->tag_len;
EVP_CTRL_CCM_GET_TAG,
c->tag_len,
tag) != 1) {
- yaca_free(tag);
- ERROR_DUMP(YACA_ERROR_INTERNAL);
- return YACA_ERROR_INTERNAL;
+ ret = YACA_ERROR_INTERNAL;
+ ERROR_DUMP(ret);
+ goto err;
}
*value = tag;
*value_len = c->tag_len;
}
return YACA_ERROR_NONE;
+
+err:
+ yaca_free(tag);
+ return ret;
}
static int check_key_bit_length_for_algo(yaca_encrypt_algorithm_e algo, size_t key_bit_len)
if (ret == YACA_ERROR_NONE && *cipher == NULL) {
ret = YACA_ERROR_INTERNAL;
ERROR_DUMP(ret);
+ return ret;
}
return ret;
* It does not necessarily indicate a more serious error.
* There is no call to EVP_CipherFinal.
*/
- ret = YACA_ERROR_INVALID_PARAMETER;
+ return YACA_ERROR_INVALID_PARAMETER;
} else {
ret = YACA_ERROR_INTERNAL;
ERROR_DUMP(ret);
+ return ret;
}
- return ret;
}
*output_len = loutput_len;
size_t key_bit_len,
size_t *iv_bit_len)
{
- const EVP_CIPHER *cipher;
int ret;
+ const EVP_CIPHER *cipher;
if (iv_bit_len == NULL || key_bit_len % 8 != 0)
return YACA_ERROR_INVALID_PARAMETER;
ret = EVP_CIPHER_iv_length(cipher);
if (ret < 0) {
- ERROR_DUMP(YACA_ERROR_INTERNAL);
- return YACA_ERROR_INTERNAL;
+ ret = YACA_ERROR_INTERNAL;
+ ERROR_DUMP(ret);
+ return ret;
}
*iv_bit_len = ret * 8;
dsa = d2i_DSAparams_bio(src, NULL);
if (dsa == NULL)
- return NULL;
+ goto err;
pkey = EVP_PKEY_new();
if (pkey == NULL)
- goto exit;
+ goto err;
if (EVP_PKEY_assign_DSA(pkey, dsa) != 1)
- goto exit;
+ goto err;
return pkey;
-exit:
+err:
EVP_PKEY_free(pkey);
DSA_free(dsa);
return NULL;
dh = d2i_DHparams_bio(src, NULL);
if (dh == NULL)
- return NULL;
+ goto err;
pkey = EVP_PKEY_new();
if (pkey == NULL)
- goto exit;
+ goto err;
if (EVP_PKEY_assign_DH(pkey, dh) != 1)
- goto exit;
+ goto err;
return pkey;
-exit:
+err:
EVP_PKEY_free(pkey);
DH_free(dh);
return NULL;
ecg = d2i_ECPKParameters_bio(src, NULL);
if (ecg == NULL)
- return NULL;
+ goto err;
eck = EC_KEY_new();
if (eck == NULL)
- goto exit;
+ goto err;
if (EC_KEY_set_group(eck, ecg) != 1)
- goto exit;
+ goto err;
EC_GROUP_free(ecg);
ecg = NULL;
pkey = EVP_PKEY_new();
if (pkey == NULL)
- goto exit;
+ goto err;
if (EVP_PKEY_assign_EC_KEY(pkey, eck) != 1)
- goto exit;
+ goto err;
return pkey;
-exit:
+err:
EVP_PKEY_free(pkey);
EC_KEY_free(eck);
EC_GROUP_free(ecg);
src = BIO_new_mem_buf(data, data_len);
if (src == NULL) {
- ERROR_DUMP(YACA_ERROR_INTERNAL);
- return YACA_ERROR_INTERNAL;
+ ret = YACA_ERROR_INTERNAL;
+ ERROR_DUMP(ret);
+ return ret;
}
/* Possible PEM */
{
assert(output_len != NULL);
+ int ret;
EVP_PKEY_CTX *pctx;
struct yaca_sign_context_s *c = get_sign_context(ctx);
assert(c != NULL);
return YACA_ERROR_INVALID_PARAMETER;
pctx = EVP_MD_CTX_pkey_ctx(c->md_ctx);
- if (pctx == NULL)
- return YACA_ERROR_INTERNAL;
+ if (pctx == NULL) {
+ ret = YACA_ERROR_INTERNAL;
+ ERROR_DUMP(ret);
+ return ret;
+ }
EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(pctx);
if (pkey == NULL) {
- ERROR_DUMP(YACA_ERROR_INTERNAL);
- return YACA_ERROR_INTERNAL;
+ ret = YACA_ERROR_INTERNAL;
+ ERROR_DUMP(ret);
+ return ret;
}
int len = EVP_PKEY_size(pkey);
if (len <= 0) {
- ERROR_DUMP(YACA_ERROR_INTERNAL);
- return YACA_ERROR_INTERNAL;
+ ret = YACA_ERROR_INTERNAL;
+ ERROR_DUMP(ret);
+ return ret;
}
*output_len = len;
return YACA_ERROR_INVALID_PARAMETER;
pctx = EVP_MD_CTX_pkey_ctx(c->md_ctx);
- if (pctx == NULL)
- return YACA_ERROR_INTERNAL;
+ if (pctx == NULL) {
+ ret = YACA_ERROR_INTERNAL;
+ ERROR_DUMP(ret);
+ return ret;
+ }
/* this function only supports padding */
if (property != YACA_PROPERTY_PADDING || value_len != sizeof(yaca_padding_e))