summaryrefslogtreecommitdiffstats
path: root/crypto/kdf
diff options
context:
space:
mode:
authorRich Salz <rsalz@openssl.org>2018-04-03 11:31:16 -0400
committerRich Salz <rsalz@openssl.org>2018-04-03 11:31:16 -0400
commitcdb10bae3f773401e039c55965eb177a6f3fc160 (patch)
treec69b1b2bc385d3f600684cf8285b9ff80322c48f /crypto/kdf
parent29f484d00d732ea4c19a7fd3dc0440045653e79e (diff)
Set error code on alloc failures
Almost all *alloc failures now set an error code. Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com> (Merged from https://github.com/openssl/openssl/pull/5842)
Diffstat (limited to 'crypto/kdf')
-rw-r--r--crypto/kdf/hkdf.c5
-rw-r--r--crypto/kdf/kdf_err.c3
-rw-r--r--crypto/kdf/tls1_prf.c10
3 files changed, 12 insertions, 6 deletions
diff --git a/crypto/kdf/hkdf.c b/crypto/kdf/hkdf.c
index 63c3523c27..16514a8430 100644
--- a/crypto/kdf/hkdf.c
+++ b/crypto/kdf/hkdf.c
@@ -48,9 +48,10 @@ static int pkey_hkdf_init(EVP_PKEY_CTX *ctx)
{
HKDF_PKEY_CTX *kctx;
- kctx = OPENSSL_zalloc(sizeof(*kctx));
- if (kctx == NULL)
+ if ((kctx = OPENSSL_zalloc(sizeof(*kctx))) == NULL) {
+ KDFerr(KDF_F_PKEY_HKDF_INIT, ERR_R_MALLOC_FAILURE);
return 0;
+ }
ctx->data = kctx;
diff --git a/crypto/kdf/kdf_err.c b/crypto/kdf/kdf_err.c
index 52ebd036e0..1627c0a394 100644
--- a/crypto/kdf/kdf_err.c
+++ b/crypto/kdf/kdf_err.c
@@ -16,6 +16,7 @@
static const ERR_STRING_DATA KDF_str_functs[] = {
{ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_HKDF_CTRL_STR, 0), "pkey_hkdf_ctrl_str"},
{ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_HKDF_DERIVE, 0), "pkey_hkdf_derive"},
+ {ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_HKDF_INIT, 0), "pkey_hkdf_init"},
{ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_SCRYPT_CTRL_STR, 0),
"pkey_scrypt_ctrl_str"},
{ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_SCRYPT_CTRL_UINT64, 0),
@@ -28,6 +29,8 @@ static const ERR_STRING_DATA KDF_str_functs[] = {
"pkey_tls1_prf_ctrl_str"},
{ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_TLS1_PRF_DERIVE, 0),
"pkey_tls1_prf_derive"},
+ {ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_TLS1_PRF_INIT, 0), "pkey_tls1_prf_init"},
+ {ERR_PACK(ERR_LIB_KDF, KDF_F_TLS1_PRF_ALG, 0), "tls1_prf_alg"},
{0, NULL}
};
diff --git a/crypto/kdf/tls1_prf.c b/crypto/kdf/tls1_prf.c
index f5b2334a58..49f7ecced9 100644
--- a/crypto/kdf/tls1_prf.c
+++ b/crypto/kdf/tls1_prf.c
@@ -37,9 +37,10 @@ static int pkey_tls1_prf_init(EVP_PKEY_CTX *ctx)
{
TLS1_PRF_PKEY_CTX *kctx;
- kctx = OPENSSL_zalloc(sizeof(*kctx));
- if (kctx == NULL)
+ if ((kctx = OPENSSL_zalloc(sizeof(*kctx))) == NULL) {
+ KDFerr(KDF_F_PKEY_TLS1_PRF_INIT, ERR_R_MALLOC_FAILURE);
return 0;
+ }
ctx->data = kctx;
return 1;
@@ -256,9 +257,10 @@ static int tls1_prf_alg(const EVP_MD *md,
seed, seed_len, out, olen))
return 0;
- tmp = OPENSSL_malloc(olen);
- if (tmp == NULL)
+ if ((tmp = OPENSSL_malloc(olen)) == NULL) {
+ KDFerr(KDF_F_TLS1_PRF_ALG, ERR_R_MALLOC_FAILURE);
return 0;
+ }
if (!tls1_prf_P_hash(EVP_sha1(), sec + slen/2, slen/2 + (slen & 1),
seed, seed_len, tmp, olen)) {
OPENSSL_clear_free(tmp, olen);