PKCS12_key_gen_utf8_ex.pod 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. =pod
  2. =head1 NAME
  3. PKCS12_key_gen_asc, PKCS12_key_gen_asc_ex,
  4. PKCS12_key_gen_uni, PKCS12_key_gen_uni_ex,
  5. PKCS12_key_gen_utf8, PKCS12_key_gen_utf8_ex - PKCS#12 Password based key derivation
  6. =head1 SYNOPSIS
  7. #include <openssl/pkcs12.h>
  8. int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
  9. int saltlen, int id, int iter, int n,
  10. unsigned char *out, const EVP_MD *md_type);
  11. int PKCS12_key_gen_asc_ex(const char *pass, int passlen, unsigned char *salt,
  12. int saltlen, int id, int iter, int n,
  13. unsigned char *out, const EVP_MD *md_type,
  14. OSSL_LIB_CTX *ctx, const char *propq);
  15. int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
  16. int saltlen, int id, int iter, int n,
  17. unsigned char *out, const EVP_MD *md_type);
  18. int PKCS12_key_gen_uni_ex(unsigned char *pass, int passlen, unsigned char *salt,
  19. int saltlen, int id, int iter, int n,
  20. unsigned char *out, const EVP_MD *md_type,
  21. OSSL_LIB_CTX *ctx, const char *propq);
  22. int PKCS12_key_gen_utf8(const char *pass, int passlen, unsigned char *salt,
  23. int saltlen, int id, int iter, int n,
  24. unsigned char *out, const EVP_MD *md_type);
  25. int PKCS12_key_gen_utf8_ex(const char *pass, int passlen, unsigned char *salt,
  26. int saltlen, int id, int iter, int n,
  27. unsigned char *out, const EVP_MD *md_type,
  28. OSSL_LIB_CTX *ctx, const char *propq);
  29. =head1 DESCRIPTION
  30. These methods perform a key derivation according to PKCS#12 (RFC7292)
  31. with an input password I<pass> of length I<passlen>, a salt I<salt> of length
  32. I<saltlen>, an iteration count I<iter> and a digest algorithm I<md_type>.
  33. The ID byte I<id> determines how the resulting key is intended to be used:
  34. =over 4
  35. =item *
  36. If ID=1, then the pseudorandom bits being produced are to be used
  37. as key material for performing encryption or decryption.
  38. =item *
  39. If ID=2, then the pseudorandom bits being produced are to be used
  40. as an IV (Initial Value) for encryption or decryption.
  41. =item *
  42. If ID=3, then the pseudorandom bits being produced are to be used
  43. as an integrity key for MACing.
  44. =back
  45. The intended format of the supplied password is determined by the method chosen:
  46. =over 4
  47. =item *
  48. PKCS12_key_gen_asc() and PKCS12_key_gen_asc_ex() expect an ASCII-formatted password.
  49. =item *
  50. PKCS12_key_gen_uni() and PKCS12_key_gen_uni_ex() expect a Unicode-formatted password.
  51. =item *
  52. PKCS12_key_gen_utf8() and PKCS12_key_gen_utf8_ex() expect a UTF-8 encoded password.
  53. =back
  54. I<pass> is the password used in the derivation of length I<passlen>. I<pass>
  55. is an optional parameter and can be NULL. If I<passlen> is -1, then the
  56. function will calculate the length of I<pass> using strlen().
  57. I<salt> is the salt used in the derivation of length I<saltlen>. If the
  58. I<salt> is NULL, then I<saltlen> must be 0. The function will not
  59. attempt to calculate the length of the I<salt> because it is not assumed to
  60. be NULL terminated.
  61. I<iter> is the iteration count and its value should be greater than or
  62. equal to 1. RFC 2898 suggests an iteration count of at least 1000. Any
  63. I<iter> less than 1 is treated as a single iteration.
  64. I<digest> is the message digest function used in the derivation.
  65. The derived key will be written to I<out>. The size of the I<out> buffer
  66. is specified via I<n>.
  67. Functions ending in _ex() allow for a library context I<ctx> and property query
  68. I<propq> to be used to select algorithm implementations.
  69. =head1 NOTES
  70. A typical application of this function is to derive keying material for an
  71. encryption algorithm from a password in the I<pass>, a salt in I<salt>,
  72. and an iteration count.
  73. Increasing the I<iter> parameter slows down the algorithm which makes it
  74. harder for an attacker to perform a brute force attack using a large number
  75. of candidate passwords.
  76. =head1 RETURN VALUES
  77. Returns 1 on success or 0 on error.
  78. =head1 CONFORMING TO
  79. IETF RFC 7292 (L<https://tools.ietf.org/html/rfc7292>)
  80. =head1 SEE ALSO
  81. L<PKCS12_create_ex(3)>,
  82. L<PKCS12_pbe_crypt_ex(3)>,
  83. L<passphrase-encoding(7)>
  84. =head1 HISTORY
  85. PKCS12_key_gen_asc_ex(), PKCS12_key_gen_uni_ex() and PKCS12_key_gen_utf8_ex()
  86. were added in OpenSSL 3.0.
  87. =head1 COPYRIGHT
  88. Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
  89. Licensed under the Apache License 2.0 (the "License"). You may not use
  90. this file except in compliance with the License. You can obtain a copy
  91. in the file LICENSE in the source distribution or at
  92. L<https://www.openssl.org/source/license.html>.
  93. =cut