EVP_BytesToKey.pod 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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> paramter 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 peform 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 more standard algorithms such as PKCS#5
  28. v2.0 for key derivation.
  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 concatentaion, 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. EVP_BytesToKey() returns the size of the derived key in bytes.
  40. =head1 SEE ALSO
  41. L<evp(3)|evp(3)>, L<rand(3)|rand(3)>,
  42. L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>
  43. =head1 HISTORY
  44. =cut