Fix: yaca_context_get_property() implementation unconsistent with documentation 64/160164/1
authorDariusz Michaluk <d.michaluk@samsung.com>
Tue, 14 Nov 2017 15:27:57 +0000 (16:27 +0100)
committerDariusz Michaluk <d.michaluk@samsung.com>
Tue, 14 Nov 2017 17:11:13 +0000 (18:11 +0100)
Change-Id: I5ffd12d68b2bc2764da50d7e7bc5dd1b92eb5ebb

examples/encrypt_ccm.c
examples/encrypt_gcm.c
src/encrypt.c

index 3bc11f8..572882c 100644 (file)
@@ -78,11 +78,6 @@ int main()
        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 */
@@ -140,7 +135,7 @@ int main()
                        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;
 
index 9778acb..7e1125b 100644 (file)
@@ -78,11 +78,6 @@ int main()
        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 */
@@ -134,7 +129,7 @@ int main()
                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;
 
index f4a21f3..1fd935c 100644 (file)
@@ -767,6 +767,8 @@ int set_encrypt_property(yaca_context_h ctx,
 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;
 
@@ -786,13 +788,19 @@ int get_encrypt_property(const yaca_context_h ctx, yaca_property_e property,
 
                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:
@@ -804,13 +812,19 @@ int get_encrypt_property(const yaca_context_h ctx, yaca_property_e property,
 
                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: