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