| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #include <openssl/pkcs8.h> |
| 16 |
| 17 | #include <assert.h> |
| 18 | #include <limits.h> |
| 19 | #include <string.h> |
| 20 |
| 21 | #include <openssl/bytestring.h> |
| 22 | #include <openssl/cipher.h> |
| 23 | #include <openssl/digest.h> |
| 24 | #include <openssl/err.h> |
| 25 | #include <openssl/mem.h> |
| 26 | #include <openssl/nid.h> |
| 27 | #include <openssl/rand.h> |
| 28 |
| 29 | #include "../bytestring/internal.h" |
| 30 | #include "../internal.h" |
| 31 | #include "internal.h" |
| 32 |
| 33 |
| 34 | static int pkcs12_encode_password(const char *in, size_t in_len, uint8_t **out, |
| 35 | size_t *out_len) { |
| 36 | CBB cbb; |
| 37 | if (!CBB_init(&cbb, in_len * 2)) { |
| 38 | return 0; |
| 39 | } |
| 40 |
| 41 | // Convert the password to BMPString, or UCS-2. See |
| 42 | // https://tools.ietf.org/html/rfc7292#appendix-B.1. |
| 43 | CBS cbs; |
| 44 | CBS_init(&cbs, (const uint8_t *)in, in_len); |
| 45 | while (CBS_len(&cbs) != 0) { |
| 46 | uint32_t c; |
| 47 | if (!CBS_get_utf8(&cbs, &c) || !CBB_add_ucs2_be(&cbb, c)) { |
| 48 | OPENSSL_PUT_ERROR(PKCS8, PKCS8_R_INVALID_CHARACTERS); |
| 49 | goto err; |
| 50 | } |
| 51 | } |
| 52 |
| 53 | // Terminate the result with a UCS-2 NUL. |
| 54 | if (!CBB_add_ucs2_be(&cbb, 0) || !CBB_finish(&cbb, out, out_len)) { |
| 55 | goto err; |
| 56 | } |
| 57 |
| 58 | return 1; |
| 59 |
| 60 | err: |
| 61 | CBB_cleanup(&cbb); |
| 62 | return 0; |
| 63 | } |
| 64 |
| 65 | int pkcs12_key_gen(const char *pass, size_t pass_len, const uint8_t *salt, |
| 66 | size_t salt_len, uint8_t id, uint32_t iterations, |
| 67 | size_t out_len, uint8_t *out, const EVP_MD *md) { |
| 68 | // See https://tools.ietf.org/html/rfc7292#appendix-B. Quoted parts of the |
| 69 | // specification have errata applied and other typos fixed. |
| 70 |
| 71 | if (iterations < 1) { |
| 72 | OPENSSL_PUT_ERROR(PKCS8, PKCS8_R_BAD_ITERATION_COUNT); |
| 73 | return 0; |
| 74 | } |
| 75 |
| 76 | int ret = 0; |
| 77 | EVP_MD_CTX ctx; |
| 78 | EVP_MD_CTX_init(&ctx); |
| 79 | uint8_t *pass_raw = NULL, *I = NULL; |
| 80 | size_t pass_raw_len = 0, I_len = 0; |
| 81 |
| 82 | { |
| 83 | // If |pass| is NULL, we use the empty string rather than {0, 0} as the raw |
| 84 | // password. |
| 85 | if (pass != NULL && |
| 86 | !pkcs12_encode_password(pass, pass_len, &pass_raw, &pass_raw_len)) { |
| 87 | goto err; |
| 88 | } |
| 89 |
| 90 | // In the spec, |block_size| is called "v", but measured in bits. |
| 91 | size_t block_size = EVP_MD_block_size(md); |
| 92 |
| 93 | // 1. Construct a string, D (the "diversifier"), by concatenating v/8 copies |
| 94 | // of ID. |
| 95 | uint8_t D[EVP_MAX_MD_BLOCK_SIZE]; |
| 96 | OPENSSL_memset(D, id, block_size); |
| 97 |
| 98 | // 2. Concatenate copies of the salt together to create a string S of length |
| 99 | // v(ceiling(s/v)) bits (the final copy of the salt may be truncated to |
| 100 | // create S). Note that if the salt is the empty string, then so is S. |
| 101 | // |
| 102 | // 3. Concatenate copies of the password together to create a string P of |
| 103 | // length v(ceiling(p/v)) bits (the final copy of the password may be |
| 104 | // truncated to create P). Note that if the password is the empty string, |
| 105 | // then so is P. |
| 106 | // |
| 107 | // 4. Set I=S||P to be the concatenation of S and P. |
| 108 | if (salt_len + block_size - 1 < salt_len || |
| 109 | pass_raw_len + block_size - 1 < pass_raw_len) { |
| 110 | OPENSSL_PUT_ERROR(PKCS8, ERR_R_OVERFLOW); |
| 111 | goto err; |
| 112 | } |
| 113 | size_t S_len = block_size * ((salt_len + block_size - 1) / block_size); |
| 114 | size_t P_len = block_size * ((pass_raw_len + block_size - 1) / block_size); |
| 115 | I_len = S_len + P_len; |
| 116 | if (I_len < S_len) { |
| 117 | OPENSSL_PUT_ERROR(PKCS8, ERR_R_OVERFLOW); |
| 118 | goto err; |
| 119 | } |
| 120 |
| 121 | I = reinterpret_cast<uint8_t *>(OPENSSL_malloc(I_len)); |
| 122 | if (I_len != 0 && I == NULL) { |
| 123 | goto err; |
| 124 | } |
| 125 |
| 126 | for (size_t i = 0; i < S_len; i++) { |
| 127 | I[i] = salt[i % salt_len]; |
| 128 | } |
| 129 | for (size_t i = 0; i < P_len; i++) { |
| 130 | I[i + S_len] = pass_raw[i % pass_raw_len]; |
| 131 | } |
| 132 |
| 133 | while (out_len != 0) { |
| 134 | // A. Set A_i=H^r(D||I). (i.e., the r-th hash of D||I, |
| 135 | // H(H(H(... H(D||I)))) |
| 136 | uint8_t A[EVP_MAX_MD_SIZE]; |
| 137 | unsigned A_len; |
| 138 | if (!EVP_DigestInit_ex(&ctx, md, NULL) || |
| 139 | !EVP_DigestUpdate(&ctx, D, block_size) || |
| 140 | !EVP_DigestUpdate(&ctx, I, I_len) || |
| 141 | !EVP_DigestFinal_ex(&ctx, A, &A_len)) { |
| 142 | goto err; |
| 143 | } |
| 144 | for (uint32_t iter = 1; iter < iterations; iter++) { |
| 145 | if (!EVP_DigestInit_ex(&ctx, md, NULL) || |
| 146 | !EVP_DigestUpdate(&ctx, A, A_len) || |
| 147 | !EVP_DigestFinal_ex(&ctx, A, &A_len)) { |
| 148 | goto err; |
| 149 | } |
| 150 | } |
| 151 |
| 152 | size_t todo = out_len < A_len ? out_len : A_len; |
| 153 | OPENSSL_memcpy(out, A, todo); |
| 154 | out += todo; |
| 155 | out_len -= todo; |
| 156 | if (out_len == 0) { |
| 157 | break; |
| 158 | } |
| 159 |
| 160 | // B. Concatenate copies of A_i to create a string B of length v bits (the |
| 161 | // final copy of A_i may be truncated to create B). |
| 162 | uint8_t B[EVP_MAX_MD_BLOCK_SIZE]; |
| 163 | for (size_t i = 0; i < block_size; i++) { |
| 164 | B[i] = A[i % A_len]; |
| 165 | } |
| 166 |
| 167 | // C. Treating I as a concatenation I_0, I_1, ..., I_(k-1) of v-bit |
| 168 | // blocks, where k=ceiling(s/v)+ceiling(p/v), modify I by setting |
| 169 | // I_j=(I_j+B+1) mod 2^v for each j. |
| 170 | assert(I_len % block_size == 0); |
| 171 | for (size_t i = 0; i < I_len; i += block_size) { |
| 172 | unsigned carry = 1; |
| 173 | for (size_t j = block_size - 1; j < block_size; j--) { |
| 174 | carry += I[i + j] + B[j]; |
| 175 | I[i + j] = (uint8_t)carry; |
| 176 | carry >>= 8; |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 |
| 181 | ret = 1; |
| 182 | } |
| 183 |
| 184 | err: |
| 185 | OPENSSL_free(I); |
| 186 | OPENSSL_free(pass_raw); |
| 187 | EVP_MD_CTX_cleanup(&ctx); |
| 188 | return ret; |
| 189 | } |
| 190 |
| 191 | static int pkcs12_pbe_cipher_init(const struct pbe_suite *suite, |
| 192 | EVP_CIPHER_CTX *ctx, uint32_t iterations, |
| 193 | const char *pass, size_t pass_len, |
| 194 | const uint8_t *salt, size_t salt_len, |
| 195 | int is_encrypt) { |
| 196 | const EVP_CIPHER *cipher = suite->cipher_func(); |
| 197 | const EVP_MD *md = suite->md_func(); |
| 198 |
| 199 | uint8_t key[EVP_MAX_KEY_LENGTH]; |
| 200 | uint8_t iv[EVP_MAX_IV_LENGTH]; |
| 201 | if (!pkcs12_key_gen(pass, pass_len, salt, salt_len, PKCS12_KEY_ID, iterations, |
| 202 | EVP_CIPHER_key_length(cipher), key, md) || |
| 203 | !pkcs12_key_gen(pass, pass_len, salt, salt_len, PKCS12_IV_ID, iterations, |
| 204 | EVP_CIPHER_iv_length(cipher), iv, md)) { |
| 205 | OPENSSL_PUT_ERROR(PKCS8, PKCS8_R_KEY_GEN_ERROR); |
| 206 | return 0; |
| 207 | } |
| 208 |
| 209 | int ret = EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, is_encrypt); |
| 210 | OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH); |
| 211 | OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH); |
| 212 | return ret; |
| 213 | } |
| 214 |
| 215 | static int pkcs12_pbe_decrypt_init(const struct pbe_suite *suite, |
| 216 | EVP_CIPHER_CTX *ctx, const char *pass, |
| 217 | size_t pass_len, CBS *param) { |
| 218 | CBS pbe_param, salt; |
| 219 | uint64_t iterations; |
| 220 | if (!CBS_get_asn1(param, &pbe_param, CBS_ASN1_SEQUENCE) || |
| 221 | !CBS_get_asn1(&pbe_param, &salt, CBS_ASN1_OCTETSTRING) || |
| 222 | !CBS_get_asn1_uint64(&pbe_param, &iterations) || |
| 223 | CBS_len(&pbe_param) != 0 || CBS_len(param) != 0) { |
| 224 | OPENSSL_PUT_ERROR(PKCS8, PKCS8_R_DECODE_ERROR); |
| 225 | return 0; |
| 226 | } |
| 227 |
| 228 | if (!pkcs12_iterations_acceptable(iterations)) { |
| 229 | OPENSSL_PUT_ERROR(PKCS8, PKCS8_R_BAD_ITERATION_COUNT); |
| 230 | return 0; |
| 231 | } |
| 232 |
| 233 | return pkcs12_pbe_cipher_init(suite, ctx, (uint32_t)iterations, pass, |
| 234 | pass_len, CBS_data(&salt), CBS_len(&salt), |
| 235 | 0 /* decrypt */); |
| 236 | } |
| 237 |
| 238 | static const struct pbe_suite kBuiltinPBE[] = { |
| 239 | { |
| 240 | NID_pbe_WithSHA1And40BitRC2_CBC, |
| 241 | // 1.2.840.113549.1.12.1.6 |
| 242 | {0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x0c, 0x01, 0x06}, |
| 243 | 10, |
| 244 | EVP_rc2_40_cbc, |
| 245 | EVP_sha1, |
| 246 | pkcs12_pbe_decrypt_init, |
| 247 | }, |
| 248 | { |
| 249 | NID_pbe_WithSHA1And128BitRC4, |
| 250 | // 1.2.840.113549.1.12.1.1 |
| 251 | {0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x0c, 0x01, 0x01}, |
| 252 | 10, |
| 253 | EVP_rc4, |
| 254 | EVP_sha1, |
| 255 | pkcs12_pbe_decrypt_init, |
| 256 | }, |
| 257 | { |
| 258 | NID_pbe_WithSHA1And3_Key_TripleDES_CBC, |
| 259 | // 1.2.840.113549.1.12.1.3 |
| 260 | {0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x0c, 0x01, 0x03}, |
| 261 | 10, |
| 262 | EVP_des_ede3_cbc, |
| 263 | EVP_sha1, |
| 264 | pkcs12_pbe_decrypt_init, |
| 265 | }, |
| 266 | { |
| 267 | NID_pbes2, |
| 268 | // 1.2.840.113549.1.5.13 |
| 269 | {0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05, 0x0d}, |
| 270 | 9, |
| 271 | NULL, |
| 272 | NULL, |
| 273 | PKCS5_pbe2_decrypt_init, |
| 274 | }, |
| 275 | }; |
| 276 |
| 277 | static const struct pbe_suite *get_pkcs12_pbe_suite(int pbe_nid) { |
| 278 | for (unsigned i = 0; i < OPENSSL_ARRAY_SIZE(kBuiltinPBE); i++) { |
| 279 | if (kBuiltinPBE[i].pbe_nid == pbe_nid && |
| 280 | // If |cipher_func| or |md_func| are missing, this is a PBES2 scheme. |
| 281 | kBuiltinPBE[i].cipher_func != NULL && kBuiltinPBE[i].md_func != NULL) { |
| 282 | return &kBuiltinPBE[i]; |
| 283 | } |
| 284 | } |
| 285 |
| 286 | return NULL; |
| 287 | } |
| 288 |
| 289 | int pkcs12_pbe_encrypt_init(CBB *out, EVP_CIPHER_CTX *ctx, int alg_nid, |
| 290 | const EVP_CIPHER *alg_cipher, uint32_t iterations, |
| 291 | const char *pass, size_t pass_len, |
| 292 | const uint8_t *salt, size_t salt_len) { |
| 293 | // TODO(davidben): OpenSSL has since extended |pbe_nid| to control either |
| 294 | // the PBES1 scheme or the PBES2 PRF. E.g. passing |NID_hmacWithSHA256| will |
| 295 | // select PBES2 with HMAC-SHA256 as the PRF. Implement this if anything uses |
| 296 | // it. See 5693a30813a031d3921a016a870420e7eb93ec90 in OpenSSL. |
| 297 | if (alg_nid == -1) { |
| 298 | return PKCS5_pbe2_encrypt_init(out, ctx, alg_cipher, iterations, pass, |
| 299 | pass_len, salt, salt_len); |
| 300 | } |
| 301 |
| 302 | const struct pbe_suite *suite = get_pkcs12_pbe_suite(alg_nid); |
| 303 | if (suite == NULL) { |
| 304 | OPENSSL_PUT_ERROR(PKCS8, PKCS8_R_UNKNOWN_ALGORITHM); |
| 305 | return 0; |
| 306 | } |
| 307 |
| 308 | // See RFC 2898, appendix A.3. |
| 309 | CBB algorithm, oid, param, salt_cbb; |
| 310 | if (!CBB_add_asn1(out, &algorithm, CBS_ASN1_SEQUENCE) || |
| 311 | !CBB_add_asn1(&algorithm, &oid, CBS_ASN1_OBJECT) || |
| 312 | !CBB_add_bytes(&oid, suite->oid, suite->oid_len) || |
| 313 | !CBB_add_asn1(&algorithm, ¶m, CBS_ASN1_SEQUENCE) || |
| 314 | !CBB_add_asn1(¶m, &salt_cbb, CBS_ASN1_OCTETSTRING) || |
| 315 | !CBB_add_bytes(&salt_cbb, salt, salt_len) || |
| 316 | !CBB_add_asn1_uint64(¶m, iterations) || !CBB_flush(out)) { |
| 317 | return 0; |
| 318 | } |
| 319 |
| 320 | return pkcs12_pbe_cipher_init(suite, ctx, iterations, pass, pass_len, salt, |
| 321 | salt_len, 1 /* encrypt */); |
| 322 | } |
| 323 |
| 324 | int pkcs8_pbe_decrypt(uint8_t **out, size_t *out_len, CBS *algorithm, |
| 325 | const char *pass, size_t pass_len, const uint8_t *in, |
| 326 | size_t in_len) { |
| 327 | int ret = 0; |
| 328 | uint8_t *buf = NULL; |
| 329 | ; |
| 330 | EVP_CIPHER_CTX ctx; |
| 331 | EVP_CIPHER_CTX_init(&ctx); |
| 332 |
| 333 | CBS obj; |
| 334 | const struct pbe_suite *suite = NULL; |
| 335 | if (!CBS_get_asn1(algorithm, &obj, CBS_ASN1_OBJECT)) { |
| 336 | OPENSSL_PUT_ERROR(PKCS8, PKCS8_R_DECODE_ERROR); |
| 337 | goto err; |
| 338 | } |
| 339 |
| 340 | for (unsigned i = 0; i < OPENSSL_ARRAY_SIZE(kBuiltinPBE); i++) { |
| 341 | if (CBS_mem_equal(&obj, kBuiltinPBE[i].oid, kBuiltinPBE[i].oid_len)) { |
| 342 | suite = &kBuiltinPBE[i]; |
| 343 | break; |
| 344 | } |
| 345 | } |
| 346 | if (suite == NULL) { |
| 347 | OPENSSL_PUT_ERROR(PKCS8, PKCS8_R_UNKNOWN_ALGORITHM); |
| 348 | goto err; |
| 349 | } |
| 350 |
| 351 | if (!suite->decrypt_init(suite, &ctx, pass, pass_len, algorithm)) { |
| 352 | OPENSSL_PUT_ERROR(PKCS8, PKCS8_R_KEYGEN_FAILURE); |
| 353 | goto err; |
| 354 | } |
| 355 |
| 356 | buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(in_len)); |
| 357 | if (buf == NULL) { |
| 358 | goto err; |
| 359 | } |
| 360 |
| 361 | if (in_len > INT_MAX) { |
| 362 | OPENSSL_PUT_ERROR(PKCS8, ERR_R_OVERFLOW); |
| 363 | goto err; |
| 364 | } |
| 365 |
| 366 | int n1, n2; |
| 367 | if (!EVP_DecryptUpdate(&ctx, buf, &n1, in, (int)in_len) || |
| 368 | !EVP_DecryptFinal_ex(&ctx, buf + n1, &n2)) { |
| 369 | goto err; |
| 370 | } |
| 371 |
| 372 | *out = buf; |
| 373 | *out_len = n1 + n2; |
| 374 | ret = 1; |
| 375 | buf = NULL; |
| 376 |
| 377 | err: |
| 378 | OPENSSL_free(buf); |
| 379 | EVP_CIPHER_CTX_cleanup(&ctx); |
| 380 | return ret; |
| 381 | } |
| 382 |
| 383 | EVP_PKEY *PKCS8_parse_encrypted_private_key(CBS *cbs, const char *pass, |
| 384 | size_t pass_len) { |
| 385 | // See RFC 5208, section 6. |
| 386 | CBS epki, algorithm, ciphertext; |
| 387 | if (!CBS_get_asn1(cbs, &epki, CBS_ASN1_SEQUENCE) || |
| 388 | !CBS_get_asn1(&epki, &algorithm, CBS_ASN1_SEQUENCE) || |
| 389 | !CBS_get_asn1(&epki, &ciphertext, CBS_ASN1_OCTETSTRING) || |
| 390 | CBS_len(&epki) != 0) { |
| 391 | OPENSSL_PUT_ERROR(PKCS8, PKCS8_R_DECODE_ERROR); |
| 392 | return 0; |
| 393 | } |
| 394 |
| 395 | uint8_t *out; |
| 396 | size_t out_len; |
| 397 | if (!pkcs8_pbe_decrypt(&out, &out_len, &algorithm, pass, pass_len, |
| 398 | CBS_data(&ciphertext), CBS_len(&ciphertext))) { |
| 399 | return 0; |
| 400 | } |
| 401 |
| 402 | CBS pki; |
| 403 | CBS_init(&pki, out, out_len); |
| 404 | EVP_PKEY *ret = EVP_parse_private_key(&pki); |
| 405 | OPENSSL_free(out); |
| 406 | return ret; |
| 407 | } |
| 408 |
| 409 | int PKCS8_marshal_encrypted_private_key(CBB *out, int pbe_nid, |
| 410 | const EVP_CIPHER *cipher, |
| 411 | const char *pass, size_t pass_len, |
| 412 | const uint8_t *salt, size_t salt_len, |
| 413 | int iterations, const EVP_PKEY *pkey) { |
| 414 | int ret = 0; |
| 415 | uint8_t *plaintext = NULL, *salt_buf = NULL; |
| 416 | size_t plaintext_len = 0; |
| 417 | EVP_CIPHER_CTX ctx; |
| 418 | EVP_CIPHER_CTX_init(&ctx); |
| 419 |
| 420 | { |
| 421 | // Generate a random salt if necessary. |
| 422 | if (salt == NULL) { |
| 423 | if (salt_len == 0) { |
| 424 | salt_len = PKCS5_SALT_LEN; |
| 425 | } |
| 426 |
| 427 | salt_buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(salt_len)); |
| 428 | if (salt_buf == NULL || !RAND_bytes(salt_buf, salt_len)) { |
| 429 | goto err; |
| 430 | } |
| 431 |
| 432 | salt = salt_buf; |
| 433 | } |
| 434 |
| 435 | if (iterations <= 0) { |
| 436 | iterations = PKCS12_DEFAULT_ITER; |
| 437 | } |
| 438 |
| 439 | // Serialize the input key. |
| 440 | CBB plaintext_cbb; |
| 441 | if (!CBB_init(&plaintext_cbb, 128) || |
| 442 | !EVP_marshal_private_key(&plaintext_cbb, pkey) || |
| 443 | !CBB_finish(&plaintext_cbb, &plaintext, &plaintext_len)) { |
| 444 | CBB_cleanup(&plaintext_cbb); |
| 445 | goto err; |
| 446 | } |
| 447 |
| 448 | CBB epki; |
| 449 | if (!CBB_add_asn1(out, &epki, CBS_ASN1_SEQUENCE) || |
| 450 | !pkcs12_pbe_encrypt_init(&epki, &ctx, pbe_nid, cipher, |
| 451 | (uint32_t)iterations, pass, pass_len, salt, |
| 452 | salt_len)) { |
| 453 | goto err; |
| 454 | } |
| 455 |
| 456 | size_t max_out = plaintext_len + EVP_CIPHER_CTX_block_size(&ctx); |
| 457 | if (max_out < plaintext_len) { |
| 458 | OPENSSL_PUT_ERROR(PKCS8, PKCS8_R_TOO_LONG); |
| 459 | goto err; |
| 460 | } |
| 461 |
| 462 | CBB ciphertext; |
| 463 | uint8_t *ptr; |
| 464 | int n1, n2; |
| 465 | if (!CBB_add_asn1(&epki, &ciphertext, CBS_ASN1_OCTETSTRING) || |
| 466 | !CBB_reserve(&ciphertext, &ptr, max_out) || |
| 467 | !EVP_CipherUpdate(&ctx, ptr, &n1, plaintext, plaintext_len) || |
| 468 | !EVP_CipherFinal_ex(&ctx, ptr + n1, &n2) || |
| 469 | !CBB_did_write(&ciphertext, n1 + n2) || !CBB_flush(out)) { |
| 470 | goto err; |
| 471 | } |
| 472 |
| 473 | ret = 1; |
| 474 | } |
| 475 |
| 476 | err: |
| 477 | OPENSSL_free(plaintext); |
| 478 | OPENSSL_free(salt_buf); |
| 479 | EVP_CIPHER_CTX_cleanup(&ctx); |
| 480 | return ret; |
| 481 | } |
| 482 |