2 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include "internal/cryptlib.h"
12 #include <openssl/pkcs12.h>
14 /* PKCS#12 PBE algorithms now in static table */
16 void PKCS12_PBE_add(void)
20 int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
21 ASN1_TYPE *param, const EVP_CIPHER *cipher,
22 const EVP_MD *md, int en_de)
25 int saltlen, iter, ret;
27 unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
32 /* Extract useful info from parameter */
34 pbe = ASN1_TYPE_unpack_sequence(ASN1_ITEM_rptr(PBEPARAM), param);
36 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_DECODE_ERROR);
43 iter = ASN1_INTEGER_get(pbe->iter);
44 salt = pbe->salt->data;
45 saltlen = pbe->salt->length;
46 if (!PKCS12_key_gen(pass, passlen, salt, saltlen, PKCS12_KEY_ID,
47 iter, EVP_CIPHER_key_length(cipher), key, md)) {
48 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_KEY_GEN_ERROR);
52 if (!PKCS12_key_gen(pass, passlen, salt, saltlen, PKCS12_IV_ID,
53 iter, EVP_CIPHER_iv_length(cipher), iv, md)) {
54 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_IV_GEN_ERROR);
59 ret = EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, en_de);
60 OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH);
61 OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH);