1 1.1 christos =pod 2 1.1 christos 3 1.1 christos =head1 NAME 4 1.1 christos 5 1.1 christos PKCS5_PBE_keyivgen, PKCS5_PBE_keyivgen_ex, PKCS5_pbe2_set, PKCS5_pbe2_set_iv, 6 1.1 christos PKCS5_pbe2_set_iv_ex, PKCS5_pbe_set, PKCS5_pbe_set_ex, PKCS5_pbe2_set_scrypt, 7 1.1 christos PKCS5_pbe_set0_algor, PKCS5_pbe_set0_algor_ex, 8 1.1 christos PKCS5_v2_PBE_keyivgen, PKCS5_v2_PBE_keyivgen_ex, 9 1.1 christos PKCS5_v2_scrypt_keyivgen, PKCS5_v2_scrypt_keyivgen_ex, 10 1.1 christos PKCS5_pbkdf2_set, PKCS5_pbkdf2_set_ex, EVP_PBE_scrypt, EVP_PBE_scrypt_ex 11 1.1 christos - PKCS#5 Password based encryption routines 12 1.1 christos 13 1.1 christos =head1 SYNOPSIS 14 1.1 christos 15 1.1 christos #include <openssl/evp.h> 16 1.1 christos 17 1.1 christos int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, 18 1.1 christos ASN1_TYPE *param, const EVP_CIPHER *cipher, 19 1.1 christos const EVP_MD *md, int en_de); 20 1.1 christos int PKCS5_PBE_keyivgen_ex(EVP_CIPHER_CTX *cctx, const char *pass, int passlen, 21 1.1 christos ASN1_TYPE *param, const EVP_CIPHER *cipher, 22 1.1 christos const EVP_MD *md, int en_de, OSSL_LIB_CTX *libctx, 23 1.1 christos const char *propq); 24 1.1 christos int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, 25 1.1 christos ASN1_TYPE *param, const EVP_CIPHER *cipher, 26 1.1 christos const EVP_MD *md, int en_de); 27 1.1 christos int PKCS5_v2_PBE_keyivgen_ex(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, 28 1.1 christos ASN1_TYPE *param, const EVP_CIPHER *cipher, 29 1.1 christos const EVP_MD *md, int en_de, 30 1.1 christos OSSL_LIB_CTX *libctx, const char *propq); 31 1.1 christos int EVP_PBE_scrypt(const char *pass, size_t passlen, 32 1.1 christos const unsigned char *salt, size_t saltlen, 33 1.1 christos uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem, 34 1.1 christos unsigned char *key, size_t keylen); 35 1.1 christos int EVP_PBE_scrypt_ex(const char *pass, size_t passlen, 36 1.1 christos const unsigned char *salt, size_t saltlen, 37 1.1 christos uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem, 38 1.1 christos unsigned char *key, size_t keylen, 39 1.1 christos OSSL_LIB_CTX *ctx, const char *propq); 40 1.1 christos int PKCS5_v2_scrypt_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, 41 1.1 christos int passlen, ASN1_TYPE *param, 42 1.1 christos const EVP_CIPHER *c, const EVP_MD *md, int en_de); 43 1.1 christos int PKCS5_v2_scrypt_keyivgen_ex(EVP_CIPHER_CTX *ctx, const char *pass, 44 1.1 christos int passlen, ASN1_TYPE *param, 45 1.1 christos const EVP_CIPHER *c, const EVP_MD *md, int en_de, 46 1.1 christos OSSL_LIB_CTX *libctx, const char *propq); 47 1.1 christos 48 1.1 christos #include <openssl/x509.h> 49 1.1 christos 50 1.1 christos int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, 51 1.1 christos const unsigned char *salt, int saltlen); 52 1.1 christos int PKCS5_pbe_set0_algor_ex(X509_ALGOR *algor, int alg, int iter, 53 1.1 christos const unsigned char *salt, int saltlen, 54 1.1 christos OSSL_LIB_CTX *libctx); 55 1.1 christos 56 1.1 christos X509_ALGOR *PKCS5_pbe_set(int alg, int iter, 57 1.1 christos const unsigned char *salt, int saltlen); 58 1.1 christos X509_ALGOR *PKCS5_pbe_set_ex(int alg, int iter, 59 1.1 christos const unsigned char *salt, int saltlen, 60 1.1 christos OSSL_LIB_CTX *libctx); 61 1.1 christos 62 1.1 christos X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, 63 1.1 christos unsigned char *salt, int saltlen); 64 1.1 christos X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, 65 1.1 christos unsigned char *salt, int saltlen, 66 1.1 christos unsigned char *aiv, int prf_nid); 67 1.1 christos X509_ALGOR *PKCS5_pbe2_set_iv_ex(const EVP_CIPHER *cipher, int iter, 68 1.1 christos unsigned char *salt, int saltlen, 69 1.1 christos unsigned char *aiv, int prf_nid, 70 1.1 christos OSSL_LIB_CTX *libctx); 71 1.1 christos X509_ALGOR *PKCS5_pbe2_set_scrypt(const EVP_CIPHER *cipher, 72 1.1 christos const unsigned char *salt, int saltlen, 73 1.1 christos unsigned char *aiv, uint64_t N, uint64_t r, 74 1.1 christos uint64_t p); 75 1.1 christos 76 1.1 christos X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, 77 1.1 christos int prf_nid, int keylen); 78 1.1 christos X509_ALGOR *PKCS5_pbkdf2_set_ex(int iter, unsigned char *salt, int saltlen, 79 1.1 christos int prf_nid, int keylen, 80 1.1 christos OSSL_LIB_CTX *libctx); 81 1.1 christos 82 1.1 christos =head1 DESCRIPTION 83 1.1 christos 84 1.1 christos =head2 Key Derivation 85 1.1 christos 86 1.1 christos PKCS5_PBE_keyivgen() and PKCS5_PBE_keyivgen_ex() take a password I<pass> of 87 1.1 christos length I<passlen>, parameters I<param> and a message digest function I<md_type> 88 1.1 christos and performs a key derivation according to PKCS#5 PBES1. The resulting key is 89 1.1 christos then used to initialise the cipher context I<ctx> with a cipher I<cipher> for 90 1.1 christos encryption (I<en_de>=1) or decryption (I<en_de>=0). 91 1.1 christos 92 1.1 christos I<pass> is an optional parameter and can be NULL. If I<passlen> is -1, then the 93 1.1 christos function will calculate the length of I<pass> using strlen(). 94 1.1 christos 95 1.1 christos PKCS5_v2_PBE_keyivgen() and PKCS5_v2_PBE_keyivgen_ex() are similar to the above 96 1.1 christos but instead use PKCS#5 PBES2 as the encryption algorithm using the supplied 97 1.1 christos parameters. 98 1.1 christos 99 1.1 christos PKCS5_v2_scrypt_keyivgen() and PKCS5_v2_scrypt_keyivgen_ex() use SCRYPT as the 100 1.1 christos key derivation part of the encryption algorithm. 101 1.1 christos 102 1.1 christos I<salt> is the salt used in the derivation of length I<saltlen>. If the 103 1.1 christos I<salt> is NULL, then I<saltlen> must be 0. The function will not 104 1.1 christos attempt to calculate the length of the I<salt> because it is not assumed to 105 1.1 christos be NULL terminated. 106 1.1 christos 107 1.1 christos I<iter> is the iteration count and its value should be greater than or 108 1.1 christos equal to 1. RFC 2898 suggests an iteration count of at least 1000. Any 109 1.1 christos I<iter> less than 1 is treated as a single iteration. 110 1.1 christos 111 1.1 christos I<digest> is the message digest function used in the derivation. 112 1.1 christos 113 1.1 christos Functions ending in _ex() take optional parameters I<libctx> and I<propq> which 114 1.1 christos are used to select appropriate algorithm implementations. 115 1.1 christos 116 1.1 christos =head2 Algorithm Identifier Creation 117 1.1 christos 118 1.1 christos PKCS5_pbe_set(), PKCS5_pbe_set_ex(), PKCS5_pbe2_set(), PKCS5_pbe2_set_iv(), 119 1.1 christos PKCS5_pbe2_set_iv_ex() and PKCS5_pbe2_set_scrypt() generate an B<X509_ALGOR> 120 1.1 christos object which represents an AlgorithmIdentifier containing the algorithm OID and 121 1.1 christos associated parameters for the PBE algorithm. 122 1.1 christos 123 1.1 christos PKCS5_pbkdf2_set() and PKCS5_pbkdf2_set_ex() generate an B<X509_ALGOR> 124 1.1 christos object which represents an AlgorithmIdentifier containing the algorithm OID and 125 1.1 christos associated parameters for the PBKDF2 algorithm. 126 1.1 christos 127 1.1 christos PKCS5_pbe_set0_algor() and PKCS5_pbe_set0_algor_ex() set the PBE algorithm OID and 128 1.1 christos parameters into the supplied B<X509_ALGOR>. 129 1.1 christos 130 1.1 christos =head1 NOTES 131 1.1 christos 132 1.1 christos The *_keyivgen() functions are typically used in PKCS#12 to encrypt objects. 133 1.1 christos 134 1.1 christos These functions make no assumption regarding the given password. 135 1.1 christos It will simply be treated as a byte sequence. 136 1.1 christos 137 1.1 christos =head1 RETURN VALUES 138 1.1 christos 139 1.1 christos PKCS5_PBE_keyivgen(), PKCS5_v2_PBE_keyivgen(), 140 1.1 christos PKCS5_v2_PBE_keyivgen_ex(), PKCS5_v2_scrypt_keyivgen(), 141 1.1 christos PKCS5_v2_scrypt_keyivgen_ex(), PKCS5_pbe_set0_algor() and 142 1.1 christos PKCS5_pbe_set0_algor_ex() return 1 for success and 0 if an error occurs. 143 1.1 christos 144 1.1 christos PKCS5_pbe_set(), PKCS5_pbe_set_ex(), PKCS5_pbe2_set(), PKCS5_pbe2_set_iv(), 145 1.1 christos PKCS5_pbe2_set_iv_ex(), PKCS5_pbe2_set_scrypt(), 146 1.1 christos PKCS5_pbkdf2_set() and PKCS5_pbkdf2_set_ex() return an B<X509_ALGOR> object or 147 1.1 christos NULL if an error occurs. 148 1.1 christos 149 1.1 christos =head1 CONFORMING TO 150 1.1 christos 151 1.1 christos IETF RFC 8018 (L<https://tools.ietf.org/html/rfc8018>) 152 1.1 christos 153 1.1 christos =head1 SEE ALSO 154 1.1 christos 155 1.1 christos L<EVP_PBE_CipherInit_ex(3)>, 156 1.1 christos L<PKCS12_pbe_crypt_ex(3)>, 157 1.1 christos L<passphrase-encoding(7)> 158 1.1 christos 159 1.1 christos =head1 HISTORY 160 1.1 christos 161 1.1 christos PKCS5_v2_PBE_keyivgen_ex(), EVP_PBE_scrypt_ex(), PKCS5_v2_scrypt_keyivgen_ex(), 162 1.1 christos PKCS5_pbe_set0_algor_ex(), PKCS5_pbe_set_ex(), PKCS5_pbe2_set_iv_ex() and 163 1.1 christos PKCS5_pbkdf2_set_ex() were added in OpenSSL 3.0. 164 1.1 christos 165 1.1 christos From OpenSSL 3.0 the PBKDF1 algorithm used in PKCS5_PBE_keyivgen() and 166 1.1 christos PKCS5_PBE_keyivgen_ex() has been moved to the legacy provider as an EVP_KDF. 167 1.1 christos 168 1.1 christos =head1 COPYRIGHT 169 1.1 christos 170 1.1 christos Copyright 2021 The OpenSSL Project Authors. All Rights Reserved. 171 1.1 christos 172 1.1 christos Licensed under the Apache License 2.0 (the "License"). You may not use 173 1.1 christos this file except in compliance with the License. You can obtain a copy 174 1.1 christos in the file LICENSE in the source distribution or at 175 1.1 christos L<https://www.openssl.org/source/license.html>. 176 1.1 christos 177 1.1 christos =cut 178