EVP_BytesToKey.pod 2.6 KB

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