1 1.1 christos =pod 2 1.1 christos 3 1.1 christos =head1 NAME 4 1.1 christos 5 1.1 christos PKCS12_PBE_keyivgen, PKCS12_PBE_keyivgen_ex, 6 1.1 christos PKCS12_pbe_crypt, PKCS12_pbe_crypt_ex - PKCS#12 Password based encryption 7 1.1 christos 8 1.1 christos =head1 SYNOPSIS 9 1.1 christos 10 1.1 christos #include <openssl/evp.h> 11 1.1 christos 12 1.1 christos int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, 13 1.1 christos ASN1_TYPE *param, const EVP_CIPHER *cipher, 14 1.1 christos const EVP_MD *md_type, int en_de); 15 1.1 christos int PKCS12_PBE_keyivgen_ex(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, 16 1.1 christos ASN1_TYPE *param, const EVP_CIPHER *cipher, 17 1.1 christos const EVP_MD *md_type, int en_de, 18 1.1 christos OSSL_LIB_CTX *libctx, const char *propq); 19 1.1 christos unsigned char *PKCS12_pbe_crypt(const X509_ALGOR *algor, 20 1.1 christos const char *pass, int passlen, 21 1.1 christos const unsigned char *in, int inlen, 22 1.1 christos unsigned char **data, int *datalen, 23 1.1 christos int en_de); 24 1.1 christos unsigned char *PKCS12_pbe_crypt_ex(const X509_ALGOR *algor, 25 1.1 christos const char *pass, int passlen, 26 1.1 christos const unsigned char *in, int inlen, 27 1.1 christos unsigned char **data, int *datalen, 28 1.1 christos int en_de, OSSL_LIB_CTX *libctx, 29 1.1 christos const char *propq); 30 1.1 christos 31 1.1 christos =head1 DESCRIPTION 32 1.1 christos 33 1.1 christos PKCS12_PBE_keyivgen() and PKCS12_PBE_keyivgen_ex() take a password I<pass> of 34 1.1 christos length I<passlen>, parameters I<param> and a message digest function I<md_type> 35 1.1 christos and perform a key derivation according to PKCS#12. The resulting key is 36 1.1 christos then used to initialise the cipher context I<ctx> with a cipher I<cipher> for 37 1.1 christos encryption (I<en_de>=1) or decryption (I<en_de>=0). 38 1.1 christos 39 1.1 christos PKCS12_PBE_keyivgen_ex() also allows the application to specify a library context 40 1.1 christos I<libctx> and property query I<propq> to select appropriate algorithm 41 1.1 christos implementations. 42 1.1 christos 43 1.1 christos PKCS12_pbe_crypt() and PKCS12_pbe_crypt_ex() will encrypt or decrypt a buffer 44 1.1 christos based on the algorithm in I<algor> and password I<pass> of length I<passlen>. 45 1.1 christos The input is from I<in> of length I<inlen> and output is into a malloc'd buffer 46 1.1 christos returned in I<*data> of length I<datalen>. The operation is determined by I<en_de>, 47 1.1 christos encryption (I<en_de>=1) or decryption (I<en_de>=0). 48 1.1 christos 49 1.1 christos PKCS12_pbe_crypt_ex() allows the application to specify a library context 50 1.1 christos I<libctx> and property query I<propq> to select appropriate algorithm 51 1.1 christos implementations. 52 1.1 christos 53 1.1 christos I<pass> is the password used in the derivation of length I<passlen>. I<pass> 54 1.1 christos is an optional parameter and can be NULL. If I<passlen> is -1, then the 55 1.1 christos function will calculate the length of I<pass> using strlen(). 56 1.1 christos 57 1.1 christos I<salt> is the salt used in the derivation of length I<saltlen>. If the 58 1.1 christos I<salt> is NULL, then I<saltlen> must be 0. The function will not 59 1.1 christos attempt to calculate the length of the I<salt> because it is not assumed to 60 1.1 christos be NULL terminated. 61 1.1 christos 62 1.1 christos I<iter> is the iteration count and its value should be greater than or 63 1.1 christos equal to 1. RFC 2898 suggests an iteration count of at least 1000. Any 64 1.1 christos I<iter> less than 1 is treated as a single iteration. 65 1.1 christos 66 1.1 christos I<digest> is the message digest function used in the derivation. 67 1.1 christos 68 1.1 christos Functions ending in _ex() take optional parameters I<libctx> and I<propq> which 69 1.1 christos are used to select appropriate algorithm implementations. 70 1.1 christos 71 1.1 christos =head1 NOTES 72 1.1 christos 73 1.1 christos The functions are typically used in PKCS#12 to encrypt objects. 74 1.1 christos 75 1.1 christos These functions make no assumption regarding the given password. 76 1.1 christos It will simply be treated as a byte sequence. 77 1.1 christos 78 1.1 christos =head1 RETURN VALUES 79 1.1 christos 80 1.1 christos PKCS12_PBE_keyivgen(), PKCS12_PBE_keyivgen_ex() return 1 on success or 0 on error. 81 1.1 christos 82 1.1 christos PKCS12_pbe_crypt() and PKCS12_pbe_crypt_ex() return a buffer containing the 83 1.1 christos output or NULL if an error occurred. 84 1.1 christos 85 1.1 christos =head1 CONFORMING TO 86 1.1 christos 87 1.1 christos IETF RFC 7292 (L<https://tools.ietf.org/html/rfc7292>) 88 1.1 christos 89 1.1 christos =head1 SEE ALSO 90 1.1 christos 91 1.1 christos L<EVP_PBE_CipherInit_ex(3)>, 92 1.1 christos L<PKCS8_encrypt_ex(3)>, 93 1.1 christos L<passphrase-encoding(7)> 94 1.1 christos 95 1.1 christos =head1 HISTORY 96 1.1 christos 97 1.1 christos PKCS12_PBE_keyivgen_ex() and PKCS12_pbe_crypt_ex() were added in OpenSSL 3.0. 98 1.1 christos 99 1.1 christos =head1 COPYRIGHT 100 1.1 christos 101 1.1 christos Copyright 2014-2021 The OpenSSL Project Authors. All Rights Reserved. 102 1.1 christos 103 1.1 christos Licensed under the Apache License 2.0 (the "License"). You may not use 104 1.1 christos this file except in compliance with the License. You can obtain a copy 105 1.1 christos in the file LICENSE in the source distribution or at 106 1.1 christos L<https://www.openssl.org/source/license.html>. 107 1.1 christos 108 1.1 christos =cut 109