OpenSSL_add_all_ciphers();
/* enable threads support */
- ret = yaca_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t), (void**)&mutexes);
- if (ret != YACA_ERROR_NONE)
- return ret;
+ if (CRYPTO_num_locks() > 0) {
+ 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) {
- int ret = YACA_ERROR_NONE;
- switch (errno) {
- case ENOMEM:
- ret = YACA_ERROR_OUT_OF_MEMORY;
- break;
- case EAGAIN:
- case EPERM:
- case EBUSY:
- case EINVAL:
- default:
- ret = YACA_ERROR_INTERNAL;
+ for (int i = 0; i < CRYPTO_num_locks(); i++) {
+ if (pthread_mutex_init(&mutexes[i], NULL) != 0) {
+ int ret = YACA_ERROR_NONE;
+ switch (errno) {
+ case ENOMEM:
+ ret = YACA_ERROR_OUT_OF_MEMORY;
+ break;
+ case EAGAIN:
+ case EPERM:
+ case EBUSY:
+ case EINVAL:
+ default:
+ ret = YACA_ERROR_INTERNAL;
+ }
+ destroy_mutexes(i);
+
+ return ret;
}
- destroy_mutexes(i);
-
- return ret;
}
- }
- CRYPTO_set_id_callback(thread_id_callback);
- CRYPTO_set_locking_callback(locking_callback);
+ CRYPTO_set_id_callback(thread_id_callback);
+ CRYPTO_set_locking_callback(locking_callback);
+ }
/*
TODO:
if (c == NULL)
return YACA_ERROR_INVALID_ARGUMENT;
- *output_len = EVP_MD_CTX_size(c->mdctx);
+ int md_size = EVP_MD_CTX_size(c->mdctx);
+ if (md_size <= 0)
+ return YACA_ERROR_INTERNAL;
+
+ *output_len = md_size;
+
return YACA_ERROR_NONE;
}
} else {
*output_len = block_size;
}
+ if (*output_len == 0)
+ return YACA_ERROR_INTERNAL;
return YACA_ERROR_NONE;
}
size_t key_len = simple_key->bits / 8;
+ assert(key_len > 0);
+
ret = yaca_malloc(key_len, (void**)data);
if (ret != YACA_ERROR_NONE)
return ret;
EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(c->mdctx->pctx);
if (pkey == NULL) {
- ERROR_DUMP(YACA_ERROR_INVALID_ARGUMENT);
- return YACA_ERROR_INVALID_ARGUMENT;
+ ERROR_DUMP(YACA_ERROR_INTERNAL);
+ return YACA_ERROR_INTERNAL;
}
- size_t len = EVP_PKEY_size(pkey);
+ int len = EVP_PKEY_size(pkey);
if (len <= 0) {
- ERROR_DUMP(YACA_ERROR_INVALID_ARGUMENT);
- return YACA_ERROR_INVALID_ARGUMENT;
+ ERROR_DUMP(YACA_ERROR_INTERNAL);
+ return YACA_ERROR_INTERNAL;
}
*output_len = len;
if (ret != YACA_ERROR_NONE)
goto exit;
+ assert(ldigest_len > 0);
+
ret = yaca_malloc(ldigest_len, (void**)&ldigest);
if (ret != YACA_ERROR_NONE)
goto exit;
lcipher_len += out_len;
+ assert(lcipher_len > 0);
+
ret = yaca_malloc(lcipher_len, (void**)&lcipher);
if (ret != YACA_ERROR_NONE)
goto exit;
goto exit;
written += out_len;
- assert(written <= lcipher_len);
+ assert(written <= lcipher_len && written > 0);
ret = yaca_realloc(written, (void**)&lcipher);
if (ret != YACA_ERROR_NONE)
}
lplain_len += out_len;
+ assert(lplain_len > 0);
ret = yaca_malloc(lplain_len, (void**)&lplain);
if (ret != YACA_ERROR_NONE)
goto exit;
written += out_len;
- assert(written <= lplain_len);
+ assert(written <= lplain_len && written > 0);
ret = yaca_realloc(written, (void**)&lplain);
if (ret != YACA_ERROR_NONE)
if (ret != YACA_ERROR_NONE)
return ret;
+ assert(*signature_len > 0);
+
ret = yaca_malloc(*signature_len, (void**)signature);
if (ret != YACA_ERROR_NONE)
return ret;