Use crypto_zalloc for internal structure allocations. 03/65603/8
authorMateusz Kulikowski <m.kulikowski@samsung.com>
Mon, 11 Apr 2016 13:50:50 +0000 (15:50 +0200)
committerLukasz Pawelczyk <l.pawelczyk@samsung.com>
Fri, 15 Apr 2016 12:11:28 +0000 (14:11 +0200)
Change-Id: I3a3f738cf238c362ac33e3aa01c3a37d263140f9
Signed-off-by: Mateusz Kulikowski <m.kulikowski@samsung.com>
src/digest.c
src/encrypt.c
src/key.c

index 93a2535..9c50748 100644 (file)
@@ -121,7 +121,7 @@ API int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo)
        if (ctx == NULL)
                return YACA_ERROR_INVALID_ARGUMENT;
 
-       nc = yaca_malloc(sizeof(struct yaca_digest_ctx_s));
+       nc = yaca_zalloc(sizeof(struct yaca_digest_ctx_s));
        if (nc == NULL)
                return YACA_ERROR_OUT_OF_MEMORY;
 
index d195800..24e9117 100644 (file)
@@ -184,12 +184,10 @@ static int encrypt_init(yaca_ctx_h *ctx,
        if (lkey == NULL)
                return YACA_ERROR_INVALID_ARGUMENT;
 
-       nc = yaca_malloc(sizeof(struct yaca_encrypt_ctx_s));
+       nc = yaca_zalloc(sizeof(struct yaca_encrypt_ctx_s));
        if (nc == NULL)
                return YACA_ERROR_OUT_OF_MEMORY;
 
-       memset(nc, 0, sizeof(struct yaca_encrypt_ctx_s));
-
        nc->ctx.type = YACA_CTX_ENCRYPT;
        nc->ctx.ctx_destroy = destroy_encrypt_ctx;
        nc->ctx.get_output_length = get_encrypt_output_length;
index 6ba3c9e..f5aa42c 100644 (file)
--- a/src/key.c
+++ b/src/key.c
@@ -137,7 +137,7 @@ API int yaca_key_import(yaca_key_h *key,
                if (data_len > SIZE_MAX - sizeof(struct yaca_key_simple_s))
                        return YACA_ERROR_TOO_BIG_ARGUMENT;
 
-               nk = yaca_malloc(sizeof(struct yaca_key_simple_s) + data_len);
+               nk = yaca_zalloc(sizeof(struct yaca_key_simple_s) + data_len);
                if (nk == NULL)
                        return YACA_ERROR_OUT_OF_MEMORY;
 
@@ -232,7 +232,7 @@ API int yaca_key_gen(yaca_key_h *sym_key,
        if (key_byte_len > SIZE_MAX - sizeof(struct yaca_key_simple_s))
                return YACA_ERROR_TOO_BIG_ARGUMENT;
 
-       nk = yaca_malloc(sizeof(struct yaca_key_simple_s) + key_byte_len);
+       nk = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_byte_len);
        if (nk == NULL)
                return YACA_ERROR_OUT_OF_MEMORY;
 
@@ -269,11 +269,11 @@ API int yaca_key_gen_pair(yaca_key_h *prv_key,
        if (key_type != YACA_KEY_TYPE_PAIR_RSA)
                return YACA_ERROR_NOT_IMPLEMENTED;
 
-       nk_prv = yaca_malloc(sizeof(struct yaca_key_evp_s));
+       nk_prv = yaca_zalloc(sizeof(struct yaca_key_evp_s));
        if (nk_prv == NULL)
                return YACA_ERROR_OUT_OF_MEMORY;
 
-       nk_pub = yaca_malloc(sizeof(struct yaca_key_evp_s));
+       nk_pub = yaca_zalloc(sizeof(struct yaca_key_evp_s));
        if (nk_pub == NULL) {
                ret = YACA_ERROR_OUT_OF_MEMORY;
                goto free_prv;
@@ -414,7 +414,7 @@ API int yaca_key_derive_pbkdf2(const char *password,
        if (key_byte_len > SIZE_MAX - sizeof(struct yaca_key_simple_s))
                return YACA_ERROR_TOO_BIG_ARGUMENT;
 
-       nk = yaca_malloc(sizeof(struct yaca_key_simple_s) + key_byte_len);
+       nk = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_byte_len);
        if (nk == NULL)
                return YACA_ERROR_OUT_OF_MEMORY;