size_t remaining = num;
#ifndef SYS_getrandom
- if (urandom_fd == -2)
- return 0;
+ assert(urandom_fd != -2);
#endif /* SYS_getrandom */
while (remaining > 0) {
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
*
assert(output_len != NULL);
struct yaca_digest_context_s *c = get_digest_context(ctx);
+ assert(c != NULL);
+ assert(c->md_ctx != NULL);
- if (c == NULL || input_len != 0)
+ if (input_len != 0)
return YACA_ERROR_INVALID_PARAMETER;
int md_size = EVP_MD_CTX_size(c->md_ctx);
static void destroy_digest_context(yaca_context_h ctx)
{
struct yaca_digest_context_s *c = get_digest_context(ctx);
-
- if (c == NULL)
- return;
+ assert(c != NULL);
EVP_MD_CTX_destroy(c->md_ctx);
c->md_ctx = NULL;
}
return false;
default:
+ assert(false);
return false;
}
}
static void destroy_encrypt_context(const yaca_context_h ctx)
{
struct yaca_encrypt_context_s *c = get_encrypt_context(ctx);
-
- if (c == NULL)
- return;
+ assert(c != NULL);
if (c->backup_ctx != NULL) {
yaca_key_destroy(c->backup_ctx->iv);
{
assert(output_len != NULL);
- struct yaca_encrypt_context_s *c = get_encrypt_context(ctx);
int block_size;
-
- if (c == NULL)
- return YACA_ERROR_INVALID_PARAMETER;
+ struct yaca_encrypt_context_s *c = get_encrypt_context(ctx);
+ assert(c != NULL);
assert(c->cipher_ctx != NULL);
block_size = EVP_CIPHER_CTX_block_size(c->cipher_ctx);
} else {
*output_len = block_size;
}
- if (*output_len == 0)
- return YACA_ERROR_INTERNAL;
+ assert(*output_len != 0);
return YACA_ERROR_NONE;
}
assert(output_len != NULL);
struct yaca_encrypt_context_s *c = get_encrypt_context(ctx);
- if (c == NULL)
- return YACA_ERROR_INVALID_PARAMETER;
+ assert(c != NULL);
assert(c->cipher_ctx != NULL);
bool encryption = is_encryption_op(c->op_type);
assert(key != YACA_KEY_NULL);
const EVP_CIPHER *cipher = EVP_CIPHER_CTX_cipher(c->cipher_ctx);
-
if (cipher == NULL)
return YACA_ERROR_INTERNAL;
lkey = key_get_simple(key);
- if (lkey == NULL)
- return YACA_ERROR_INVALID_PARAMETER;
+ assert(lkey != NULL);
liv = key_get_simple(iv);
const void *value,
size_t value_len)
{
- struct yaca_encrypt_context_s *c = get_encrypt_context(ctx);
int len;
int ret = YACA_ERROR_NONE;
+ struct yaca_encrypt_context_s *c = get_encrypt_context(ctx);
+ assert(c != NULL);
+ assert(c->cipher_ctx != NULL);
- if (c == NULL || value == NULL || value_len == 0)
+ if (value == NULL || value_len == 0)
return YACA_ERROR_INVALID_PARAMETER;
- assert(c->cipher_ctx != NULL);
int mode = EVP_CIPHER_CTX_mode(c->cipher_ctx);
int nid = EVP_CIPHER_CTX_nid(c->cipher_ctx);
return YACA_ERROR_INVALID_PARAMETER;
lsym_key = key_get_simple(sym_key);
- if (lsym_key == NULL)
- return YACA_ERROR_INVALID_PARAMETER;
+ assert(lsym_key != NULL);
if (lsym_key->key.type != YACA_KEY_TYPE_DES &&
lsym_key->key.type != YACA_KEY_TYPE_SYMMETRIC)
/* Neither PEM nor DER will ever be shorter then 4 bytes (12 seems
* to be minimum for DER, much more for PEM). This is just to make
- * sure we have at least 4 bytes for strncmp() below.
- */
- if (data_len < 4)
- return YACA_ERROR_INVALID_PARAMETER;
-
- /* This is because of BIO_new_mem_buf() having its length param typed int */
- if (data_len > INT_MAX)
+ * sure we have at least 4 bytes for strncmp() below. INT_MAX is
+ * because of BIO_new_mem_buf() having its length param typed
+ * int */
+ if (data_len < 4 || data_len > INT_MAX)
return YACA_ERROR_INVALID_PARAMETER;
src = BIO_new_mem_buf(data, data_len);
break;
default:
- return YACA_ERROR_INVALID_PARAMETER;
+ assert(false);
+ return YACA_ERROR_INTERNAL;
}
break;
}
default:
- return YACA_ERROR_INVALID_PARAMETER;
+ assert(false);
+ return YACA_ERROR_INTERNAL;
}
break;
break;
default:
- /* We shouldn't be here */
assert(false);
return YACA_ERROR_INTERNAL;
}
assert(key_bit_len > 0 || params != NULL);
int ret;
- int evp_id;
+ int evp_id = -1;
EVP_PKEY *pkey_out = NULL;
EVP_PKEY *pkey_params = NULL;
yaca_key_type_e params_type = params->key.type;
ret = convert_params_to_priv(params_type, &key_type);
- if (ret != YACA_ERROR_NONE)
- return ret;
-
- if (out_type != key_type)
- return YACA_ERROR_INVALID_PARAMETER;
+ assert(ret == YACA_ERROR_NONE);
+ assert(out_type == key_type);
pkey_params = params->evp;
}
case YACA_KEY_TYPE_EC_PARAMS:
assert(params == NULL);
ret = convert_params_to_evp_id(out_type, &evp_id);
- if (ret != YACA_ERROR_NONE)
- return ret;
+ assert(ret == YACA_ERROR_NONE);
ret = generate_evp_pkey_params(evp_id, key_bit_len, &pkey_out);
break;
case YACA_KEY_TYPE_DH_PRIV:
case YACA_KEY_TYPE_EC_PRIV:
ret = convert_priv_to_evp_id(out_type, &evp_id);
- if (ret != YACA_ERROR_NONE)
- return ret;
+ assert(ret == YACA_ERROR_NONE);
ret = generate_evp_pkey_key(evp_id, key_bit_len, pkey_params, &pkey_out);
break;
default:
- return YACA_ERROR_INVALID_PARAMETER;
+ assert(false);
+ return YACA_ERROR_INTERNAL;
}
if (ret != YACA_ERROR_NONE)
return ret;
return convert_nid_to_ec(nid, key_bit_len);
}
default:
- /* We shouldn't be here */
assert(false);
return YACA_ERROR_INTERNAL;
}
*key = (yaca_key_h)nk_evp;
} else {
assert(false);
+ return YACA_ERROR_INTERNAL;
}
return YACA_ERROR_NONE;
if (evp_params == NULL || prv_key == NULL)
return YACA_ERROR_INVALID_PARAMETER;
- ret = yaca_key_get_type(params, ¶ms_type);
- if (ret != YACA_ERROR_NONE)
- return ret;
+ params_type = evp_params->key.type;
ret = convert_params_to_priv(params_type, &key_type);
if (ret != YACA_ERROR_NONE)
if (evp_key == NULL || pub_key == NULL)
return YACA_ERROR_INVALID_PARAMETER;
- ret = yaca_key_get_type(prv_key, &prv_type);
- if (ret != YACA_ERROR_NONE)
- return ret;
+ prv_type = evp_key->key.type;
ret = convert_priv_to_pub(prv_type, &pub_type);
if (ret != YACA_ERROR_NONE)
if (evp_key == NULL || params == NULL)
return YACA_ERROR_INVALID_PARAMETER;
- ret = yaca_key_get_type(key, &key_type);
- if (ret != YACA_ERROR_NONE)
- return ret;
+ key_type = evp_key->key.type;
ret = convert_priv_to_params(key_type, ¶ms_type);
if (ret != YACA_ERROR_NONE)
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
*
case YACA_PADDING_PKCS1_SSLV23:
return RSA_SSLV23_PADDING;
default:
+ assert(false);
return -1;
}
}
return YACA_ERROR_INVALID_PARAMETER;
lpadding = rsa_padding2openssl(padding);
- assert(lpadding != -1);
lasym_key = key_get_evp(key);
assert(lasym_key != NULL);
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
*
{
assert(output_len != NULL);
- struct yaca_sign_context_s *c = get_sign_context(ctx);
EVP_PKEY_CTX *pctx;
+ struct yaca_sign_context_s *c = get_sign_context(ctx);
+ assert(c != NULL);
+ assert(c->md_ctx != NULL);
- if (c == NULL || input_len != 0)
+ if (input_len != 0)
return YACA_ERROR_INVALID_PARAMETER;
- assert(c->md_ctx != NULL);
-
pctx = EVP_MD_CTX_pkey_ctx(c->md_ctx);
if (pctx == NULL)
return YACA_ERROR_INTERNAL;
static void destroy_sign_context(yaca_context_h ctx)
{
struct yaca_sign_context_s *c = get_sign_context(ctx);
-
- if (c == NULL)
- return;
+ assert(c != NULL);
EVP_MD_CTX_destroy(c->md_ctx);
c->md_ctx = NULL;
size_t value_len)
{
int ret;
- struct yaca_sign_context_s *c = get_sign_context(ctx);
yaca_padding_e padding;
int pad;
EVP_PKEY *pkey;
EVP_PKEY_CTX *pctx;
+ struct yaca_sign_context_s *c = get_sign_context(ctx);
+ assert(c != NULL);
+ assert(c->md_ctx != NULL);
- if (c == NULL || value == NULL || c->state == CTX_FINALIZED)
+ if (value == NULL || c->state == CTX_FINALIZED)
return YACA_ERROR_INVALID_PARAMETER;
- assert(c->md_ctx != NULL);
-
pctx = EVP_MD_CTX_pkey_ctx(c->md_ctx);
if (pctx == NULL)
return YACA_ERROR_INTERNAL;
}
pad = rsa_padding2openssl(padding);
- assert(pad != -1);
pkey = EVP_PKEY_CTX_get0_pkey(pctx);
if (pkey == NULL) {
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
*
written += out_len;
assert(written <= lciphertext_len);
- if (((bcm == YACA_BCM_CBC || bcm == YACA_BCM_ECB) && written == 0) ||
- (bcm != YACA_BCM_CBC && bcm != YACA_BCM_ECB && plaintext_len == 0 && written > 0)) {
- ret = YACA_ERROR_INTERNAL;
- goto exit;
- }
-
if (written > 0) {
ret = yaca_realloc(written, (void**)&lciphertext);
if (ret != YACA_ERROR_NONE)
written += out_len;
assert(written <= lplaintext_len);
- if (bcm != YACA_BCM_CBC && bcm != YACA_BCM_ECB && ciphertext_len == 0 && written > 0) {
- ret = YACA_ERROR_INTERNAL;
- goto exit;
- }
-
if (written > 0) {
ret = yaca_realloc(written, (void**)&lplaintext);
if (ret != YACA_ERROR_NONE)