1*64af7bbfSschwarze.\" $OpenBSD: PKCS5_PBKDF2_HMAC.3,v 1.9 2019/06/07 20:46:25 schwarze Exp $ 2b78a4598Sschwarze.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100 38974101aSjmc.\" 4b78a4598Sschwarze.\" This file was written by Jeffrey Walton <noloader@gmail.com>. 5b78a4598Sschwarze.\" Copyright (c) 2014, 2015 The OpenSSL Project. All rights reserved. 6b78a4598Sschwarze.\" 7b78a4598Sschwarze.\" Redistribution and use in source and binary forms, with or without 8b78a4598Sschwarze.\" modification, are permitted provided that the following conditions 9b78a4598Sschwarze.\" are met: 10b78a4598Sschwarze.\" 11b78a4598Sschwarze.\" 1. Redistributions of source code must retain the above copyright 12b78a4598Sschwarze.\" notice, this list of conditions and the following disclaimer. 13b78a4598Sschwarze.\" 14b78a4598Sschwarze.\" 2. Redistributions in binary form must reproduce the above copyright 15b78a4598Sschwarze.\" notice, this list of conditions and the following disclaimer in 16b78a4598Sschwarze.\" the documentation and/or other materials provided with the 17b78a4598Sschwarze.\" distribution. 18b78a4598Sschwarze.\" 19b78a4598Sschwarze.\" 3. All advertising materials mentioning features or use of this 20b78a4598Sschwarze.\" software must display the following acknowledgment: 21b78a4598Sschwarze.\" "This product includes software developed by the OpenSSL Project 22b78a4598Sschwarze.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 23b78a4598Sschwarze.\" 24b78a4598Sschwarze.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 25b78a4598Sschwarze.\" endorse or promote products derived from this software without 26b78a4598Sschwarze.\" prior written permission. For written permission, please contact 27b78a4598Sschwarze.\" openssl-core@openssl.org. 28b78a4598Sschwarze.\" 29b78a4598Sschwarze.\" 5. Products derived from this software may not be called "OpenSSL" 30b78a4598Sschwarze.\" nor may "OpenSSL" appear in their names without prior written 31b78a4598Sschwarze.\" permission of the OpenSSL Project. 32b78a4598Sschwarze.\" 33b78a4598Sschwarze.\" 6. Redistributions of any form whatsoever must retain the following 34b78a4598Sschwarze.\" acknowledgment: 35b78a4598Sschwarze.\" "This product includes software developed by the OpenSSL Project 36b78a4598Sschwarze.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 37b78a4598Sschwarze.\" 38b78a4598Sschwarze.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 39b78a4598Sschwarze.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 40b78a4598Sschwarze.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 41b78a4598Sschwarze.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 42b78a4598Sschwarze.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 43b78a4598Sschwarze.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 44b78a4598Sschwarze.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 45b78a4598Sschwarze.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 46b78a4598Sschwarze.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 47b78a4598Sschwarze.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 48b78a4598Sschwarze.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 49b78a4598Sschwarze.\" OF THE POSSIBILITY OF SUCH DAMAGE. 50b78a4598Sschwarze.\" 5192086ec9Sschwarze.Dd $Mdocdate: June 7 2019 $ 526fcf0eb2Sschwarze.Dt PKCS5_PBKDF2_HMAC 3 536fcf0eb2Sschwarze.Os 546fcf0eb2Sschwarze.Sh NAME 556fcf0eb2Sschwarze.Nm PKCS5_PBKDF2_HMAC , 566fcf0eb2Sschwarze.Nm PKCS5_PBKDF2_HMAC_SHA1 576fcf0eb2Sschwarze.Nd password based derivation routines with salt and iteration count 586fcf0eb2Sschwarze.Sh SYNOPSIS 596fcf0eb2Sschwarze.In openssl/evp.h 606fcf0eb2Sschwarze.Ft int 616fcf0eb2Sschwarze.Fo PKCS5_PBKDF2_HMAC 626fcf0eb2Sschwarze.Fa "const char *pass" 636fcf0eb2Sschwarze.Fa "int passlen" 646fcf0eb2Sschwarze.Fa "const unsigned char *salt" 656fcf0eb2Sschwarze.Fa "int saltlen" 666fcf0eb2Sschwarze.Fa "int iter" 676fcf0eb2Sschwarze.Fa "const EVP_MD *digest" 686fcf0eb2Sschwarze.Fa "int keylen" 696fcf0eb2Sschwarze.Fa "unsigned char *out" 706fcf0eb2Sschwarze.Fc 716fcf0eb2Sschwarze.Ft int 726fcf0eb2Sschwarze.Fo PKCS5_PBKDF2_HMAC_SHA1 736fcf0eb2Sschwarze.Fa "const char *pass" 746fcf0eb2Sschwarze.Fa "int passlen" 756fcf0eb2Sschwarze.Fa "const unsigned char *salt" 766fcf0eb2Sschwarze.Fa "int saltlen" 776fcf0eb2Sschwarze.Fa "int iter" 786fcf0eb2Sschwarze.Fa "int keylen" 796fcf0eb2Sschwarze.Fa "unsigned char *out" 806fcf0eb2Sschwarze.Fc 816fcf0eb2Sschwarze.Sh DESCRIPTION 826fcf0eb2Sschwarze.Fn PKCS5_PBKDF2_HMAC 836fcf0eb2Sschwarzederives a key from a password using a salt and iteration count as 846fcf0eb2Sschwarzespecified in RFC 2898. 856fcf0eb2Sschwarze.Pp 866fcf0eb2Sschwarze.Fa pass 876fcf0eb2Sschwarzeis the password used in the derivation of length 886fcf0eb2Sschwarze.Fa passlen . 896fcf0eb2Sschwarze.Fa pass 906fcf0eb2Sschwarzeis an optional parameter and can be 916fcf0eb2Sschwarze.Dv NULL . 926fcf0eb2SschwarzeIf 936fcf0eb2Sschwarze.Fa passlen 946fcf0eb2Sschwarzeis -1, then the function will calculate the length of 956fcf0eb2Sschwarze.Fa pass 966fcf0eb2Sschwarzeusing 976fcf0eb2Sschwarze.Xr strlen 3 . 986fcf0eb2Sschwarze.Pp 996fcf0eb2Sschwarze.Fa salt 1006fcf0eb2Sschwarzeis the salt used in the derivation of length 1016fcf0eb2Sschwarze.Fa saltlen . 1026fcf0eb2SschwarzeIf the 1036fcf0eb2Sschwarze.Fa salt 1046fcf0eb2Sschwarzeis 1056fcf0eb2Sschwarze.Dv NULL , 1066fcf0eb2Sschwarzethen 1076fcf0eb2Sschwarze.Fa saltlen 1086fcf0eb2Sschwarzemust be 0. 1096fcf0eb2SschwarzeThe function will not attempt to calculate the length of the 1106fcf0eb2Sschwarze.Fa salt 1116fcf0eb2Sschwarzebecause it is not assumed to be NUL terminated. 1126fcf0eb2Sschwarze.Pp 1136fcf0eb2Sschwarze.Fa iter 1146fcf0eb2Sschwarzeis the iteration count and its value should be greater than or equal to 1. 1156fcf0eb2SschwarzeRFC 2898 suggests an iteration count of at least 1000. 1166fcf0eb2SschwarzeAny 1176fcf0eb2Sschwarze.Fa iter 1186fcf0eb2Sschwarzeless than 1 is treated as a single iteration. 1196fcf0eb2Sschwarze.Pp 1206fcf0eb2Sschwarze.Fa digest 1216fcf0eb2Sschwarzeis the message digest function used in the derivation. 1226fcf0eb2SschwarzeValues include any of the EVP_* message digests. 1236fcf0eb2Sschwarze.Fn PKCS5_PBKDF2_HMAC_SHA1 1246fcf0eb2Sschwarzecalls 1256fcf0eb2Sschwarze.Fn PKCS5_PBKDF2_HMAC 1266fcf0eb2Sschwarzewith 1276fcf0eb2Sschwarze.Xr EVP_sha1 3 . 1286fcf0eb2Sschwarze.Pp 1296fcf0eb2SschwarzeThe derived key will be written to 1306fcf0eb2Sschwarze.Fa out . 1316fcf0eb2SschwarzeThe size of the 1326fcf0eb2Sschwarze.Fa out 1336fcf0eb2Sschwarzebuffer is specified via 1346fcf0eb2Sschwarze.Fa keylen . 1356fcf0eb2Sschwarze.Pp 1366fcf0eb2SschwarzeA typical application of this function is to derive keying material for 1376fcf0eb2Sschwarzean encryption algorithm from a password in the 1386fcf0eb2Sschwarze.Fa pass , 1396fcf0eb2Sschwarzea salt in 1406fcf0eb2Sschwarze.Fa salt , 1416fcf0eb2Sschwarzeand an iteration count. 1426fcf0eb2Sschwarze.Pp 1436fcf0eb2SschwarzeIncreasing the 1446fcf0eb2Sschwarze.Fa iter 1456fcf0eb2Sschwarzeparameter slows down the algorithm which makes it harder for an attacker 1466fcf0eb2Sschwarzeto perform a brute force attack using a large number of candidate 1476fcf0eb2Sschwarzepasswords. 1486fcf0eb2Sschwarze.Sh RETURN VALUES 1496fcf0eb2Sschwarze.Fn PKCS5_PBKDF2_HMAC 1506fcf0eb2Sschwarzeand 1516fcf0eb2Sschwarze.Fn PBKCS5_PBKDF2_HMAC_SHA1 1526fcf0eb2Sschwarzereturn 1 on success or 0 on error. 1536fcf0eb2Sschwarze.Sh SEE ALSO 1546fcf0eb2Sschwarze.Xr EVP_BytesToKey 3 , 155*64af7bbfSschwarze.Xr EVP_DigestInit 3 1563fe1df4aSschwarze.Sh HISTORY 1573fe1df4aSschwarze.Fn PKCS5_PBKDF2_HMAC_SHA1 1583fe1df4aSschwarzefirst appeared in OpenSSL 0.9.4 and has been available since 1593fe1df4aSschwarze.Ox 2.6 . 16056929f71Sschwarze.Pp 16156929f71Sschwarze.Fn PKCS5_PBKDF2_HMAC 16256929f71Sschwarzefirst appeared in OpenSSL 1.0.0 and has been available since 16356929f71Sschwarze.Ox 4.9 . 164