* @since_tizen 3.0
*
* @see yaca_init()
+ *
+ * @return #YACA_ERROR_NONE on success
+ * @retval #YACA_ERROR_NONE Successful
*/
-void yaca_exit(void);
+int yaca_exit(void);
/**
* @brief Allocates the memory.
*
* @since_tizen 3.0
*
- * @param[in] size Size of the allocation (bytes)
+ * @param[in] size Size of the allocation (bytes)
+ * @param[out] memory Allocated memory
*
- * @return NULL on failure, pointer to allocated memory otherwise
+ * @return #YACA_ERROR_NONE on success, negative on error
+ * @retval #YACA_ERROR_NONE Successful
+ * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0)
+ * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
*
* @see yaca_zalloc()
* @see yaca_realloc()
* @see yaca_free()
*/
-void *yaca_malloc(size_t size);
+int yaca_malloc(size_t size, void **memory);
/**
* @brief Allocates the zeroed memory.
*
* @since_tizen 3.0
*
- * @param[in] size Size of the allocation (bytes)
+ * @param[in] size Size of the allocation (bytes)
+ * @param[out] memory Allocated memory
*
- * @return NULL on failure, pointer to allocated and zeroed memory otherwise
+ * @return #YACA_ERROR_NONE on success, negative on error
+ * @retval #YACA_ERROR_NONE Successful
+ * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0)
+ * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
*
* @see yaca_malloc()
* @see yaca_realloc()
* @see yaca_free()
*/
-void *yaca_zalloc(size_t size);
+int yaca_zalloc(size_t size, void **memory);
/**
* @brief Re-allocates the memory.
*
* @since_tizen 3.0
*
- * @param[in] addr Address of the memory to be reallocated
- * @param[in] size Size of the new allocation (bytes)
+ * @remarks In case of failure the function doesn't free the memory pointed by @b memory.
+ *
+ * @remarks If @b *memory is NULL then the call is equivalent to yaca_malloc().
*
- * @return NULL on failure, pointer to allocated memory otherwise
+ * @remarks If the function fails the contents of @b memory will be left unchanged.
+ *
+ * @param[in] size Size of the new allocation (bytes)
+ * @param[in,out] memory Memory to be reallocated
+ *
+ * @return #YACA_ERROR_NONE on success, negative on error
+ * @retval #YACA_ERROR_NONE Successful
+ * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0)
+ * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
*
* @see yaca_malloc()
* @see yaca_zalloc()
* @see yaca_free()
*/
-void *yaca_realloc(void *addr, size_t size);
+int yaca_realloc(size_t size, void **memory);
/**
* @brief Frees the memory allocated by yaca_malloc(), yaca_zalloc(),
*
* @param[in] ptr Pointer to the memory to be freed
*
+ * @return #YACA_ERROR_NONE on success
+ * @retval #YACA_ERROR_NONE Successful
+ *
* @see yaca_malloc()
* @see yaca_zalloc()
* @see yaca_realloc()
*/
-void yaca_free(void *ptr);
+int yaca_free(void *ptr);
/**
* @brief Generates random data.
*
* @param[in,out] ctx Crypto context
*
+ * @return #YACA_ERROR_NONE on success
+ * @retval #YACA_ERROR_NONE Successful
+ *
* @see #yaca_ctx_h
*
*/
-void yaca_ctx_free(yaca_ctx_h ctx);
+int yaca_ctx_free(yaca_ctx_h ctx);
/**
* @brief Returns the output length for a given algorithm. Can only be called
*
* @param[in,out] key Key to be freed
*
+ * @return #YACA_ERROR_NONE on success
+ * @retval #YACA_ERROR_NONE Successful
+ *
* @see yaca_key_import()
* @see yaca_key_export()
* @see yaca_key_gen()
*/
-void yaca_key_free(yaca_key_h key);
+int yaca_key_free(yaca_key_h key);
/**@}*/
/* Calculate max output: size of update + final chunks */
enc_size = output_len + block_len;
- if ((enc = yaca_malloc(enc_size)) == NULL)
+ if (yaca_malloc(enc_size, (void**)&enc) != YACA_ERROR_NONE)
goto exit;
out_size = enc_size;
/* Calculate max output: size of update + final chunks */
dec_size = output_len + block_len;
- if ((dec = yaca_malloc(dec_size)) == NULL)
+ if (yaca_malloc(dec_size, (void**)&dec) != YACA_ERROR_NONE)
goto exit;
out_size = dec_size;
if (yaca_key_gen(YACA_KEY_TYPE_IV, iv_bits, &iv) != YACA_ERROR_NONE)
goto exit;
- if ((aad = yaca_zalloc(aad_size)) == NULL)
+ if (yaca_zalloc(aad_size, (void**)&aad) != YACA_ERROR_NONE)
goto exit;
if (yaca_rand_bytes(aad, aad_size) != YACA_ERROR_NONE)
goto exit;
- if ((tag = yaca_zalloc(tag_size)) == NULL)
+ if (yaca_zalloc(tag_size, (void**)&tag) != YACA_ERROR_NONE)
goto exit;
/* Encryption */
/* Calculate max output: size of update + final chunks */
enc_size = output_len + block_len;
- if ((enc = yaca_malloc(enc_size)) == NULL)
+ if (yaca_malloc(enc_size, (void**)&enc) != YACA_ERROR_NONE)
goto exit;
out_size = enc_size;
/* Calculate max output: size of update + final chunks */
dec_size = output_len + block_len;
- if ((dec = yaca_malloc(dec_size)) == NULL)
+ if (yaca_malloc(dec_size, (void**)&dec) != YACA_ERROR_NONE)
goto exit;
out_size = dec_size;
if (yaca_key_gen(YACA_KEY_TYPE_IV, iv_bits, &iv) != YACA_ERROR_NONE)
goto exit;
- if ((aad = yaca_zalloc(aad_size)) == NULL)
+ if (yaca_zalloc(aad_size, (void**)&aad) != YACA_ERROR_NONE)
goto exit;
if (yaca_rand_bytes(aad, aad_size) != YACA_ERROR_NONE)
goto exit;
- if ((tag = yaca_zalloc(tag_size)) == NULL)
+ if (yaca_zalloc(tag_size, (void**)&tag) != YACA_ERROR_NONE)
goto exit;
/* Encryption */
/* Calculate max output: size of update + final chunks */
enc_size = output_len + block_len;
- if ((enc = yaca_malloc(enc_size)) == NULL)
+ if (yaca_malloc(enc_size, (void**)&enc) != YACA_ERROR_NONE)
goto exit;
out_size = enc_size;
/* Calculate max output: size of update + final chunks */
dec_size = output_len + block_len;
- if ((dec = yaca_malloc(dec_size)) == NULL)
+ if (yaca_malloc(dec_size, (void**)&dec) != YACA_ERROR_NONE)
goto exit;
out_size = dec_size;
rewind(fp);
/* allocate memory for entire content */
- buffer = yaca_malloc(size+1);
- if (buffer == NULL)
+ if (yaca_malloc(size + 1, (void**)&buffer) != YACA_ERROR_NONE)
goto exit;
/* copy the file into the buffer */
rewind(fp);
/* allocate memory for entire content */
- buffer = yaca_malloc(size+1);
- if (buffer == NULL)
+ if (yaca_malloc(size + 1, (void**)&buffer) != YACA_ERROR_NONE)
goto exit;
/* copy the file into the buffer */
#include <openssl/bio.h>
#include <yaca_crypto.h>
+#include <yaca_error.h>
#include "misc.h"
if (read > 0) {
if (buf == NULL) {
- buf = yaca_malloc(read);
- if (buf == NULL) {
+ if (yaca_malloc(read, (void**)&buf) != YACA_ERROR_NONE) {
ret = -1;
break;
}
} else {
- char *new_buf = yaca_realloc(buf, buf_len + read);
- if (new_buf == NULL) {
+ if (yaca_realloc(buf_len + read, (void**)&buf) != YACA_ERROR_NONE) {
ret = -1;
break;
}
- buf = new_buf;
}
memcpy(buf + buf_len, tmp, read);
int read_stdin_line(const char *prompt, char **string)
{
char *buf = NULL;
- char *ret;
size_t size;
ssize_t read;
return -1;
}
- ret = yaca_realloc(buf, read);
- if (ret == NULL) {
+ if (yaca_realloc(read, (void**)&buf) != YACA_ERROR_NONE) {
free(buf);
return -1;
}
/* Calculate max output: size of update + final chunks */
enc_size = output_len + block_len;
- if ((enc = yaca_malloc(enc_size)) == NULL)
+ if (yaca_malloc(enc_size, (void**)&enc) != YACA_ERROR_NONE)
goto exit;
/* Seal and finalize */
/* Calculate max output: size of update + final chunks */
dec_size = output_len + block_len;
- if ((dec = yaca_malloc(dec_size)) == NULL)
+ if (yaca_malloc(dec_size, (void**)&dec) != YACA_ERROR_NONE)
goto exit;
/* Open and finalize */
if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE)
goto exit;
- if ((signature = yaca_malloc(signature_len)) == NULL)
+ if (yaca_malloc(signature_len, (void**)&signature) != YACA_ERROR_NONE)
goto exit;
if (yaca_sign_final(ctx, signature, &signature_len) != YACA_ERROR_NONE)
if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE)
goto exit;
- if ((signature1 = yaca_malloc(signature_len)) == NULL)
+ if (yaca_malloc(signature_len, (void**)&signature1) != YACA_ERROR_NONE)
goto exit;
if (yaca_sign_final(ctx, signature1, &signature_len) != YACA_ERROR_NONE)
if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE)
goto exit;
- if ((signature2 = yaca_malloc(signature_len)) == NULL)
+ if (yaca_malloc(signature_len, (void**)&signature2) != YACA_ERROR_NONE)
goto exit;
if (yaca_sign_final(ctx, signature2, &signature_len) != YACA_ERROR_NONE)
if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE)
goto exit;
- if ((signature1 = yaca_malloc(signature_len)) == NULL)
+ if (yaca_malloc(signature_len, (void**)&signature1) != YACA_ERROR_NONE)
goto exit;
if (yaca_sign_final(ctx, signature1, &signature_len))
if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE)
goto exit;
- if ((signature2 = yaca_malloc(signature_len)) == NULL)
+ if (yaca_malloc(signature_len, (void**)&signature2) != YACA_ERROR_NONE)
goto exit;
if (yaca_sign_final(ctx, signature2, &signature_len))
API int yaca_init(void)
{
+ int ret;
if (mutexes != NULL)
return YACA_ERROR_INTERNAL; // TODO introduce new one?
OpenSSL_add_all_ciphers();
/* enable threads support */
- mutexes = yaca_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
- if (mutexes == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t), (void**)&mutexes);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
for (int i = 0; i < CRYPTO_num_locks(); i++) {
if (pthread_mutex_init(&mutexes[i], NULL) != 0) {
return YACA_ERROR_NONE;
}
-API void yaca_exit(void)
+API int yaca_exit(void)
{
ERR_free_strings();
ERR_remove_thread_state(NULL);
CRYPTO_set_locking_callback(NULL);
destroy_mutexes(CRYPTO_num_locks());
+
+ return YACA_ERROR_NONE;
}
-API void *yaca_malloc(size_t size)
+API int yaca_malloc(size_t size, void **memory)
{
- return OPENSSL_malloc(size);
+ if (size == 0 || memory == NULL)
+ return YACA_ERROR_INVALID_ARGUMENT;
+
+ *memory = OPENSSL_malloc(size);
+ if (*memory == NULL) {
+ ERROR_DUMP(YACA_ERROR_OUT_OF_MEMORY);
+ return YACA_ERROR_OUT_OF_MEMORY;
+ }
+
+ return YACA_ERROR_NONE;
}
-API void *yaca_zalloc(size_t size)
+API int yaca_zalloc(size_t size, void **memory)
{
- void *blob = OPENSSL_malloc(size);
- if (blob != NULL)
- memset(blob, 0, size);
- return blob;
+ int ret = yaca_malloc(size, memory);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
+
+ memset(*memory, 0, size);
+
+ return YACA_ERROR_NONE;
}
-API void *yaca_realloc(void *addr, size_t size)
+API int yaca_realloc(size_t size, void **memory)
{
- return OPENSSL_realloc(addr, size);
+ if (size == 0 || memory == NULL)
+ return YACA_ERROR_INVALID_ARGUMENT;
+
+ void *tmp = OPENSSL_realloc(*memory, size);
+ if (tmp == NULL) {
+ ERROR_DUMP(YACA_ERROR_OUT_OF_MEMORY);
+ return YACA_ERROR_OUT_OF_MEMORY;
+ }
+
+ *memory = tmp;
+
+ return YACA_ERROR_NONE;
}
-API void yaca_free(void *ptr)
+API int yaca_free(void *ptr)
{
OPENSSL_free(ptr);
+
+ return YACA_ERROR_NONE;
}
API int yaca_rand_bytes(char *data, size_t data_len)
return ctx->get_param(ctx, param, value, value_len);
}
-API void yaca_ctx_free(yaca_ctx_h ctx)
+API int yaca_ctx_free(yaca_ctx_h ctx)
{
if (ctx != YACA_CTX_NULL) {
assert(ctx->ctx_destroy != NULL);
ctx->ctx_destroy(ctx);
yaca_free(ctx);
}
+
+ return YACA_ERROR_NONE;
}
API int yaca_get_output_length(const yaca_ctx_h ctx, size_t input_len, size_t *output_len)
if (ctx == NULL)
return YACA_ERROR_INVALID_ARGUMENT;
- nc = yaca_zalloc(sizeof(struct yaca_digest_ctx_s));
- if (nc == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_digest_ctx_s), (void**)&nc);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
nc->ctx.type = YACA_CTX_DIGEST;
nc->ctx.ctx_destroy = destroy_digest_context;
if (lkey == NULL)
return YACA_ERROR_INVALID_ARGUMENT;
- nc = yaca_zalloc(sizeof(struct yaca_encrypt_ctx_s));
- if (nc == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_encrypt_ctx_s), (void**)&nc);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
nc->ctx.type = YACA_CTX_ENCRYPT;
nc->ctx.ctx_destroy = destroy_encrypt_ctx;
}
}
- nk = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_data_len);
- if (nk == NULL) {
- ret = YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_data_len, (void**)&nk);
+ if (ret != YACA_ERROR_NONE)
goto exit;
- }
memcpy(nk->d, key_data, key_data_len);
nk->bits = key_data_len * 8;
goto exit;
}
- nk = yaca_zalloc(sizeof(struct yaca_key_evp_s));
- if (nk == NULL) {
- ret = YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_key_evp_s), (void**)&nk);
+ if (ret != YACA_ERROR_NONE)
goto exit;
- }
nk->evp = pkey;
*key = (yaca_key_h)nk;
char **data,
size_t *data_len)
{
+ int ret;
assert(simple_key != NULL);
assert(data != NULL);
assert(data_len != NULL);
size_t key_len = simple_key->bits / 8;
- *data = yaca_malloc(key_len);
- if (*data == NULL) {
- ERROR_DUMP(YACA_ERROR_OUT_OF_MEMORY);
- return YACA_ERROR_OUT_OF_MEMORY;
- }
+ ret = yaca_malloc(key_len, (void**)data);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
memcpy(*data, simple_key->d, key_len);
*data_len = key_len;
goto exit;
}
- *data = yaca_malloc(bio_data_len);
- if (*data == NULL) {
- ret = YACA_ERROR_OUT_OF_MEMORY;
- ERROR_DUMP(ret);
+ ret = yaca_malloc(bio_data_len, (void**)data);
+ if (ret != YACA_ERROR_NONE)
goto exit;
- }
memcpy(*data, bio_data, bio_data_len);
*data_len = bio_data_len;
goto exit;
}
- *data = yaca_malloc(bio_data_len);
- if (*data == NULL) {
- ret = YACA_ERROR_OUT_OF_MEMORY;
- ERROR_DUMP(ret);
+ ret = yaca_malloc(bio_data_len, (void**)data);
+ if (ret != YACA_ERROR_NONE)
goto exit;
- }
memcpy(*data, bio_data, bio_data_len);
*data_len = bio_data_len;
struct yaca_key_simple_s *nk;
size_t key_byte_len = key_bits / 8;
- nk = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_byte_len);
- if (nk == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_byte_len, (void**)&nk);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
nk->bits = key_bits;
struct yaca_key_simple_s *nk;
size_t key_byte_len = key_bits / 8;
- nk = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_byte_len);
- if (nk == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_byte_len, (void**)&nk);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
DES_cblock *des_key = (DES_cblock*)nk->d;
if (key_byte_len >= 8) {
EVP_PKEY_CTX *ctx;
EVP_PKEY *pkey = NULL;
- nk = yaca_zalloc(sizeof(struct yaca_key_evp_s));
- if (nk == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_key_evp_s), (void**)&nk);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL);
if (ctx == NULL) {
EVP_PKEY *pkey = NULL;
EVP_PKEY *params = NULL;
- nk = yaca_zalloc(sizeof(struct yaca_key_evp_s));
- if (nk == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_key_evp_s), (void**)&nk);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_DSA, NULL);
if (pctx == NULL) {
if (prv_key == YACA_KEY_NULL || evp_key == NULL || pub_key == NULL)
return YACA_ERROR_INVALID_ARGUMENT;
- nk = yaca_zalloc(sizeof(struct yaca_key_evp_s));
- if (nk == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_key_evp_s), (void**)&nk);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
mem = BIO_new(BIO_s_mem());
if (mem == NULL) {
return ret;
}
-API void yaca_key_free(yaca_key_h key)
+API int yaca_key_free(yaca_key_h key)
{
struct yaca_key_simple_s *simple_key = key_get_simple(key);
struct yaca_key_evp_s *evp_key = key_get_evp(key);
EVP_PKEY_free(evp_key->evp);
yaca_free(evp_key);
}
+
+ return YACA_ERROR_NONE;
}
API int yaca_key_derive_pbkdf2(const char *password,
if (ret != YACA_ERROR_NONE)
return ret;
- nk = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_byte_len);
- if (nk == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_byte_len, (void**)&nk);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
nk->bits = key_bits;
nk->key.type = YACA_KEY_TYPE_SYMMETRIC; // TODO: how to handle other keys?
lpub = key_get_evp(pub_key);
assert(lpub);
- nc = yaca_zalloc(sizeof(struct yaca_seal_ctx_s));
- if (nc == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_seal_ctx_s), (void**)&nc);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
nc->ctx.type = YACA_CTX_SEAL;
nc->ctx.ctx_destroy = destroy_seal_ctx;
}
pub_key_length = ret;
- lkey = yaca_zalloc(sizeof(struct yaca_key_simple_s) + pub_key_length);
- if (lkey == NULL) {
- ret = YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_key_simple_s) + pub_key_length, (void**)&lkey);
+ if (ret != YACA_ERROR_NONE)
goto exit;
- }
key_data = (unsigned char*)lkey->d;
ret = encrypt_get_algorithm(algo, bcm, sym_key_bits, &cipher);
iv_length = ret;
if (iv_length > 0) {
- liv = yaca_zalloc(sizeof(struct yaca_key_simple_s) + iv_length);
- if (liv == NULL) {
- ret = YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_key_simple_s) + iv_length, (void**)&liv);
+ if (ret != YACA_ERROR_NONE)
goto exit;
- }
iv_data = (unsigned char*)liv->d;
}
if (lkey == NULL || lkey->key.type != YACA_KEY_TYPE_SYMMETRIC)
return YACA_ERROR_INVALID_ARGUMENT;
- nc = yaca_zalloc(sizeof(struct yaca_seal_ctx_s));
- if (nc == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_seal_ctx_s), (void**)&nc);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
nc->ctx.type = YACA_CTX_SEAL;
nc->ctx.ctx_destroy = destroy_seal_ctx;
return ret;
}
- *value = yaca_malloc(sizeof(yaca_padding_e));
- if (*value == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_malloc(sizeof(yaca_padding_e), value);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
memcpy(*value, &padding, sizeof(yaca_padding_e));
*value_len = sizeof(yaca_padding_e);
return YACA_ERROR_INVALID_ARGUMENT;
}
- nc = yaca_zalloc(sizeof(struct yaca_sign_ctx_s));
- if (nc == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_sign_ctx_s), (void**)&nc);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
nc->op_type = OP_SIGN;
nc->ctx.type = YACA_CTX_SIGN;
(key->type != YACA_KEY_TYPE_SYMMETRIC && key->type != YACA_KEY_TYPE_DES))
return YACA_ERROR_INVALID_ARGUMENT;
- nc = yaca_zalloc(sizeof(struct yaca_sign_ctx_s));
- if (nc == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_sign_ctx_s), (void**)&nc);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
nc->op_type = OP_SIGN;
nc->ctx.type = YACA_CTX_SIGN;
(key->type != YACA_KEY_TYPE_SYMMETRIC && key->type != YACA_KEY_TYPE_DES))
return YACA_ERROR_INVALID_ARGUMENT;
- nc = yaca_zalloc(sizeof(struct yaca_sign_ctx_s));
- if (nc == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_sign_ctx_s), (void**)&nc);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
nc->op_type = OP_SIGN;
nc->ctx.type = YACA_CTX_SIGN;
return YACA_ERROR_INVALID_ARGUMENT;
}
- nc = yaca_zalloc(sizeof(struct yaca_sign_ctx_s));
- if (nc == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_zalloc(sizeof(struct yaca_sign_ctx_s), (void**)&nc);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
nc->op_type = OP_VERIFY;
nc->ctx.type = YACA_CTX_SIGN;
if (ret != YACA_ERROR_NONE)
goto exit;
- ldigest = yaca_malloc(ldigest_len);
- if (ldigest == NULL)
+ ret = yaca_malloc(ldigest_len, (void**)&ldigest);
+ if (ret != YACA_ERROR_NONE)
goto exit;
ret = yaca_digest_final(ctx, ldigest, &ldigest_len);
yaca_ctx_h ctx;
int ret;
char *lcipher = NULL;
- char *rcipher = NULL;
size_t out_len, lcipher_len, written;
if (plain == NULL || plain_len == 0 || cipher == NULL || cipher_len == NULL ||
lcipher_len += out_len;
- lcipher = yaca_malloc(lcipher_len);
- if (lcipher == NULL)
+ ret = yaca_malloc(lcipher_len, (void**)&lcipher);
+ if (ret != YACA_ERROR_NONE)
goto exit;
out_len = lcipher_len;
written += out_len;
assert(written <= lcipher_len);
- rcipher = yaca_realloc(lcipher, written);
- if (rcipher == NULL) {
- ret = YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_realloc(written, (void**)&lcipher);
+ if (ret != YACA_ERROR_NONE)
goto exit;
- }
- *cipher = rcipher;
+ *cipher = lcipher;
*cipher_len = written;
lcipher = NULL;
ret = YACA_ERROR_NONE;
yaca_ctx_h ctx;
int ret;
char *lplain = NULL;
- char *rplain = NULL;
size_t out_len, lplain_len, written;
if (cipher == NULL || cipher_len == 0 || plain == NULL || plain_len == NULL ||
lplain_len += out_len;
- lplain = yaca_malloc(lplain_len);
- if (lplain == NULL)
+ ret = yaca_malloc(lplain_len, (void**)&lplain);
+ if (ret != YACA_ERROR_NONE)
goto exit;
out_len = lplain_len;
written += out_len;
assert(written <= lplain_len);
- rplain = yaca_realloc(lplain, written);
- if (rplain == NULL) {
- ret = YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_realloc(written, (void**)&lplain);
+ if (ret != YACA_ERROR_NONE)
goto exit;
- }
- *plain = rplain;
+ *plain = lplain;
*plain_len = written;
lplain = NULL;
ret = YACA_ERROR_NONE;
if (ret != YACA_ERROR_NONE)
return ret;
- *signature = yaca_malloc(*signature_len);
- if (signature == NULL)
- return YACA_ERROR_OUT_OF_MEMORY;
+ ret = yaca_malloc(*signature_len, (void**)signature);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
ret = yaca_sign_final(ctx, *signature, signature_len);
if (ret != YACA_ERROR_NONE) {