yaca: add yaca_zalloc 02/65602/8
authorMateusz Kulikowski <m.kulikowski@samsung.com>
Mon, 11 Apr 2016 13:46:33 +0000 (15:46 +0200)
committerLukasz Pawelczyk <l.pawelczyk@samsung.com>
Fri, 15 Apr 2016 12:10:12 +0000 (14:10 +0200)
This allocator will be mostly used to allocate contexts/keys.

Change-Id: I5c3a5efcda5a243503ac80502c221157e18eaa2a
Signed-off-by: Mateusz Kulikowski <m.kulikowski@samsung.com>
api/yaca/crypto.h
src/crypto.c

index cd30ff2..309d2f9 100644 (file)
@@ -68,6 +68,16 @@ void yaca_exit(void);
 void *yaca_malloc(size_t size);
 
 /**
+ * @brief yaca_zalloc  Allocates the zeroed memory.
+ *
+ * @param[in] size  Size of the allocation (bytes).
+ *
+ * @return NULL on failure, pointer to allocated and zeroed memory otherwise.
+ */
+// TODO: this should be a macro to CRYPTO_*
+void *yaca_zalloc(size_t size);
+
+/**
  * @brief yaca_realloc  Re-allocates the memory.
  *
  * @param[in] addr  Address of the memory to be reallocated.
index 4a49071..550abf0 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include <assert.h>
+#include <string.h>
 
 #include <openssl/crypto.h>
 #include <openssl/evp.h>
@@ -54,6 +55,14 @@ API void *yaca_malloc(size_t size)
        return OPENSSL_malloc(size);
 }
 
+API void *yaca_zalloc(size_t size)
+{
+       void *blob = OPENSSL_malloc(size);
+       if (blob != NULL)
+               memset(blob, 0, size);
+       return blob;
+}
+
 API void *yaca_realloc(void *addr, size_t size)
 {
        return OPENSSL_realloc(addr, size);