1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimPKCS5_PBKDF2_HMAC, PKCS5_PBKDF2_HMAC_SHA1 - password based derivation routines with salt and iteration count 6e71b7053SJung-uk Kim 7e71b7053SJung-uk Kim=head1 SYNOPSIS 8e71b7053SJung-uk Kim 9e71b7053SJung-uk Kim #include <openssl/evp.h> 10e71b7053SJung-uk Kim 11e71b7053SJung-uk Kim int PKCS5_PBKDF2_HMAC(const char *pass, int passlen, 12e71b7053SJung-uk Kim const unsigned char *salt, int saltlen, int iter, 13e71b7053SJung-uk Kim const EVP_MD *digest, 14e71b7053SJung-uk Kim int keylen, unsigned char *out); 15e71b7053SJung-uk Kim 16e71b7053SJung-uk Kim int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, 17e71b7053SJung-uk Kim const unsigned char *salt, int saltlen, int iter, 18e71b7053SJung-uk Kim int keylen, unsigned char *out); 19e71b7053SJung-uk Kim 20e71b7053SJung-uk Kim=head1 DESCRIPTION 21e71b7053SJung-uk Kim 22e71b7053SJung-uk KimPKCS5_PBKDF2_HMAC() derives a key from a password using a salt and iteration count 23e71b7053SJung-uk Kimas specified in RFC 2898. 24e71b7053SJung-uk Kim 25e71b7053SJung-uk KimB<pass> is the password used in the derivation of length B<passlen>. B<pass> 26e71b7053SJung-uk Kimis an optional parameter and can be NULL. If B<passlen> is -1, then the 27e71b7053SJung-uk Kimfunction will calculate the length of B<pass> using strlen(). 28e71b7053SJung-uk Kim 29e71b7053SJung-uk KimB<salt> is the salt used in the derivation of length B<saltlen>. If the 30e71b7053SJung-uk KimB<salt> is NULL, then B<saltlen> must be 0. The function will not 31e71b7053SJung-uk Kimattempt to calculate the length of the B<salt> because it is not assumed to 32e71b7053SJung-uk Kimbe NULL terminated. 33e71b7053SJung-uk Kim 34e71b7053SJung-uk KimB<iter> is the iteration count and its value should be greater than or 35e71b7053SJung-uk Kimequal to 1. RFC 2898 suggests an iteration count of at least 1000. Any 36*ad991e4cSEd MasteB<iter> value less than 1 is invalid; such values will result in failure 37*ad991e4cSEd Masteand raise the PROV_R_INVALID_ITERATION_COUNT error. 38e71b7053SJung-uk Kim 39b077aed3SPierre ProncheryB<digest> is the message digest function used in the derivation. 40b077aed3SPierre ProncheryPKCS5_PBKDF2_HMAC_SHA1() calls PKCS5_PBKDF2_HMAC() with EVP_sha1(). 41e71b7053SJung-uk Kim 42e71b7053SJung-uk KimThe derived key will be written to B<out>. The size of the B<out> buffer 43e71b7053SJung-uk Kimis specified via B<keylen>. 44e71b7053SJung-uk Kim 45e71b7053SJung-uk Kim=head1 NOTES 46e71b7053SJung-uk Kim 47e71b7053SJung-uk KimA typical application of this function is to derive keying material for an 48e71b7053SJung-uk Kimencryption algorithm from a password in the B<pass>, a salt in B<salt>, 49e71b7053SJung-uk Kimand an iteration count. 50e71b7053SJung-uk Kim 51e71b7053SJung-uk KimIncreasing the B<iter> parameter slows down the algorithm which makes it 52e71b7053SJung-uk Kimharder for an attacker to perform a brute force attack using a large number 53e71b7053SJung-uk Kimof candidate passwords. 54e71b7053SJung-uk Kim 55e71b7053SJung-uk KimThese functions make no assumption regarding the given password. 56e71b7053SJung-uk KimIt will simply be treated as a byte sequence. 57e71b7053SJung-uk Kim 58e71b7053SJung-uk Kim=head1 RETURN VALUES 59e71b7053SJung-uk Kim 60e71b7053SJung-uk KimPKCS5_PBKDF2_HMAC() and PBKCS5_PBKDF2_HMAC_SHA1() return 1 on success or 0 on error. 61e71b7053SJung-uk Kim 62e71b7053SJung-uk Kim=head1 SEE ALSO 63e71b7053SJung-uk Kim 64e71b7053SJung-uk KimL<evp(7)>, L<RAND_bytes(3)>, 65e71b7053SJung-uk KimL<EVP_BytesToKey(3)>, 66e71b7053SJung-uk KimL<passphrase-encoding(7)> 67e71b7053SJung-uk Kim 68e71b7053SJung-uk Kim=head1 COPYRIGHT 69e71b7053SJung-uk Kim 70*ad991e4cSEd MasteCopyright 2014-2023 The OpenSSL Project Authors. All Rights Reserved. 71e71b7053SJung-uk Kim 72b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 73e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 74e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 75e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 76e71b7053SJung-uk Kim 77e71b7053SJung-uk Kim=cut 78