PKCS5_PBE_keyivgen.3ossl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "PKCS5_PBE_KEYIVGEN 3ossl"
  58. .TH PKCS5_PBE_KEYIVGEN 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. PKCS5_PBE_keyivgen, PKCS5_PBE_keyivgen_ex, PKCS5_pbe2_set, PKCS5_pbe2_set_iv,
  65. PKCS5_pbe2_set_iv_ex, PKCS5_pbe_set, PKCS5_pbe_set_ex, PKCS5_pbe2_set_scrypt,
  66. PKCS5_pbe_set0_algor, PKCS5_pbe_set0_algor_ex,
  67. PKCS5_v2_PBE_keyivgen, PKCS5_v2_PBE_keyivgen_ex,
  68. PKCS5_v2_scrypt_keyivgen, PKCS5_v2_scrypt_keyivgen_ex,
  69. PKCS5_pbkdf2_set, PKCS5_pbkdf2_set_ex, EVP_PBE_scrypt, EVP_PBE_scrypt_ex
  70. \&\- PKCS#5 Password based encryption routines
  71. .SH SYNOPSIS
  72. .IX Header "SYNOPSIS"
  73. .Vb 1
  74. \& #include <openssl/evp.h>
  75. \&
  76. \& int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
  77. \& ASN1_TYPE *param, const EVP_CIPHER *cipher,
  78. \& const EVP_MD *md, int en_de);
  79. \& int PKCS5_PBE_keyivgen_ex(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
  80. \& ASN1_TYPE *param, const EVP_CIPHER *cipher,
  81. \& const EVP_MD *md, int en_de, OSSL_LIB_CTX *libctx,
  82. \& const char *propq);
  83. \& int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
  84. \& ASN1_TYPE *param, const EVP_CIPHER *cipher,
  85. \& const EVP_MD *md, int en_de);
  86. \& int PKCS5_v2_PBE_keyivgen_ex(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
  87. \& ASN1_TYPE *param, const EVP_CIPHER *cipher,
  88. \& const EVP_MD *md, int en_de,
  89. \& OSSL_LIB_CTX *libctx, const char *propq);
  90. \& int EVP_PBE_scrypt(const char *pass, size_t passlen,
  91. \& const unsigned char *salt, size_t saltlen,
  92. \& uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem,
  93. \& unsigned char *key, size_t keylen);
  94. \& int EVP_PBE_scrypt_ex(const char *pass, size_t passlen,
  95. \& const unsigned char *salt, size_t saltlen,
  96. \& uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem,
  97. \& unsigned char *key, size_t keylen,
  98. \& OSSL_LIB_CTX *ctx, const char *propq);
  99. \& int PKCS5_v2_scrypt_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass,
  100. \& int passlen, ASN1_TYPE *param,
  101. \& const EVP_CIPHER *c, const EVP_MD *md, int en_de);
  102. \& int PKCS5_v2_scrypt_keyivgen_ex(EVP_CIPHER_CTX *ctx, const char *pass,
  103. \& int passlen, ASN1_TYPE *param,
  104. \& const EVP_CIPHER *c, const EVP_MD *md, int en_de,
  105. \& OSSL_LIB_CTX *libctx, const char *propq);
  106. \&
  107. \& #include <openssl/x509.h>
  108. \&
  109. \& int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
  110. \& const unsigned char *salt, int saltlen);
  111. \& int PKCS5_pbe_set0_algor_ex(X509_ALGOR *algor, int alg, int iter,
  112. \& const unsigned char *salt, int saltlen,
  113. \& OSSL_LIB_CTX *libctx);
  114. \&
  115. \& X509_ALGOR *PKCS5_pbe_set(int alg, int iter,
  116. \& const unsigned char *salt, int saltlen);
  117. \& X509_ALGOR *PKCS5_pbe_set_ex(int alg, int iter,
  118. \& const unsigned char *salt, int saltlen,
  119. \& OSSL_LIB_CTX *libctx);
  120. \&
  121. \& X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
  122. \& unsigned char *salt, int saltlen);
  123. \& X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter,
  124. \& unsigned char *salt, int saltlen,
  125. \& unsigned char *aiv, int prf_nid);
  126. \& X509_ALGOR *PKCS5_pbe2_set_iv_ex(const EVP_CIPHER *cipher, int iter,
  127. \& unsigned char *salt, int saltlen,
  128. \& unsigned char *aiv, int prf_nid,
  129. \& OSSL_LIB_CTX *libctx);
  130. \& X509_ALGOR *PKCS5_pbe2_set_scrypt(const EVP_CIPHER *cipher,
  131. \& const unsigned char *salt, int saltlen,
  132. \& unsigned char *aiv, uint64_t N, uint64_t r,
  133. \& uint64_t p);
  134. \&
  135. \& X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen,
  136. \& int prf_nid, int keylen);
  137. \& X509_ALGOR *PKCS5_pbkdf2_set_ex(int iter, unsigned char *salt, int saltlen,
  138. \& int prf_nid, int keylen,
  139. \& OSSL_LIB_CTX *libctx);
  140. .Ve
  141. .SH DESCRIPTION
  142. .IX Header "DESCRIPTION"
  143. .SS "Key Derivation"
  144. .IX Subsection "Key Derivation"
  145. \&\fBPKCS5_PBE_keyivgen()\fR and \fBPKCS5_PBE_keyivgen_ex()\fR take a password \fIpass\fR of
  146. length \fIpasslen\fR, parameters \fIparam\fR and a message digest function \fImd_type\fR
  147. and performs a key derivation according to PKCS#5 PBES1. The resulting key is
  148. then used to initialise the cipher context \fIctx\fR with a cipher \fIcipher\fR for
  149. encryption (\fIen_de\fR=1) or decryption (\fIen_de\fR=0).
  150. .PP
  151. \&\fIpass\fR is an optional parameter and can be NULL. If \fIpasslen\fR is \-1, then the
  152. function will calculate the length of \fIpass\fR using \fBstrlen()\fR.
  153. .PP
  154. \&\fBPKCS5_v2_PBE_keyivgen()\fR and \fBPKCS5_v2_PBE_keyivgen_ex()\fR are similar to the above
  155. but instead use PKCS#5 PBES2 as the encryption algorithm using the supplied
  156. parameters.
  157. .PP
  158. \&\fBPKCS5_v2_scrypt_keyivgen()\fR and \fBPKCS5_v2_scrypt_keyivgen_ex()\fR use SCRYPT as the
  159. key derivation part of the encryption algorithm.
  160. .PP
  161. \&\fIsalt\fR is the salt used in the derivation of length \fIsaltlen\fR. If the
  162. \&\fIsalt\fR is NULL, then \fIsaltlen\fR must be 0. The function will not
  163. attempt to calculate the length of the \fIsalt\fR because it is not assumed to
  164. be NULL terminated.
  165. .PP
  166. \&\fIiter\fR is the iteration count and its value should be greater than or
  167. equal to 1. RFC 2898 suggests an iteration count of at least 1000. Any
  168. \&\fIiter\fR less than 1 is treated as a single iteration.
  169. .PP
  170. \&\fIdigest\fR is the message digest function used in the derivation.
  171. .PP
  172. Functions ending in \fB_ex()\fR take optional parameters \fIlibctx\fR and \fIpropq\fR which
  173. are used to select appropriate algorithm implementations.
  174. .SS "Algorithm Identifier Creation"
  175. .IX Subsection "Algorithm Identifier Creation"
  176. \&\fBPKCS5_pbe_set()\fR, \fBPKCS5_pbe_set_ex()\fR, \fBPKCS5_pbe2_set()\fR, \fBPKCS5_pbe2_set_iv()\fR,
  177. \&\fBPKCS5_pbe2_set_iv_ex()\fR and \fBPKCS5_pbe2_set_scrypt()\fR generate an \fBX509_ALGOR\fR
  178. object which represents an AlgorithmIdentifier containing the algorithm OID and
  179. associated parameters for the PBE algorithm.
  180. .PP
  181. \&\fBPKCS5_pbkdf2_set()\fR and \fBPKCS5_pbkdf2_set_ex()\fR generate an \fBX509_ALGOR\fR
  182. object which represents an AlgorithmIdentifier containing the algorithm OID and
  183. associated parameters for the PBKDF2 algorithm.
  184. .PP
  185. \&\fBPKCS5_pbe_set0_algor()\fR and \fBPKCS5_pbe_set0_algor_ex()\fR set the PBE algorithm OID and
  186. parameters into the supplied \fBX509_ALGOR\fR.
  187. .PP
  188. If \fIsalt\fR is NULL, then \fIsaltlen\fR specifies the size in bytes of the random salt to
  189. generate. If \fIsaltlen\fR is 0 then a default size is used.
  190. For PBE related functions such as \fBPKCS5_pbe_set_ex()\fR the default salt length is 8 bytes.
  191. For PBE2 related functions that use PBKDF2 such as \fBPKCS5_pbkdf2_set()\fR,
  192. \&\fBPKCS5_pbe2_set_scrypt()\fR and \fBPKCS5_pbe2_set()\fR the default salt length is 16 bytes.
  193. .SH NOTES
  194. .IX Header "NOTES"
  195. The *\fB_keyivgen()\fR functions are typically used in PKCS#12 to encrypt objects.
  196. .PP
  197. These functions make no assumption regarding the given password.
  198. It will simply be treated as a byte sequence.
  199. .SH "RETURN VALUES"
  200. .IX Header "RETURN VALUES"
  201. \&\fBPKCS5_PBE_keyivgen()\fR, \fBPKCS5_v2_PBE_keyivgen()\fR,
  202. \&\fBPKCS5_v2_PBE_keyivgen_ex()\fR, \fBPKCS5_v2_scrypt_keyivgen()\fR,
  203. \&\fBPKCS5_v2_scrypt_keyivgen_ex()\fR, \fBPKCS5_pbe_set0_algor()\fR and
  204. \&\fBPKCS5_pbe_set0_algor_ex()\fR return 1 for success and 0 if an error occurs.
  205. .PP
  206. \&\fBPKCS5_pbe_set()\fR, \fBPKCS5_pbe_set_ex()\fR, \fBPKCS5_pbe2_set()\fR, \fBPKCS5_pbe2_set_iv()\fR,
  207. \&\fBPKCS5_pbe2_set_iv_ex()\fR, \fBPKCS5_pbe2_set_scrypt()\fR,
  208. \&\fBPKCS5_pbkdf2_set()\fR and \fBPKCS5_pbkdf2_set_ex()\fR return an \fBX509_ALGOR\fR object or
  209. NULL if an error occurs.
  210. .SH "CONFORMING TO"
  211. .IX Header "CONFORMING TO"
  212. IETF RFC 8018 (<https://tools.ietf.org/html/rfc8018>)
  213. .SH "SEE ALSO"
  214. .IX Header "SEE ALSO"
  215. \&\fBEVP_PBE_CipherInit_ex\fR\|(3),
  216. \&\fBPKCS12_pbe_crypt_ex\fR\|(3),
  217. \&\fBpassphrase\-encoding\fR\|(7)
  218. .SH HISTORY
  219. .IX Header "HISTORY"
  220. \&\fBPKCS5_v2_PBE_keyivgen_ex()\fR, \fBEVP_PBE_scrypt_ex()\fR, \fBPKCS5_v2_scrypt_keyivgen_ex()\fR,
  221. \&\fBPKCS5_pbe_set0_algor_ex()\fR, \fBPKCS5_pbe_set_ex()\fR, \fBPKCS5_pbe2_set_iv_ex()\fR and
  222. \&\fBPKCS5_pbkdf2_set_ex()\fR were added in OpenSSL 3.0.
  223. .PP
  224. From OpenSSL 3.0 the PBKDF1 algorithm used in \fBPKCS5_PBE_keyivgen()\fR and
  225. \&\fBPKCS5_PBE_keyivgen_ex()\fR has been moved to the legacy provider as an EVP_KDF.
  226. .PP
  227. In OpenSSL 3.2 the default salt length changed from 8 bytes to 16 bytes for PBE2
  228. related functions such as \fBPKCS5_pbe2_set()\fR.
  229. This is required for PBKDF2 FIPS compliance.
  230. .SH COPYRIGHT
  231. .IX Header "COPYRIGHT"
  232. Copyright 2021\-2023 The OpenSSL Project Authors. All Rights Reserved.
  233. .PP
  234. Licensed under the Apache License 2.0 (the "License"). You may not use
  235. this file except in compliance with the License. You can obtain a copy
  236. in the file LICENSE in the source distribution or at
  237. <https://www.openssl.org/source/license.html>.