Deleted Added
full compact
p5_pbev2.c (1.1.1.6) p5_pbev2.c (1.1.1.7)
1/* p5_pbev2.c */
2/*
3 * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
4 * 1999-2004.
5 */
6/* ====================================================================
7 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
8 *

--- 77 unchanged lines hidden (view full) ---

86 * this is horrible! Extended version to allow application supplied PRF NID
87 * and IV.
88 */
89
90X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter,
91 unsigned char *salt, int saltlen,
92 unsigned char *aiv, int prf_nid)
93{
1/* p5_pbev2.c */
2/*
3 * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
4 * 1999-2004.
5 */
6/* ====================================================================
7 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
8 *

--- 77 unchanged lines hidden (view full) ---

86 * this is horrible! Extended version to allow application supplied PRF NID
87 * and IV.
88 */
89
90X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter,
91 unsigned char *salt, int saltlen,
92 unsigned char *aiv, int prf_nid)
93{
94 X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL;
94 X509_ALGOR *scheme = NULL, *ret = NULL;
95 int alg_nid, keylen;
96 EVP_CIPHER_CTX ctx;
97 unsigned char iv[EVP_MAX_IV_LENGTH];
98 PBE2PARAM *pbe2 = NULL;
95 int alg_nid, keylen;
96 EVP_CIPHER_CTX ctx;
97 unsigned char iv[EVP_MAX_IV_LENGTH];
98 PBE2PARAM *pbe2 = NULL;
99 ASN1_OBJECT *obj;
100
101 alg_nid = EVP_CIPHER_type(cipher);
102 if (alg_nid == NID_undef) {
103 ASN1err(ASN1_F_PKCS5_PBE2_SET_IV,
104 ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
105 goto err;
106 }
99
100 alg_nid = EVP_CIPHER_type(cipher);
101 if (alg_nid == NID_undef) {
102 ASN1err(ASN1_F_PKCS5_PBE2_SET_IV,
103 ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
104 goto err;
105 }
107 obj = OBJ_nid2obj(alg_nid);
108
109 if (!(pbe2 = PBE2PARAM_new()))
110 goto merr;
111
112 /* Setup the AlgorithmIdentifier for the encryption scheme */
113 scheme = pbe2->encryption;
114
106
107 if (!(pbe2 = PBE2PARAM_new()))
108 goto merr;
109
110 /* Setup the AlgorithmIdentifier for the encryption scheme */
111 scheme = pbe2->encryption;
112
115 scheme->algorithm = obj;
113 scheme->algorithm = OBJ_nid2obj(alg_nid);
116 if (!(scheme->parameter = ASN1_TYPE_new()))
117 goto merr;
118
119 /* Create random IV */
120 if (EVP_CIPHER_iv_length(cipher)) {
121 if (aiv)
122 memcpy(iv, aiv, EVP_CIPHER_iv_length(cipher));
123 else if (RAND_bytes(iv, EVP_CIPHER_iv_length(cipher)) <= 0)

--- 59 unchanged lines hidden (view full) ---

183 return ret;
184
185 merr:
186 ASN1err(ASN1_F_PKCS5_PBE2_SET_IV, ERR_R_MALLOC_FAILURE);
187
188 err:
189 PBE2PARAM_free(pbe2);
190 /* Note 'scheme' is freed as part of pbe2 */
114 if (!(scheme->parameter = ASN1_TYPE_new()))
115 goto merr;
116
117 /* Create random IV */
118 if (EVP_CIPHER_iv_length(cipher)) {
119 if (aiv)
120 memcpy(iv, aiv, EVP_CIPHER_iv_length(cipher));
121 else if (RAND_bytes(iv, EVP_CIPHER_iv_length(cipher)) <= 0)

--- 59 unchanged lines hidden (view full) ---

181 return ret;
182
183 merr:
184 ASN1err(ASN1_F_PKCS5_PBE2_SET_IV, ERR_R_MALLOC_FAILURE);
185
186 err:
187 PBE2PARAM_free(pbe2);
188 /* Note 'scheme' is freed as part of pbe2 */
191 X509_ALGOR_free(kalg);
192 X509_ALGOR_free(ret);
193
194 return NULL;
189 X509_ALGOR_free(ret);
190
191 return NULL;
195
196}
197
198X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
199 unsigned char *salt, int saltlen)
200{
201 return PKCS5_pbe2_set_iv(cipher, iter, salt, saltlen, NULL, -1);
202}
203

--- 77 unchanged lines hidden ---
192}
193
194X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
195 unsigned char *salt, int saltlen)
196{
197 return PKCS5_pbe2_set_iv(cipher, iter, salt, saltlen, NULL, -1);
198}
199

--- 77 unchanged lines hidden ---