if (ret != YACA_ERROR_NONE)
goto exit;
- /* Allocate memory for tag */
- ret = yaca_zalloc(tag_len, (void**)&tag);
- if (ret != YACA_ERROR_NONE)
- goto exit;
-
/* Encryption */
{
/* Initialize encryption context */
goto exit;
/* Get the tag after final encryption */
- ret = yaca_context_get_property(ctx, YACA_PROPERTY_CCM_TAG, (void**)tag, &tag_len);
+ ret = yaca_context_get_property(ctx, YACA_PROPERTY_CCM_TAG, (void**)&tag, &tag_len);
if (ret != YACA_ERROR_NONE)
goto exit;
if (ret != YACA_ERROR_NONE)
goto exit;
- /* Allocate memory for tag */
- ret = yaca_zalloc(tag_len, (void**)&tag);
- if (ret != YACA_ERROR_NONE)
- goto exit;
-
/* Encryption */
{
/* Initialize encryption context */
if (ret != YACA_ERROR_NONE)
goto exit;
- ret = yaca_context_get_property(ctx, YACA_PROPERTY_GCM_TAG, (void**)tag, &tag_len);
+ ret = yaca_context_get_property(ctx, YACA_PROPERTY_GCM_TAG, (void**)&tag, &tag_len);
if (ret != YACA_ERROR_NONE)
goto exit;
int get_encrypt_property(const yaca_context_h ctx, yaca_property_e property,
void **value, size_t *value_len)
{
+ int ret;
+ void *tag = NULL;
struct yaca_encrypt_context_s *c = get_encrypt_context(ctx);
int mode;
assert(c->tag_len <= INT_MAX);
+ ret = yaca_malloc(c->tag_len, &tag);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
+
if (EVP_CIPHER_CTX_ctrl(c->cipher_ctx,
EVP_CTRL_GCM_GET_TAG,
c->tag_len,
- value) != 1) {
+ tag) != 1) {
+ yaca_free(tag);
ERROR_DUMP(YACA_ERROR_INTERNAL);
return YACA_ERROR_INTERNAL;
}
+ *value = tag;
*value_len = c->tag_len;
break;
case YACA_PROPERTY_CCM_TAG:
assert(c->tag_len <= INT_MAX);
+ ret = yaca_malloc(c->tag_len, &tag);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
+
if (EVP_CIPHER_CTX_ctrl(c->cipher_ctx,
EVP_CTRL_CCM_GET_TAG,
c->tag_len,
- value) != 1) {
+ tag) != 1) {
+ yaca_free(tag);
ERROR_DUMP(YACA_ERROR_INTERNAL);
return YACA_ERROR_INTERNAL;
}
+ *value = tag;
*value_len = c->tag_len;
break;
default: