provider-rand.7ossl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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 "PROVIDER-RAND 7ossl"
  58. .TH PROVIDER-RAND 7ossl 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. provider\-rand \- The random number generation library <\-> provider
  65. functions
  66. .SH SYNOPSIS
  67. .IX Header "SYNOPSIS"
  68. .Vb 2
  69. \& #include <openssl/core_dispatch.h>
  70. \& #include <openssl/core_names.h>
  71. \&
  72. \& /*
  73. \& * None of these are actual functions, but are displayed like this for
  74. \& * the function signatures for functions that are offered as function
  75. \& * pointers in OSSL_DISPATCH arrays.
  76. \& */
  77. \&
  78. \& /* Context management */
  79. \& void *OSSL_FUNC_rand_newctx(void *provctx, void *parent,
  80. \& const OSSL_DISPATCH *parent_calls);
  81. \& void OSSL_FUNC_rand_freectx(void *ctx);
  82. \&
  83. \& /* Random number generator functions: NIST */
  84. \& int OSSL_FUNC_rand_instantiate(void *ctx, unsigned int strength,
  85. \& int prediction_resistance,
  86. \& const unsigned char *pstr, size_t pstr_len,
  87. \& const OSSL_PARAM params[]);
  88. \& int OSSL_FUNC_rand_uninstantiate(void *ctx);
  89. \& int OSSL_FUNC_rand_generate(void *ctx, unsigned char *out, size_t outlen,
  90. \& unsigned int strength, int prediction_resistance,
  91. \& const unsigned char *addin, size_t addin_len);
  92. \& int OSSL_FUNC_rand_reseed(void *ctx, int prediction_resistance,
  93. \& const unsigned char *ent, size_t ent_len,
  94. \& const unsigned char *addin, size_t addin_len);
  95. \&
  96. \& /* Random number generator functions: additional */
  97. \& size_t OSSL_FUNC_rand_nonce(void *ctx, unsigned char *out, size_t outlen,
  98. \& int strength, size_t min_noncelen,
  99. \& size_t max_noncelen);
  100. \& size_t OSSL_FUNC_rand_get_seed(void *ctx, unsigned char **buffer,
  101. \& int entropy, size_t min_len, size_t max_len,
  102. \& int prediction_resistance,
  103. \& const unsigned char *adin, size_t adin_len);
  104. \& void OSSL_FUNC_rand_clear_seed(void *ctx, unsigned char *buffer, size_t b_len);
  105. \& int OSSL_FUNC_rand_verify_zeroization(void *ctx);
  106. \&
  107. \& /* Context Locking */
  108. \& int OSSL_FUNC_rand_enable_locking(void *ctx);
  109. \& int OSSL_FUNC_rand_lock(void *ctx);
  110. \& void OSSL_FUNC_rand_unlock(void *ctx);
  111. \&
  112. \& /* RAND parameter descriptors */
  113. \& const OSSL_PARAM *OSSL_FUNC_rand_gettable_params(void *provctx);
  114. \& const OSSL_PARAM *OSSL_FUNC_rand_gettable_ctx_params(void *ctx, void *provctx);
  115. \& const OSSL_PARAM *OSSL_FUNC_rand_settable_ctx_params(void *ctx, void *provctx);
  116. \&
  117. \& /* RAND parameters */
  118. \& int OSSL_FUNC_rand_get_params(OSSL_PARAM params[]);
  119. \& int OSSL_FUNC_rand_get_ctx_params(void *ctx, OSSL_PARAM params[]);
  120. \& int OSSL_FUNC_rand_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
  121. .Ve
  122. .SH DESCRIPTION
  123. .IX Header "DESCRIPTION"
  124. This documentation is primarily aimed at provider authors. See \fBprovider\fR\|(7)
  125. for further information.
  126. .PP
  127. The RAND operation enables providers to implement random number generation
  128. algorithms and random number sources and make
  129. them available to applications via the API function \fBEVP_RAND\fR\|(3).
  130. .SS "Context Management Functions"
  131. .IX Subsection "Context Management Functions"
  132. \&\fBOSSL_FUNC_rand_newctx()\fR should create and return a pointer to a provider side
  133. structure for holding context information during a rand operation.
  134. A pointer to this context will be passed back in a number of the other rand
  135. operation function calls.
  136. The parameter \fIprovctx\fR is the provider context generated during provider
  137. initialisation (see \fBprovider\fR\|(7)).
  138. The parameter \fIparent\fR specifies another rand instance to be used for
  139. seeding purposes. If NULL and the specific instance supports it, the
  140. operating system will be used for seeding.
  141. The parameter \fIparent_calls\fR points to the dispatch table for \fIparent\fR.
  142. Thus, the parent need not be from the same provider as the new instance.
  143. .PP
  144. \&\fBOSSL_FUNC_rand_freectx()\fR is passed a pointer to the provider side rand context in
  145. the \fImctx\fR parameter.
  146. If it receives NULL as \fIctx\fR value, it should not do anything other than
  147. return.
  148. This function should free any resources associated with that context.
  149. .SS "Random Number Generator Functions: NIST"
  150. .IX Subsection "Random Number Generator Functions: NIST"
  151. These functions correspond to those defined in NIST SP 800\-90A and SP 800\-90C.
  152. .PP
  153. \&\fBOSSL_FUNC_rand_instantiate()\fR is used to instantiate the DRBG \fIctx\fR at a requested
  154. security \fIstrength\fR. In addition, \fIprediction_resistance\fR can be requested.
  155. Additional input \fIaddin\fR of length \fIaddin_len\fR bytes can optionally
  156. be provided. The parameters specified in \fIparams\fR configure the DRBG and these
  157. should be processed before instantiation.
  158. .PP
  159. \&\fBOSSL_FUNC_rand_uninstantiate()\fR is used to uninstantiate the DRBG \fIctx\fR. After being
  160. uninstantiated, a DRBG is unable to produce output until it is instantiated
  161. anew.
  162. .PP
  163. \&\fBOSSL_FUNC_rand_generate()\fR is used to generate random bytes from the DRBG \fIctx\fR.
  164. It will generate \fIoutlen\fR bytes placing them into the buffer pointed to by
  165. \&\fIout\fR. The generated bytes will meet the specified security \fIstrength\fR and,
  166. if \fIprediction_resistance\fR is true, the bytes will be produced after reseeding
  167. from a live entropy source. Additional input \fIaddin\fR of length \fIaddin_len\fR
  168. bytes can optionally be provided.
  169. .SS "Random Number Generator Functions: Additional"
  170. .IX Subsection "Random Number Generator Functions: Additional"
  171. \&\fBOSSL_FUNC_rand_nonce()\fR is used to generate a nonce of the given \fIstrength\fR with a
  172. length from \fImin_noncelen\fR to \fImax_noncelen\fR. If the output buffer \fIout\fR is
  173. NULL, the length of the nonce should be returned.
  174. .PP
  175. \&\fBOSSL_FUNC_rand_get_seed()\fR is used by deterministic generators to obtain their
  176. seeding material from their parent. The seed bytes will meet the specified
  177. security level of \fIentropy\fR bits and there will be between \fImin_len\fR
  178. and \fImax_len\fR inclusive bytes in total. If \fIprediction_resistance\fR is
  179. true, the bytes will be produced from a live entropy source. Additional
  180. input \fIaddin\fR of length \fIaddin_len\fR bytes can optionally be provided.
  181. A pointer to the seed material is returned in \fI*buffer\fR and this must be
  182. freed by a later call to \fBOSSL_FUNC_rand_clear_seed()\fR.
  183. .PP
  184. \&\fBOSSL_FUNC_rand_clear_seed()\fR frees a seed \fIbuffer\fR of length \fIb_len\fR bytes
  185. which was previously allocated by \fBOSSL_FUNC_rand_get_seed()\fR.
  186. .PP
  187. \&\fBOSSL_FUNC_rand_verify_zeroization()\fR is used to determine if the internal state of the
  188. DRBG is zero. This capability is mandated by NIST as part of the self
  189. tests, it is unlikely to be useful in other circumstances.
  190. .SS "Context Locking"
  191. .IX Subsection "Context Locking"
  192. When DRBGs are used by multiple threads, there must be locking employed to
  193. ensure their proper operation. Because locking introduces an overhead, it
  194. is disabled by default.
  195. .PP
  196. \&\fBOSSL_FUNC_rand_enable_locking()\fR allows locking to be turned on for a DRBG and all of
  197. its parent DRBGs. From this call onwards, the DRBG can be used in a thread
  198. safe manner.
  199. .PP
  200. \&\fBOSSL_FUNC_rand_lock()\fR is used to lock a DRBG. Once locked, exclusive access
  201. is guaranteed.
  202. .PP
  203. \&\fBOSSL_FUNC_rand_unlock()\fR is used to unlock a DRBG.
  204. .SS "Rand Parameters"
  205. .IX Subsection "Rand Parameters"
  206. See \fBOSSL_PARAM\fR\|(3) for further details on the parameters structure used by
  207. these functions.
  208. .PP
  209. \&\fBOSSL_FUNC_rand_get_params()\fR gets details of parameter values associated with the
  210. provider algorithm and stores them in \fIparams\fR.
  211. .PP
  212. \&\fBOSSL_FUNC_rand_set_ctx_params()\fR sets rand parameters associated with the given
  213. provider side rand context \fIctx\fR to \fIparams\fR.
  214. Any parameter settings are additional to any that were previously set.
  215. Passing NULL for \fIparams\fR should return true.
  216. .PP
  217. \&\fBOSSL_FUNC_rand_get_ctx_params()\fR gets details of currently set parameter values
  218. associated with the given provider side rand context \fIctx\fR and stores them
  219. in \fIparams\fR.
  220. Passing NULL for \fIparams\fR should return true.
  221. .PP
  222. \&\fBOSSL_FUNC_rand_gettable_params()\fR, \fBOSSL_FUNC_rand_gettable_ctx_params()\fR,
  223. and \fBOSSL_FUNC_rand_settable_ctx_params()\fR all return constant \fBOSSL_PARAM\fR\|(3)
  224. arrays as descriptors of the parameters that \fBOSSL_FUNC_rand_get_params()\fR,
  225. \&\fBOSSL_FUNC_rand_get_ctx_params()\fR, and \fBOSSL_FUNC_rand_set_ctx_params()\fR
  226. can handle, respectively. \fBOSSL_FUNC_rand_gettable_ctx_params()\fR
  227. and \fBOSSL_FUNC_rand_settable_ctx_params()\fR will return the parameters
  228. associated with the provider side context \fIctx\fR in its current state
  229. if it is not NULL. Otherwise, they return the parameters associated
  230. with the provider side algorithm \fIprovctx\fR.
  231. .PP
  232. Parameters currently recognised by built-in rands are as follows. Not all
  233. parameters are relevant to, or are understood by all rands:
  234. .IP """state"" (\fBOSSL_RAND_PARAM_STATE\fR) <integer>" 4
  235. .IX Item """state"" (OSSL_RAND_PARAM_STATE) <integer>"
  236. Returns the state of the random number generator.
  237. .IP """strength"" (\fBOSSL_RAND_PARAM_STRENGTH\fR) <unsigned integer>" 4
  238. .IX Item """strength"" (OSSL_RAND_PARAM_STRENGTH) <unsigned integer>"
  239. Returns the bit strength of the random number generator.
  240. .IP """fips-indicator"" (\fBOSSL_RAND_PARAM_FIPS_APPROVED_INDICATOR\fR) <integer>" 4
  241. .IX Item """fips-indicator"" (OSSL_RAND_PARAM_FIPS_APPROVED_INDICATOR) <integer>"
  242. A getter that returns 1 if the operation is FIPS approved, or 0 otherwise.
  243. This option is used by the OpenSSL FIPS provider and is not supported
  244. by all EVP_RAND sources.
  245. .PP
  246. For rands that are also deterministic random bit generators (DRBGs), these
  247. additional parameters are recognised. Not all
  248. parameters are relevant to, or are understood by all DRBG rands:
  249. .IP """reseed_requests"" (\fBOSSL_DRBG_PARAM_RESEED_REQUESTS\fR) <unsigned integer>" 4
  250. .IX Item """reseed_requests"" (OSSL_DRBG_PARAM_RESEED_REQUESTS) <unsigned integer>"
  251. Reads or set the number of generate requests before reseeding the
  252. associated RAND ctx.
  253. .IP """reseed_time_interval"" (\fBOSSL_DRBG_PARAM_RESEED_TIME_INTERVAL\fR) <integer>" 4
  254. .IX Item """reseed_time_interval"" (OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL) <integer>"
  255. Reads or set the number of elapsed seconds before reseeding the
  256. associated RAND ctx.
  257. .IP """max_request"" (\fBOSSL_DRBG_PARAM_RESEED_REQUESTS\fR) <unsigned integer>" 4
  258. .IX Item """max_request"" (OSSL_DRBG_PARAM_RESEED_REQUESTS) <unsigned integer>"
  259. Specifies the maximum number of bytes that can be generated in a single
  260. call to OSSL_FUNC_rand_generate.
  261. .IP """min_entropylen"" (\fBOSSL_DRBG_PARAM_MIN_ENTROPYLEN\fR) <unsigned integer>" 4
  262. .IX Item """min_entropylen"" (OSSL_DRBG_PARAM_MIN_ENTROPYLEN) <unsigned integer>"
  263. .PD 0
  264. .IP """max_entropylen"" (\fBOSSL_DRBG_PARAM_MAX_ENTROPYLEN\fR) <unsigned integer>" 4
  265. .IX Item """max_entropylen"" (OSSL_DRBG_PARAM_MAX_ENTROPYLEN) <unsigned integer>"
  266. .PD
  267. Specify the minimum and maximum number of bytes of random material that
  268. can be used to seed the DRBG.
  269. .IP """min_noncelen"" (\fBOSSL_DRBG_PARAM_MIN_NONCELEN\fR) <unsigned integer>" 4
  270. .IX Item """min_noncelen"" (OSSL_DRBG_PARAM_MIN_NONCELEN) <unsigned integer>"
  271. .PD 0
  272. .IP """max_noncelen"" (\fBOSSL_DRBG_PARAM_MAX_NONCELEN\fR) <unsigned integer>" 4
  273. .IX Item """max_noncelen"" (OSSL_DRBG_PARAM_MAX_NONCELEN) <unsigned integer>"
  274. .PD
  275. Specify the minimum and maximum number of bytes of nonce that can be used to
  276. instantiate the DRBG.
  277. .IP """max_perslen"" (\fBOSSL_DRBG_PARAM_MAX_PERSLEN\fR) <unsigned integer>" 4
  278. .IX Item """max_perslen"" (OSSL_DRBG_PARAM_MAX_PERSLEN) <unsigned integer>"
  279. .PD 0
  280. .IP """max_adinlen"" (\fBOSSL_DRBG_PARAM_MAX_ADINLEN\fR) <unsigned integer>" 4
  281. .IX Item """max_adinlen"" (OSSL_DRBG_PARAM_MAX_ADINLEN) <unsigned integer>"
  282. .PD
  283. Specify the minimum and maximum number of bytes of personalisation string
  284. that can be used with the DRBG.
  285. .IP """reseed_counter"" (\fBOSSL_DRBG_PARAM_RESEED_COUNTER\fR) <unsigned integer>" 4
  286. .IX Item """reseed_counter"" (OSSL_DRBG_PARAM_RESEED_COUNTER) <unsigned integer>"
  287. Specifies the number of times the DRBG has been seeded or reseeded.
  288. .IP """digest"" (\fBOSSL_DRBG_PARAM_DIGEST\fR) <UTF8 string>" 4
  289. .IX Item """digest"" (OSSL_DRBG_PARAM_DIGEST) <UTF8 string>"
  290. .PD 0
  291. .IP """cipher"" (\fBOSSL_DRBG_PARAM_CIPHER\fR) <UTF8 string>" 4
  292. .IX Item """cipher"" (OSSL_DRBG_PARAM_CIPHER) <UTF8 string>"
  293. .IP """mac"" (\fBOSSL_DRBG_PARAM_MAC\fR) <UTF8 string>" 4
  294. .IX Item """mac"" (OSSL_DRBG_PARAM_MAC) <UTF8 string>"
  295. .PD
  296. Sets the name of the underlying cipher, digest or MAC to be used.
  297. It must name a suitable algorithm for the DRBG that's being used.
  298. .IP """properties"" (\fBOSSL_DRBG_PARAM_PROPERTIES\fR) <UTF8 string>" 4
  299. .IX Item """properties"" (OSSL_DRBG_PARAM_PROPERTIES) <UTF8 string>"
  300. Sets the properties to be queried when trying to fetch an underlying algorithm.
  301. This must be given together with the algorithm naming parameter to be
  302. considered valid.
  303. .PP
  304. The OpenSSL FIPS provider also supports the following parameters:
  305. .IP """fips-indicator"" (\fBOSSL_DRBG_PARAM_FIPS_APPROVED_INDICATOR\fR) <integer>" 4
  306. .IX Item """fips-indicator"" (OSSL_DRBG_PARAM_FIPS_APPROVED_INDICATOR) <integer>"
  307. A getter that returns 1 if the operation is FIPS approved, or 0 otherwise.
  308. This may be used after calling \fBOSSL_FUNC_rand_generate()\fR. It may
  309. return 0 if the "digest-check" is set to 0.
  310. .IP """digest-check"" (\fBOSSL_DRBG_PARAM_FIPS_DIGEST_CHECK\fR) <integer>" 4
  311. .IX Item """digest-check"" (OSSL_DRBG_PARAM_FIPS_DIGEST_CHECK) <integer>"
  312. If required this parameter should be set before the digest is set.
  313. The default value of 1 causes an error when the digest is set if the digest is
  314. not FIPS approved (e.g. truncated digests). Setting this to 0 will ignore
  315. the error and set the approved "fips-indicator" to 0.
  316. This option breaks FIPS compliance if it causes the approved "fips-indicator"
  317. to return 0.
  318. .SH "RETURN VALUES"
  319. .IX Header "RETURN VALUES"
  320. \&\fBOSSL_FUNC_rand_newctx()\fR should return the newly created
  321. provider side rand context, or NULL on failure.
  322. .PP
  323. \&\fBOSSL_FUNC_rand_gettable_params()\fR, \fBOSSL_FUNC_rand_gettable_ctx_params()\fR and
  324. \&\fBOSSL_FUNC_rand_settable_ctx_params()\fR should return a constant \fBOSSL_PARAM\fR\|(3)
  325. array, or NULL if none is offered.
  326. .PP
  327. \&\fBOSSL_FUNC_rand_nonce()\fR returns the size of the generated nonce, or 0 on error.
  328. .PP
  329. \&\fBOSSL_FUNC_rand_get_seed()\fR returns the size of the generated seed, or 0 on
  330. error.
  331. .PP
  332. All of the remaining functions should return 1 for success or 0 on error.
  333. .SH NOTES
  334. .IX Header "NOTES"
  335. The RAND life-cycle is described in \fBlife_cycle\-rand\fR\|(7). Providers should
  336. ensure that the various transitions listed there are supported. At some point
  337. the EVP layer will begin enforcing the listed transitions.
  338. .SH "SEE ALSO"
  339. .IX Header "SEE ALSO"
  340. \&\fBprovider\fR\|(7),
  341. \&\fBRAND\fR\|(7),
  342. \&\fBEVP_RAND\fR\|(7),
  343. \&\fBlife_cycle\-rand\fR\|(7),
  344. \&\fBEVP_RAND\fR\|(3)
  345. .SH HISTORY
  346. .IX Header "HISTORY"
  347. The provider RAND interface was introduced in OpenSSL 3.0.
  348. The Rand Parameters "fips-indicator" and "digest-check" were added in
  349. OpenSSL 3.4.
  350. .SH COPYRIGHT
  351. .IX Header "COPYRIGHT"
  352. Copyright 2020\-2024 The OpenSSL Project Authors. All Rights Reserved.
  353. .PP
  354. Licensed under the Apache License 2.0 (the "License"). You may not use
  355. this file except in compliance with the License. You can obtain a copy
  356. in the file LICENSE in the source distribution or at
  357. <https://www.openssl.org/source/license.html>.