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