diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/p5_pbe.c')
-rw-r--r-- | src/lib/libcrypto/asn1/p5_pbe.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c index 891150638e..ec788267e0 100644 --- a/src/lib/libcrypto/asn1/p5_pbe.c +++ b/src/lib/libcrypto/asn1/p5_pbe.c | |||
@@ -76,47 +76,55 @@ IMPLEMENT_ASN1_FUNCTIONS(PBEPARAM) | |||
76 | X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, | 76 | X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, |
77 | int saltlen) | 77 | int saltlen) |
78 | { | 78 | { |
79 | PBEPARAM *pbe; | 79 | PBEPARAM *pbe=NULL; |
80 | ASN1_OBJECT *al; | 80 | ASN1_OBJECT *al; |
81 | X509_ALGOR *algor; | 81 | X509_ALGOR *algor; |
82 | ASN1_TYPE *astype; | 82 | ASN1_TYPE *astype=NULL; |
83 | 83 | ||
84 | if (!(pbe = PBEPARAM_new ())) { | 84 | if (!(pbe = PBEPARAM_new ())) { |
85 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); | 85 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); |
86 | return NULL; | 86 | goto err; |
87 | } | 87 | } |
88 | if(iter <= 0) iter = PKCS5_DEFAULT_ITER; | 88 | if(iter <= 0) iter = PKCS5_DEFAULT_ITER; |
89 | ASN1_INTEGER_set (pbe->iter, iter); | 89 | if (!ASN1_INTEGER_set(pbe->iter, iter)) { |
90 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); | ||
91 | goto err; | ||
92 | } | ||
90 | if (!saltlen) saltlen = PKCS5_SALT_LEN; | 93 | if (!saltlen) saltlen = PKCS5_SALT_LEN; |
91 | if (!(pbe->salt->data = OPENSSL_malloc (saltlen))) { | 94 | if (!(pbe->salt->data = OPENSSL_malloc (saltlen))) { |
92 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); | 95 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); |
93 | return NULL; | 96 | goto err; |
94 | } | 97 | } |
95 | pbe->salt->length = saltlen; | 98 | pbe->salt->length = saltlen; |
96 | if (salt) memcpy (pbe->salt->data, salt, saltlen); | 99 | if (salt) memcpy (pbe->salt->data, salt, saltlen); |
97 | else if (RAND_pseudo_bytes (pbe->salt->data, saltlen) < 0) | 100 | else if (RAND_pseudo_bytes (pbe->salt->data, saltlen) < 0) |
98 | return NULL; | 101 | goto err; |
99 | 102 | ||
100 | if (!(astype = ASN1_TYPE_new())) { | 103 | if (!(astype = ASN1_TYPE_new())) { |
101 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); | 104 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); |
102 | return NULL; | 105 | goto err; |
103 | } | 106 | } |
104 | 107 | ||
105 | astype->type = V_ASN1_SEQUENCE; | 108 | astype->type = V_ASN1_SEQUENCE; |
106 | if(!ASN1_pack_string(pbe, i2d_PBEPARAM, &astype->value.sequence)) { | 109 | if(!ASN1_pack_string(pbe, i2d_PBEPARAM, &astype->value.sequence)) { |
107 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); | 110 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); |
108 | return NULL; | 111 | goto err; |
109 | } | 112 | } |
110 | PBEPARAM_free (pbe); | 113 | PBEPARAM_free (pbe); |
114 | pbe = NULL; | ||
111 | 115 | ||
112 | al = OBJ_nid2obj(alg); /* never need to free al */ | 116 | al = OBJ_nid2obj(alg); /* never need to free al */ |
113 | if (!(algor = X509_ALGOR_new())) { | 117 | if (!(algor = X509_ALGOR_new())) { |
114 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); | 118 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); |
115 | return NULL; | 119 | goto err; |
116 | } | 120 | } |
117 | ASN1_OBJECT_free(algor->algorithm); | 121 | ASN1_OBJECT_free(algor->algorithm); |
118 | algor->algorithm = al; | 122 | algor->algorithm = al; |
119 | algor->parameter = astype; | 123 | algor->parameter = astype; |
120 | 124 | ||
121 | return (algor); | 125 | return (algor); |
126 | err: | ||
127 | if (pbe != NULL) PBEPARAM_free(pbe); | ||
128 | if (astype != NULL) ASN1_TYPE_free(astype); | ||
129 | return NULL; | ||
122 | } | 130 | } |