]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/EVP_BytesToKey.pod
Deprecate the low level Diffie-Hellman functions.
[thirdparty/openssl.git] / doc / man3 / EVP_BytesToKey.pod
CommitLineData
55e42c93
DSH
1=pod
2
3=head1 NAME
4
d90e74c5 5EVP_BytesToKey - password based encryption routine
55e42c93
DSH
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
aebb9aac
RS
11 int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
12 const unsigned char *salt,
13 const unsigned char *data, int datal, int count,
14 unsigned char *key, unsigned char *iv);
55e42c93
DSH
15
16=head1 DESCRIPTION
17
18EVP_BytesToKey() derives a key and IV from various parameters. B<type> is
19the cipher to derive the key and IV for. B<md> is the message digest to use.
2b4ffc65 20The B<salt> parameter is used as a salt in the derivation: it should point to
55e42c93
DSH
21an 8 byte buffer or NULL if no salt is used. B<data> is a buffer containing
22B<datal> bytes which is used to derive the keying data. B<count> is the
23iteration count to use. The derived key and IV will be written to B<key>
24and B<iv> respectively.
25
26=head1 NOTES
27
28A typical application of this function is to derive keying material for an
29encryption algorithm from a password in the B<data> parameter.
30
31Increasing the B<count> parameter slows down the algorithm which makes it
186bb907 32harder for an attacker to perform a brute force attack using a large number
55e42c93
DSH
33of candidate passwords.
34
35If the total key and IV length is less than the digest length and
36B<MD5> is used then the derivation algorithm is compatible with PKCS#5 v1.5
37otherwise a non standard extension is used to derive the extra data.
38
82c4d793
JW
39Newer applications should use a more modern algorithm such as PBKDF2 as
40defined in PKCS#5v2.1 and provided by PKCS5_PBKDF2_HMAC.
55e42c93
DSH
41
42=head1 KEY DERIVATION ALGORITHM
43
44The key and IV is derived by concatenating D_1, D_2, etc until
45enough data is available for the key and IV. D_i is defined as:
46
1bc74519 47 D_i = HASH^count(D_(i-1) || data || salt)
55e42c93 48
186bb907 49where || denotes concatenation, D_0 is empty, HASH is the digest
55e42c93
DSH
50algorithm in use, HASH^1(data) is simply HASH(data), HASH^2(data)
51is HASH(HASH(data)) and so on.
52
53The initial bytes are used for the key and the subsequent bytes for
54the IV.
55
56=head1 RETURN VALUES
57
5aed1693
RS
58If B<data> is NULL, then EVP_BytesToKey() returns the number of bytes
59needed to store the derived key.
60Otherwise, EVP_BytesToKey() returns the size of the derived key in bytes,
61or 0 on error.
55e42c93
DSH
62
63=head1 SEE ALSO
64
b97fdb57 65L<evp(7)>, L<RAND_bytes(3)>,
9b86974e
RS
66L<PKCS5_PBKDF2_HMAC(3)>,
67L<EVP_EncryptInit(3)>
55e42c93 68
e2f92610
RS
69=head1 COPYRIGHT
70
71Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
72
4746f25a 73Licensed under the Apache License 2.0 (the "License"). You may not use
e2f92610
RS
74this file except in compliance with the License. You can obtain a copy
75in the file LICENSE in the source distribution or at
76L<https://www.openssl.org/source/license.html>.
77
78=cut