summaryrefslogtreecommitdiffstats
path: root/crypto/x509/x_pubkey.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/x509/x_pubkey.c')
-rw-r--r--crypto/x509/x_pubkey.c61
1 files changed, 32 insertions, 29 deletions
diff --git a/crypto/x509/x_pubkey.c b/crypto/x509/x_pubkey.c
index c8d76f882e..89184fc910 100644
--- a/crypto/x509/x_pubkey.c
+++ b/crypto/x509/x_pubkey.c
@@ -112,12 +112,13 @@ static int x509_pubkey_ex_new_ex(ASN1_VALUE **pval, const ASN1_ITEM *it,
{
X509_PUBKEY *ret;
- if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL
- || !x509_pubkey_ex_populate((ASN1_VALUE **)&ret, NULL)
+ if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
+ return 0;
+ if (!x509_pubkey_ex_populate((ASN1_VALUE **)&ret, NULL)
|| !x509_pubkey_set0_libctx(ret, libctx, propq)) {
x509_pubkey_ex_free((ASN1_VALUE **)&ret, NULL);
ret = NULL;
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_X509_LIB);
} else {
*pval = (ASN1_VALUE *)ret;
}
@@ -141,7 +142,7 @@ static int x509_pubkey_ex_d2i_ex(ASN1_VALUE **pval,
if (*pval == NULL && !x509_pubkey_ex_new_ex(pval, it, libctx, propq))
return 0;
if (!x509_pubkey_ex_populate(pval, NULL)) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_X509_LIB);
return 0;
}
@@ -190,10 +191,8 @@ static int x509_pubkey_ex_d2i_ex(ASN1_VALUE **pval,
*/
if (aclass != V_ASN1_UNIVERSAL) {
tmpbuf = OPENSSL_memdup(in_saved, publen);
- if (tmpbuf == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (tmpbuf == NULL)
return 0;
- }
in_saved = tmpbuf;
*tmpbuf = V_ASN1_CONSTRUCTED | V_ASN1_SEQUENCE;
}
@@ -284,16 +283,22 @@ X509_PUBKEY *X509_PUBKEY_dup(const X509_PUBKEY *a)
{
X509_PUBKEY *pubkey = OPENSSL_zalloc(sizeof(*pubkey));
- if (pubkey == NULL
- || !x509_pubkey_set0_libctx(pubkey, a->libctx, a->propq)
- || (pubkey->algor = X509_ALGOR_dup(a->algor)) == NULL
- || (pubkey->public_key = ASN1_BIT_STRING_new()) == NULL
- || !ASN1_BIT_STRING_set(pubkey->public_key,
- a->public_key->data,
- a->public_key->length)) {
+ if (pubkey == NULL)
+ return NULL;
+ if (!x509_pubkey_set0_libctx(pubkey, a->libctx, a->propq)) {
+ ERR_raise(ERR_LIB_X509, ERR_R_X509_LIB);
+ x509_pubkey_ex_free((ASN1_VALUE **)&pubkey,
+ ASN1_ITEM_rptr(X509_PUBKEY_INTERNAL));
+ return NULL;
+ }
+ if ((pubkey->algor = X509_ALGOR_dup(a->algor)) == NULL
+ || (pubkey->public_key = ASN1_BIT_STRING_new()) == NULL
+ || !ASN1_BIT_STRING_set(pubkey->public_key,
+ a->public_key->data,
+ a->public_key->length)) {
x509_pubkey_ex_free((ASN1_VALUE **)&pubkey,
ASN1_ITEM_rptr(X509_PUBKEY_INTERNAL));
- ERR_raise(ERR_LIB_X509, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_X509, ERR_R_ASN1_LIB);
return NULL;
}
@@ -325,7 +330,7 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
if (pkey->ameth != NULL) {
if ((pk = X509_PUBKEY_new()) == NULL) {
- ERR_raise(ERR_LIB_X509, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_X509, ERR_R_ASN1_LIB);
goto error;
}
if (pkey->ameth->pub_encode != NULL) {
@@ -416,7 +421,7 @@ static int x509_pubkey_decode(EVP_PKEY **ppkey, const X509_PUBKEY *key)
pkey = EVP_PKEY_new();
if (pkey == NULL) {
- ERR_raise(ERR_LIB_X509, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_X509, ERR_R_EVP_LIB);
return -1;
}
@@ -499,10 +504,8 @@ static EVP_PKEY *d2i_PUBKEY_int(EVP_PKEY **a,
*/
if (libctx != NULL || propq != NULL || force_legacy) {
xpk2 = OPENSSL_zalloc(sizeof(*xpk2));
- if (xpk2 == NULL) {
- ERR_raise(ERR_LIB_X509, ERR_R_MALLOC_FAILURE);
+ if (xpk2 == NULL)
return NULL;
- }
if (!x509_pubkey_set0_libctx(xpk2, libctx, propq))
goto end;
xpk2->flag_force_legacy = !!force_legacy;
@@ -628,7 +631,7 @@ int i2d_RSA_PUBKEY(const RSA *a, unsigned char **pp)
return 0;
pktmp = EVP_PKEY_new();
if (pktmp == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
return -1;
}
(void)EVP_PKEY_assign_RSA(pktmp, (RSA *)a);
@@ -670,7 +673,7 @@ int ossl_i2d_DH_PUBKEY(const DH *a, unsigned char **pp)
return 0;
pktmp = EVP_PKEY_new();
if (pktmp == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
return -1;
}
(void)EVP_PKEY_assign_DH(pktmp, (DH *)a);
@@ -711,7 +714,7 @@ int ossl_i2d_DHx_PUBKEY(const DH *a, unsigned char **pp)
return 0;
pktmp = EVP_PKEY_new();
if (pktmp == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
return -1;
}
(void)EVP_PKEY_assign(pktmp, EVP_PKEY_DHX, (DH *)a);
@@ -753,7 +756,7 @@ int i2d_DSA_PUBKEY(const DSA *a, unsigned char **pp)
return 0;
pktmp = EVP_PKEY_new();
if (pktmp == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
return -1;
}
(void)EVP_PKEY_assign_DSA(pktmp, (DSA *)a);
@@ -798,7 +801,7 @@ int i2d_EC_PUBKEY(const EC_KEY *a, unsigned char **pp)
if (a == NULL)
return 0;
if ((pktmp = EVP_PKEY_new()) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
return -1;
}
(void)EVP_PKEY_assign_EC_KEY(pktmp, (EC_KEY *)a);
@@ -839,7 +842,7 @@ int ossl_i2d_ED25519_PUBKEY(const ECX_KEY *a, unsigned char **pp)
if (a == NULL)
return 0;
if ((pktmp = EVP_PKEY_new()) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
return -1;
}
(void)EVP_PKEY_assign(pktmp, EVP_PKEY_ED25519, (ECX_KEY *)a);
@@ -881,7 +884,7 @@ int ossl_i2d_ED448_PUBKEY(const ECX_KEY *a, unsigned char **pp)
if (a == NULL)
return 0;
if ((pktmp = EVP_PKEY_new()) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
return -1;
}
(void)EVP_PKEY_assign(pktmp, EVP_PKEY_ED448, (ECX_KEY *)a);
@@ -923,7 +926,7 @@ int ossl_i2d_X25519_PUBKEY(const ECX_KEY *a, unsigned char **pp)
if (a == NULL)
return 0;
if ((pktmp = EVP_PKEY_new()) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
return -1;
}
(void)EVP_PKEY_assign(pktmp, EVP_PKEY_X25519, (ECX_KEY *)a);
@@ -965,7 +968,7 @@ int ossl_i2d_X448_PUBKEY(const ECX_KEY *a, unsigned char **pp)
if (a == NULL)
return 0;
if ((pktmp = EVP_PKEY_new()) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
return -1;
}
(void)EVP_PKEY_assign(pktmp, EVP_PKEY_X448, (ECX_KEY *)a);