|
Packit |
c4476c |
=pod
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
=head1 NAME
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
EVP_BytesToKey - password based encryption routine
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
=head1 SYNOPSIS
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
#include <openssl/evp.h>
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
|
|
Packit |
c4476c |
const unsigned char *salt,
|
|
Packit |
c4476c |
const unsigned char *data, int datal, int count,
|
|
Packit |
c4476c |
unsigned char *key, unsigned char *iv);
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
=head1 DESCRIPTION
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
EVP_BytesToKey() derives a key and IV from various parameters. B<type> is
|
|
Packit |
c4476c |
the cipher to derive the key and IV for. B<md> is the message digest to use.
|
|
Packit |
c4476c |
The B<salt> parameter is used as a salt in the derivation: it should point to
|
|
Packit |
c4476c |
an 8 byte buffer or NULL if no salt is used. B<data> is a buffer containing
|
|
Packit |
c4476c |
B<datal> bytes which is used to derive the keying data. B<count> is the
|
|
Packit |
c4476c |
iteration count to use. The derived key and IV will be written to B<key>
|
|
Packit |
c4476c |
and B<iv> respectively.
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
=head1 NOTES
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
A typical application of this function is to derive keying material for an
|
|
Packit |
c4476c |
encryption algorithm from a password in the B<data> parameter.
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
Increasing the B<count> parameter slows down the algorithm which makes it
|
|
Packit |
c4476c |
harder for an attacker to perform a brute force attack using a large number
|
|
Packit |
c4476c |
of candidate passwords.
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
If the total key and IV length is less than the digest length and
|
|
Packit |
c4476c |
B<MD5> is used then the derivation algorithm is compatible with PKCS#5 v1.5
|
|
Packit |
c4476c |
otherwise a non standard extension is used to derive the extra data.
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
Newer applications should use a more modern algorithm such as PBKDF2 as
|
|
Packit |
c4476c |
defined in PKCS#5v2.1 and provided by PKCS5_PBKDF2_HMAC.
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
=head1 KEY DERIVATION ALGORITHM
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
The key and IV is derived by concatenating D_1, D_2, etc until
|
|
Packit |
c4476c |
enough data is available for the key and IV. D_i is defined as:
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
D_i = HASH^count(D_(i-1) || data || salt)
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
where || denotes concatenation, D_0 is empty, HASH is the digest
|
|
Packit |
c4476c |
algorithm in use, HASH^1(data) is simply HASH(data), HASH^2(data)
|
|
Packit |
c4476c |
is HASH(HASH(data)) and so on.
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
The initial bytes are used for the key and the subsequent bytes for
|
|
Packit |
c4476c |
the IV.
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
=head1 RETURN VALUES
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
If B<data> is NULL, then EVP_BytesToKey() returns the number of bytes
|
|
Packit |
c4476c |
needed to store the derived key.
|
|
Packit |
c4476c |
Otherwise, EVP_BytesToKey() returns the size of the derived key in bytes,
|
|
Packit |
c4476c |
or 0 on error.
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
=head1 SEE ALSO
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
L<evp(7)>, L<RAND_bytes(3)>,
|
|
Packit |
c4476c |
L<PKCS5_PBKDF2_HMAC(3)>,
|
|
Packit |
c4476c |
L<EVP_EncryptInit(3)>
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
=head1 COPYRIGHT
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
Licensed under the OpenSSL license (the "License"). You may not use
|
|
Packit |
c4476c |
this file except in compliance with the License. You can obtain a copy
|
|
Packit |
c4476c |
in the file LICENSE in the source distribution or at
|
|
Packit |
c4476c |
L<https://www.openssl.org/source/license.html>.
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
=cut
|