EVP_RAND.3ossl 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
  2. .\"
  3. .\" Standard preamble:
  4. .\" ========================================================================
  5. .de Sp \" Vertical space (when we can't use .PP)
  6. .if t .sp .5v
  7. .if n .sp
  8. ..
  9. .de Vb \" Begin verbatim text
  10. .ft CW
  11. .nf
  12. .ne \\$1
  13. ..
  14. .de Ve \" End verbatim text
  15. .ft R
  16. .fi
  17. ..
  18. .\" Set up some character translations and predefined strings. \*(-- will
  19. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  20. .\" double quote, and \*(R" will give a right double quote. \*(C+ will
  21. .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
  22. .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
  23. .\" nothing in troff, for use with C<>.
  24. .tr \(*W-
  25. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  26. .ie n \{\
  27. . ds -- \(*W-
  28. . ds PI pi
  29. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  30. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  31. . ds L" ""
  32. . ds R" ""
  33. . ds C` ""
  34. . ds C' ""
  35. 'br\}
  36. .el\{\
  37. . ds -- \|\(em\|
  38. . ds PI \(*p
  39. . ds L" ``
  40. . ds R" ''
  41. . ds C`
  42. . ds C'
  43. 'br\}
  44. .\"
  45. .\" Escape single quotes in literal strings from groff's Unicode transform.
  46. .ie \n(.g .ds Aq \(aq
  47. .el .ds Aq '
  48. .\"
  49. .\" If the F register is >0, we'll generate index entries on stderr for
  50. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  51. .\" entries marked with X<> in POD. Of course, you'll have to process the
  52. .\" output yourself in some meaningful fashion.
  53. .\"
  54. .\" Avoid warning from groff about undefined register 'F'.
  55. .de IX
  56. ..
  57. .nr rF 0
  58. .if \n(.g .if rF .nr rF 1
  59. .if (\n(rF:(\n(.g==0)) \{\
  60. . if \nF \{\
  61. . de IX
  62. . tm Index:\\$1\t\\n%\t"\\$2"
  63. ..
  64. . if !\nF==2 \{\
  65. . nr % 0
  66. . nr F 2
  67. . \}
  68. . \}
  69. .\}
  70. .rr rF
  71. .\"
  72. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  73. .\" Fear. Run. Save yourself. No user-serviceable parts.
  74. . \" fudge factors for nroff and troff
  75. .if n \{\
  76. . ds #H 0
  77. . ds #V .8m
  78. . ds #F .3m
  79. . ds #[ \f1
  80. . ds #] \fP
  81. .\}
  82. .if t \{\
  83. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  84. . ds #V .6m
  85. . ds #F 0
  86. . ds #[ \&
  87. . ds #] \&
  88. .\}
  89. . \" simple accents for nroff and troff
  90. .if n \{\
  91. . ds ' \&
  92. . ds ` \&
  93. . ds ^ \&
  94. . ds , \&
  95. . ds ~ ~
  96. . ds /
  97. .\}
  98. .if t \{\
  99. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  100. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  101. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  102. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  103. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  104. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  105. .\}
  106. . \" troff and (daisy-wheel) nroff accents
  107. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  108. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  109. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  110. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  111. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  112. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  113. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  114. .ds ae a\h'-(\w'a'u*4/10)'e
  115. .ds Ae A\h'-(\w'A'u*4/10)'E
  116. . \" corrections for vroff
  117. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  118. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  119. . \" for low resolution devices (crt and lpr)
  120. .if \n(.H>23 .if \n(.V>19 \
  121. \{\
  122. . ds : e
  123. . ds 8 ss
  124. . ds o a
  125. . ds d- d\h'-1'\(ga
  126. . ds D- D\h'-1'\(hy
  127. . ds th \o'bp'
  128. . ds Th \o'LP'
  129. . ds ae ae
  130. . ds Ae AE
  131. .\}
  132. .rm #[ #] #H #V #F C
  133. .\" ========================================================================
  134. .\"
  135. .IX Title "EVP_RAND 3ossl"
  136. .TH EVP_RAND 3ossl "2024-09-03" "3.3.2" "OpenSSL"
  137. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  138. .\" way too many mistakes in technical documents.
  139. .if n .ad l
  140. .nh
  141. .SH "NAME"
  142. EVP_RAND, EVP_RAND_fetch, EVP_RAND_free, EVP_RAND_up_ref, EVP_RAND_CTX,
  143. EVP_RAND_CTX_new, EVP_RAND_CTX_free, EVP_RAND_CTX_up_ref, EVP_RAND_instantiate,
  144. EVP_RAND_uninstantiate, EVP_RAND_generate, EVP_RAND_reseed, EVP_RAND_nonce,
  145. EVP_RAND_enable_locking, EVP_RAND_verify_zeroization, EVP_RAND_get_strength,
  146. EVP_RAND_get_state,
  147. EVP_RAND_get0_provider, EVP_RAND_CTX_get0_rand, EVP_RAND_is_a,
  148. EVP_RAND_get0_name, EVP_RAND_names_do_all,
  149. EVP_RAND_get0_description,
  150. EVP_RAND_CTX_get_params,
  151. EVP_RAND_CTX_set_params, EVP_RAND_do_all_provided, EVP_RAND_get_params,
  152. EVP_RAND_gettable_ctx_params, EVP_RAND_settable_ctx_params,
  153. EVP_RAND_CTX_gettable_params, EVP_RAND_CTX_settable_params,
  154. EVP_RAND_gettable_params, EVP_RAND_STATE_UNINITIALISED, EVP_RAND_STATE_READY,
  155. EVP_RAND_STATE_ERROR \- EVP RAND routines
  156. .SH "SYNOPSIS"
  157. .IX Header "SYNOPSIS"
  158. .Vb 1
  159. \& #include <openssl/evp.h>
  160. \&
  161. \& typedef struct evp_rand_st EVP_RAND;
  162. \& typedef struct evp_rand_ctx_st EVP_RAND_CTX;
  163. \&
  164. \& EVP_RAND *EVP_RAND_fetch(OSSL_LIB_CTX *libctx, const char *algorithm,
  165. \& const char *properties);
  166. \& int EVP_RAND_up_ref(EVP_RAND *rand);
  167. \& void EVP_RAND_free(EVP_RAND *rand);
  168. \& EVP_RAND_CTX *EVP_RAND_CTX_new(EVP_RAND *rand, EVP_RAND_CTX *parent);
  169. \& void EVP_RAND_CTX_free(EVP_RAND_CTX *ctx);
  170. \& int EVP_RAND_CTX_up_ref(EVP_RAND_CTX *ctx);
  171. \& EVP_RAND *EVP_RAND_CTX_get0_rand(EVP_RAND_CTX *ctx);
  172. \& int EVP_RAND_get_params(EVP_RAND *rand, OSSL_PARAM params[]);
  173. \& int EVP_RAND_CTX_get_params(EVP_RAND_CTX *ctx, OSSL_PARAM params[]);
  174. \& int EVP_RAND_CTX_set_params(EVP_RAND_CTX *ctx, const OSSL_PARAM params[]);
  175. \& const OSSL_PARAM *EVP_RAND_gettable_params(const EVP_RAND *rand);
  176. \& const OSSL_PARAM *EVP_RAND_gettable_ctx_params(const EVP_RAND *rand);
  177. \& const OSSL_PARAM *EVP_RAND_settable_ctx_params(const EVP_RAND *rand);
  178. \& const OSSL_PARAM *EVP_RAND_CTX_gettable_params(EVP_RAND_CTX *ctx);
  179. \& const OSSL_PARAM *EVP_RAND_CTX_settable_params(EVP_RAND_CTX *ctx);
  180. \& const char *EVP_RAND_get0_name(const EVP_RAND *rand);
  181. \& const char *EVP_RAND_get0_description(const EVP_RAND *rand);
  182. \& int EVP_RAND_is_a(const EVP_RAND *rand, const char *name);
  183. \& const OSSL_PROVIDER *EVP_RAND_get0_provider(const EVP_RAND *rand);
  184. \& void EVP_RAND_do_all_provided(OSSL_LIB_CTX *libctx,
  185. \& void (*fn)(EVP_RAND *rand, void *arg),
  186. \& void *arg);
  187. \& int EVP_RAND_names_do_all(const EVP_RAND *rand,
  188. \& void (*fn)(const char *name, void *data),
  189. \& void *data);
  190. \&
  191. \& int EVP_RAND_instantiate(EVP_RAND_CTX *ctx, unsigned int strength,
  192. \& int prediction_resistance,
  193. \& const unsigned char *pstr, size_t pstr_len,
  194. \& const OSSL_PARAM params[]);
  195. \& int EVP_RAND_uninstantiate(EVP_RAND_CTX *ctx);
  196. \& int EVP_RAND_generate(EVP_RAND_CTX *ctx, unsigned char *out, size_t outlen,
  197. \& unsigned int strength, int prediction_resistance,
  198. \& const unsigned char *addin, size_t addin_len);
  199. \& int EVP_RAND_reseed(EVP_RAND_CTX *ctx, int prediction_resistance,
  200. \& const unsigned char *ent, size_t ent_len,
  201. \& const unsigned char *addin, size_t addin_len);
  202. \& int EVP_RAND_nonce(EVP_RAND_CTX *ctx, unsigned char *out, size_t outlen);
  203. \& int EVP_RAND_enable_locking(EVP_RAND_CTX *ctx);
  204. \& int EVP_RAND_verify_zeroization(EVP_RAND_CTX *ctx);
  205. \& unsigned int EVP_RAND_get_strength(EVP_RAND_CTX *ctx);
  206. \& int EVP_RAND_get_state(EVP_RAND_CTX *ctx);
  207. \&
  208. \& #define EVP_RAND_STATE_UNINITIALISED 0
  209. \& #define EVP_RAND_STATE_READY 1
  210. \& #define EVP_RAND_STATE_ERROR 2
  211. .Ve
  212. .SH "DESCRIPTION"
  213. .IX Header "DESCRIPTION"
  214. The \s-1EVP RAND\s0 routines are a high-level interface to random number generators
  215. both deterministic and not.
  216. If you just want to generate random bytes then you don't need to use
  217. these functions: just call \fBRAND_bytes()\fR or \fBRAND_priv_bytes()\fR.
  218. If you want to do more, these calls should be used instead of the older
  219. \&\s-1RAND\s0 and \s-1RAND_DRBG\s0 functions.
  220. .PP
  221. After creating a \fB\s-1EVP_RAND_CTX\s0\fR for the required algorithm using
  222. \&\fBEVP_RAND_CTX_new()\fR, inputs to the algorithm are supplied either by
  223. passing them as part of the \fBEVP_RAND_instantiate()\fR call or using calls to
  224. \&\fBEVP_RAND_CTX_set_params()\fR before calling \fBEVP_RAND_instantiate()\fR. Finally,
  225. call \fBEVP_RAND_generate()\fR to produce cryptographically secure random bytes.
  226. .SS "Types"
  227. .IX Subsection "Types"
  228. \&\fB\s-1EVP_RAND\s0\fR is a type that holds the implementation of a \s-1RAND.\s0
  229. .PP
  230. \&\fB\s-1EVP_RAND_CTX\s0\fR is a context type that holds the algorithm inputs.
  231. \&\fB\s-1EVP_RAND_CTX\s0\fR structures are reference counted.
  232. .SS "Algorithm implementation fetching"
  233. .IX Subsection "Algorithm implementation fetching"
  234. \&\fBEVP_RAND_fetch()\fR fetches an implementation of a \s-1RAND\s0 \fIalgorithm\fR, given
  235. a library context \fIlibctx\fR and a set of \fIproperties\fR.
  236. See \*(L"\s-1ALGORITHM FETCHING\*(R"\s0 in \fBcrypto\fR\|(7) for further information.
  237. .PP
  238. The returned value must eventually be freed with
  239. \&\fBEVP_RAND_free\fR\|(3).
  240. .PP
  241. \&\fBEVP_RAND_up_ref()\fR increments the reference count of an already fetched
  242. \&\s-1RAND.\s0
  243. .PP
  244. \&\fBEVP_RAND_free()\fR frees a fetched algorithm.
  245. \&\s-1NULL\s0 is a valid parameter, for which this function is a no-op.
  246. .SS "Context manipulation functions"
  247. .IX Subsection "Context manipulation functions"
  248. \&\fBEVP_RAND_CTX_new()\fR creates a new context for the \s-1RAND\s0 implementation \fIrand\fR.
  249. If not \s-1NULL,\s0 \fIparent\fR specifies the seed source for this implementation.
  250. Not all random number generators need to have a seed source specified.
  251. If a parent is required, a \s-1NULL\s0 \fIparent\fR will utilise the operating
  252. system entropy sources.
  253. It is recommended to minimise the number of random number generators that
  254. rely on the operating system for their randomness because this is often scarce.
  255. .PP
  256. \&\fBEVP_RAND_CTX_free()\fR frees up the context \fIctx\fR. If \fIctx\fR is \s-1NULL,\s0 nothing
  257. is done.
  258. .PP
  259. \&\fBEVP_RAND_CTX_get0_rand()\fR returns the \fB\s-1EVP_RAND\s0\fR associated with the context
  260. \&\fIctx\fR.
  261. .SS "Random Number Generator Functions"
  262. .IX Subsection "Random Number Generator Functions"
  263. \&\fBEVP_RAND_instantiate()\fR processes any parameters in \fIparams\fR and
  264. then instantiates the \s-1RAND\s0 \fIctx\fR with a minimum security strength
  265. of <strength> and personalisation string \fIpstr\fR of length <pstr_len>.
  266. If \fIprediction_resistance\fR is specified, fresh entropy from a live source
  267. will be sought. This call operates as per \s-1NIST SP 800\-90A\s0 and \s-1SP 800\-90C.\s0
  268. .PP
  269. \&\fBEVP_RAND_uninstantiate()\fR uninstantiates the \s-1RAND\s0 \fIctx\fR as per
  270. \&\s-1NIST SP 800\-90A\s0 and \s-1SP 800\-90C.\s0 Subsequent to this call, the \s-1RAND\s0 cannot
  271. be used to generate bytes. It can only be freed or instantiated again.
  272. .PP
  273. \&\fBEVP_RAND_generate()\fR produces random bytes from the \s-1RAND\s0 \fIctx\fR with the
  274. additional input \fIaddin\fR of length \fIaddin_len\fR. The bytes
  275. produced will meet the security \fIstrength\fR.
  276. If \fIprediction_resistance\fR is specified, fresh entropy from a live source
  277. will be sought. This call operates as per \s-1NIST SP 800\-90A\s0 and \s-1SP 800\-90C.\s0
  278. .PP
  279. \&\fBEVP_RAND_reseed()\fR reseeds the \s-1RAND\s0 with new entropy.
  280. Entropy \fIent\fR of length \fIent_len\fR bytes can be supplied as can additional
  281. input \fIaddin\fR of length \fIaddin_len\fR bytes. In the \s-1FIPS\s0 provider, both are
  282. treated as additional input as per \s-1NIST\s0 SP\-800\-90Ar1, Sections 9.1 and 9.2.
  283. Additional seed material is also drawn from the \s-1RAND\s0's parent or the
  284. operating system. If \fIprediction_resistance\fR is specified, fresh entropy
  285. from a live source will be sought. This call operates as per \s-1NIST SP 800\-90A\s0
  286. and \s-1SP 800\-90C.\s0
  287. .PP
  288. \&\fBEVP_RAND_nonce()\fR creates a nonce in \fIout\fR of maximum length \fIoutlen\fR
  289. bytes from the \s-1RAND\s0 \fIctx\fR. The function returns the length of the generated
  290. nonce. If \fIout\fR is \s-1NULL,\s0 the length is still returned but no generation
  291. takes place. This allows a caller to dynamically allocate a buffer of the
  292. appropriate size.
  293. .PP
  294. \&\fBEVP_RAND_enable_locking()\fR enables locking for the \s-1RAND\s0 \fIctx\fR and all of
  295. its parents. After this \fIctx\fR will operate in a thread safe manner, albeit
  296. more slowly. This function is not itself thread safe if called with the same
  297. \&\fIctx\fR from multiple threads. Typically locking should be enabled before a
  298. \&\fIctx\fR is shared across multiple threads.
  299. .PP
  300. \&\fBEVP_RAND_get_params()\fR retrieves details about the implementation
  301. \&\fIrand\fR.
  302. The set of parameters given with \fIparams\fR determine exactly what
  303. parameters should be retrieved.
  304. Note that a parameter that is unknown in the underlying context is
  305. simply ignored.
  306. .PP
  307. \&\fBEVP_RAND_CTX_get_params()\fR retrieves chosen parameters, given the
  308. context \fIctx\fR and its underlying context.
  309. The set of parameters given with \fIparams\fR determine exactly what
  310. parameters should be retrieved.
  311. Note that a parameter that is unknown in the underlying context is
  312. simply ignored.
  313. .PP
  314. \&\fBEVP_RAND_CTX_set_params()\fR passes chosen parameters to the underlying
  315. context, given a context \fIctx\fR.
  316. The set of parameters given with \fIparams\fR determine exactly what
  317. parameters are passed down.
  318. Note that a parameter that is unknown in the underlying context is
  319. simply ignored.
  320. Also, what happens when a needed parameter isn't passed down is
  321. defined by the implementation.
  322. .PP
  323. \&\fBEVP_RAND_gettable_params()\fR returns an \s-1\fBOSSL_PARAM\s0\fR\|(3) array that describes
  324. the retrievable and settable parameters. \fBEVP_RAND_gettable_params()\fR returns
  325. parameters that can be used with \fBEVP_RAND_get_params()\fR.
  326. .PP
  327. \&\fBEVP_RAND_gettable_ctx_params()\fR and \fBEVP_RAND_CTX_gettable_params()\fR return
  328. constant \s-1\fBOSSL_PARAM\s0\fR\|(3) arrays that describe the retrievable parameters that
  329. can be used with \fBEVP_RAND_CTX_get_params()\fR. \fBEVP_RAND_gettable_ctx_params()\fR
  330. returns the parameters that can be retrieved from the algorithm, whereas
  331. \&\fBEVP_RAND_CTX_gettable_params()\fR returns the parameters that can be retrieved
  332. in the context's current state.
  333. .PP
  334. \&\fBEVP_RAND_settable_ctx_params()\fR and \fBEVP_RAND_CTX_settable_params()\fR return
  335. constant \s-1\fBOSSL_PARAM\s0\fR\|(3) arrays that describe the settable parameters that
  336. can be used with \fBEVP_RAND_CTX_set_params()\fR. \fBEVP_RAND_settable_ctx_params()\fR
  337. returns the parameters that can be retrieved from the algorithm, whereas
  338. \&\fBEVP_RAND_CTX_settable_params()\fR returns the parameters that can be retrieved
  339. in the context's current state.
  340. .SS "Information functions"
  341. .IX Subsection "Information functions"
  342. \&\fBEVP_RAND_get_strength()\fR returns the security strength of the \s-1RAND\s0 \fIctx\fR.
  343. .PP
  344. \&\fBEVP_RAND_get_state()\fR returns the current state of the \s-1RAND\s0 \fIctx\fR.
  345. States defined by the OpenSSL RNGs are:
  346. .IP "\(bu" 4
  347. \&\s-1EVP_RAND_STATE_UNINITIALISED:\s0 this \s-1RNG\s0 is currently uninitialised.
  348. The instantiate call will change this to the ready state.
  349. .IP "\(bu" 4
  350. \&\s-1EVP_RAND_STATE_READY:\s0 this \s-1RNG\s0 is currently ready to generate output.
  351. .IP "\(bu" 4
  352. \&\s-1EVP_RAND_STATE_ERROR:\s0 this \s-1RNG\s0 is in an error state.
  353. .PP
  354. \&\fBEVP_RAND_is_a()\fR returns 1 if \fIrand\fR is an implementation of an
  355. algorithm that's identifiable with \fIname\fR, otherwise 0.
  356. .PP
  357. \&\fBEVP_RAND_get0_provider()\fR returns the provider that holds the implementation
  358. of the given \fIrand\fR.
  359. .PP
  360. \&\fBEVP_RAND_do_all_provided()\fR traverses all \s-1RAND\s0 implemented by all activated
  361. providers in the given library context \fIlibctx\fR, and for each of the
  362. implementations, calls the given function \fIfn\fR with the implementation method
  363. and the given \fIarg\fR as argument.
  364. .PP
  365. \&\fBEVP_RAND_get0_name()\fR returns the canonical name of \fIrand\fR.
  366. .PP
  367. \&\fBEVP_RAND_names_do_all()\fR traverses all names for \fIrand\fR, and calls
  368. \&\fIfn\fR with each name and \fIdata\fR.
  369. .PP
  370. \&\fBEVP_RAND_get0_description()\fR returns a description of the rand, meant for
  371. display and human consumption. The description is at the discretion of
  372. the rand implementation.
  373. .PP
  374. \&\fBEVP_RAND_verify_zeroization()\fR confirms if the internal \s-1DRBG\s0 state is
  375. currently zeroed. This is used by the \s-1FIPS\s0 provider to support the mandatory
  376. self tests.
  377. .SH "PARAMETERS"
  378. .IX Header "PARAMETERS"
  379. The standard parameter names are:
  380. .ie n .IP """state"" (\fB\s-1OSSL_RAND_PARAM_STATE\s0\fR) <integer>" 4
  381. .el .IP "``state'' (\fB\s-1OSSL_RAND_PARAM_STATE\s0\fR) <integer>" 4
  382. .IX Item "state (OSSL_RAND_PARAM_STATE) <integer>"
  383. Returns the state of the random number generator.
  384. .ie n .IP """strength"" (\fB\s-1OSSL_RAND_PARAM_STRENGTH\s0\fR) <unsigned integer>" 4
  385. .el .IP "``strength'' (\fB\s-1OSSL_RAND_PARAM_STRENGTH\s0\fR) <unsigned integer>" 4
  386. .IX Item "strength (OSSL_RAND_PARAM_STRENGTH) <unsigned integer>"
  387. Returns the bit strength of the random number generator.
  388. .PP
  389. For rands that are also deterministic random bit generators (DRBGs), these
  390. additional parameters are recognised. Not all
  391. parameters are relevant to, or are understood by all \s-1DRBG\s0 rands:
  392. .ie n .IP """reseed_requests"" (\fB\s-1OSSL_DRBG_PARAM_RESEED_REQUESTS\s0\fR) <unsigned integer>" 4
  393. .el .IP "``reseed_requests'' (\fB\s-1OSSL_DRBG_PARAM_RESEED_REQUESTS\s0\fR) <unsigned integer>" 4
  394. .IX Item "reseed_requests (OSSL_DRBG_PARAM_RESEED_REQUESTS) <unsigned integer>"
  395. Reads or set the number of generate requests before reseeding the
  396. associated \s-1RAND\s0 ctx.
  397. .ie n .IP """reseed_time_interval"" (\fB\s-1OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL\s0\fR) <integer>" 4
  398. .el .IP "``reseed_time_interval'' (\fB\s-1OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL\s0\fR) <integer>" 4
  399. .IX Item "reseed_time_interval (OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL) <integer>"
  400. Reads or set the number of elapsed seconds before reseeding the
  401. associated \s-1RAND\s0 ctx.
  402. .ie n .IP """max_request"" (\fB\s-1OSSL_RAND_PARAM_MAX_REQUEST\s0\fR) <unsigned integer>" 4
  403. .el .IP "``max_request'' (\fB\s-1OSSL_RAND_PARAM_MAX_REQUEST\s0\fR) <unsigned integer>" 4
  404. .IX Item "max_request (OSSL_RAND_PARAM_MAX_REQUEST) <unsigned integer>"
  405. Specifies the maximum number of bytes that can be generated in a single
  406. call to OSSL_FUNC_rand_generate.
  407. .ie n .IP """min_entropylen"" (\fB\s-1OSSL_DRBG_PARAM_MIN_ENTROPYLEN\s0\fR) <unsigned integer>" 4
  408. .el .IP "``min_entropylen'' (\fB\s-1OSSL_DRBG_PARAM_MIN_ENTROPYLEN\s0\fR) <unsigned integer>" 4
  409. .IX Item "min_entropylen (OSSL_DRBG_PARAM_MIN_ENTROPYLEN) <unsigned integer>"
  410. .PD 0
  411. .ie n .IP """max_entropylen"" (\fB\s-1OSSL_DRBG_PARAM_MAX_ENTROPYLEN\s0\fR) <unsigned integer>" 4
  412. .el .IP "``max_entropylen'' (\fB\s-1OSSL_DRBG_PARAM_MAX_ENTROPYLEN\s0\fR) <unsigned integer>" 4
  413. .IX Item "max_entropylen (OSSL_DRBG_PARAM_MAX_ENTROPYLEN) <unsigned integer>"
  414. .PD
  415. Specify the minimum and maximum number of bytes of random material that
  416. can be used to seed the \s-1DRBG.\s0
  417. .ie n .IP """min_noncelen"" (\fB\s-1OSSL_DRBG_PARAM_MIN_NONCELEN\s0\fR) <unsigned integer>" 4
  418. .el .IP "``min_noncelen'' (\fB\s-1OSSL_DRBG_PARAM_MIN_NONCELEN\s0\fR) <unsigned integer>" 4
  419. .IX Item "min_noncelen (OSSL_DRBG_PARAM_MIN_NONCELEN) <unsigned integer>"
  420. .PD 0
  421. .ie n .IP """max_noncelen"" (\fB\s-1OSSL_DRBG_PARAM_MAX_NONCELEN\s0\fR) <unsigned integer>" 4
  422. .el .IP "``max_noncelen'' (\fB\s-1OSSL_DRBG_PARAM_MAX_NONCELEN\s0\fR) <unsigned integer>" 4
  423. .IX Item "max_noncelen (OSSL_DRBG_PARAM_MAX_NONCELEN) <unsigned integer>"
  424. .PD
  425. Specify the minimum and maximum number of bytes of nonce that can be used to
  426. seed the \s-1DRBG.\s0
  427. .ie n .IP """max_perslen"" (\fB\s-1OSSL_DRBG_PARAM_MAX_PERSLEN\s0\fR) <unsigned integer>" 4
  428. .el .IP "``max_perslen'' (\fB\s-1OSSL_DRBG_PARAM_MAX_PERSLEN\s0\fR) <unsigned integer>" 4
  429. .IX Item "max_perslen (OSSL_DRBG_PARAM_MAX_PERSLEN) <unsigned integer>"
  430. .PD 0
  431. .ie n .IP """max_adinlen"" (\fB\s-1OSSL_DRBG_PARAM_MAX_ADINLEN\s0\fR) <unsigned integer>" 4
  432. .el .IP "``max_adinlen'' (\fB\s-1OSSL_DRBG_PARAM_MAX_ADINLEN\s0\fR) <unsigned integer>" 4
  433. .IX Item "max_adinlen (OSSL_DRBG_PARAM_MAX_ADINLEN) <unsigned integer>"
  434. .PD
  435. Specify the minimum and maximum number of bytes of personalisation string
  436. that can be used with the \s-1DRBG.\s0
  437. .ie n .IP """reseed_counter"" (\fB\s-1OSSL_DRBG_PARAM_RESEED_COUNTER\s0\fR) <unsigned integer>" 4
  438. .el .IP "``reseed_counter'' (\fB\s-1OSSL_DRBG_PARAM_RESEED_COUNTER\s0\fR) <unsigned integer>" 4
  439. .IX Item "reseed_counter (OSSL_DRBG_PARAM_RESEED_COUNTER) <unsigned integer>"
  440. Specifies the number of times the \s-1DRBG\s0 has been seeded or reseeded.
  441. .ie n .IP """properties"" (\fB\s-1OSSL_RAND_PARAM_PROPERTIES\s0\fR) <\s-1UTF8\s0 string>" 4
  442. .el .IP "``properties'' (\fB\s-1OSSL_RAND_PARAM_PROPERTIES\s0\fR) <\s-1UTF8\s0 string>" 4
  443. .IX Item "properties (OSSL_RAND_PARAM_PROPERTIES) <UTF8 string>"
  444. .PD 0
  445. .ie n .IP """mac"" (\fB\s-1OSSL_RAND_PARAM_MAC\s0\fR) <\s-1UTF8\s0 string>" 4
  446. .el .IP "``mac'' (\fB\s-1OSSL_RAND_PARAM_MAC\s0\fR) <\s-1UTF8\s0 string>" 4
  447. .IX Item "mac (OSSL_RAND_PARAM_MAC) <UTF8 string>"
  448. .ie n .IP """digest"" (\fB\s-1OSSL_RAND_PARAM_DIGEST\s0\fR) <\s-1UTF8\s0 string>" 4
  449. .el .IP "``digest'' (\fB\s-1OSSL_RAND_PARAM_DIGEST\s0\fR) <\s-1UTF8\s0 string>" 4
  450. .IX Item "digest (OSSL_RAND_PARAM_DIGEST) <UTF8 string>"
  451. .ie n .IP """cipher"" (\fB\s-1OSSL_RAND_PARAM_CIPHER\s0\fR) <\s-1UTF8\s0 string>" 4
  452. .el .IP "``cipher'' (\fB\s-1OSSL_RAND_PARAM_CIPHER\s0\fR) <\s-1UTF8\s0 string>" 4
  453. .IX Item "cipher (OSSL_RAND_PARAM_CIPHER) <UTF8 string>"
  454. .PD
  455. For \s-1RAND\s0 implementations that use an underlying computation \s-1MAC,\s0 digest or
  456. cipher, these parameters set what the algorithm should be.
  457. .Sp
  458. The value is always the name of the intended algorithm,
  459. or the properties in the case of \fB\s-1OSSL_RAND_PARAM_PROPERTIES\s0\fR.
  460. .SH "NOTES"
  461. .IX Header "NOTES"
  462. The use of a nonzero value for the \fIprediction_resistance\fR argument to
  463. \&\fBEVP_RAND_instantiate()\fR, \fBEVP_RAND_generate()\fR or \fBEVP_RAND_reseed()\fR should
  464. be used sparingly. In the default setup, this will cause all public and
  465. private DRBGs to be reseeded on next use. Since, by default, public and
  466. private DRBGs are allocated on a per thread basis, this can result in
  467. significant overhead for highly multi-threaded applications. For normal
  468. use-cases, the default \*(L"reseed_requests\*(R" and \*(L"reseed_time_interval\*(R"
  469. thresholds ensure sufficient prediction resistance over time and you
  470. can reduce those values if you think they are too high. Explicitly
  471. requesting prediction resistance is intended for more special use-cases
  472. like generating long-term secrets.
  473. .PP
  474. An \fB\s-1EVP_RAND_CTX\s0\fR needs to have locking enabled if it acts as the parent of
  475. more than one child and the children can be accessed concurrently. This must
  476. be done by explicitly calling \fBEVP_RAND_enable_locking()\fR.
  477. .PP
  478. The \s-1RAND\s0 life-cycle is described in \fBlife_cycle\-rand\fR\|(7). In the future,
  479. the transitions described there will be enforced. When this is done, it will
  480. not be considered a breaking change to the \s-1API.\s0
  481. .SH "RETURN VALUES"
  482. .IX Header "RETURN VALUES"
  483. \&\fBEVP_RAND_fetch()\fR returns a pointer to a newly fetched \fB\s-1EVP_RAND\s0\fR, or
  484. \&\s-1NULL\s0 if allocation failed.
  485. .PP
  486. \&\fBEVP_RAND_get0_provider()\fR returns a pointer to the provider for the \s-1RAND,\s0 or
  487. \&\s-1NULL\s0 on error.
  488. .PP
  489. \&\fBEVP_RAND_CTX_get0_rand()\fR returns a pointer to the \fB\s-1EVP_RAND\s0\fR associated
  490. with the context.
  491. .PP
  492. \&\fBEVP_RAND_get0_name()\fR returns the name of the random number generation
  493. algorithm.
  494. .PP
  495. \&\fBEVP_RAND_up_ref()\fR returns 1 on success, 0 on error.
  496. .PP
  497. \&\fBEVP_RAND_names_do_all()\fR returns 1 if the callback was called for all names. A
  498. return value of 0 means that the callback was not called for any names.
  499. .PP
  500. \&\fBEVP_RAND_CTX_new()\fR returns either the newly allocated
  501. \&\fB\s-1EVP_RAND_CTX\s0\fR structure or \s-1NULL\s0 if an error occurred.
  502. .PP
  503. \&\fBEVP_RAND_CTX_free()\fR does not return a value.
  504. .PP
  505. \&\fBEVP_RAND_CTX_up_ref()\fR returns 1 on success, 0 on error.
  506. .PP
  507. \&\fBEVP_RAND_nonce()\fR returns the length of the nonce.
  508. .PP
  509. \&\fBEVP_RAND_get_strength()\fR returns the strength of the random number generator
  510. in bits.
  511. .PP
  512. \&\fBEVP_RAND_gettable_params()\fR, \fBEVP_RAND_gettable_ctx_params()\fR and
  513. \&\fBEVP_RAND_settable_ctx_params()\fR return an array of OSSL_PARAMs.
  514. .PP
  515. \&\fBEVP_RAND_verify_zeroization()\fR returns 1 if the internal \s-1DRBG\s0 state is
  516. currently zeroed, and 0 if not.
  517. .PP
  518. The remaining functions return 1 for success and 0 or a negative value for
  519. failure.
  520. .SH "SEE ALSO"
  521. .IX Header "SEE ALSO"
  522. \&\fBRAND_bytes\fR\|(3),
  523. \&\s-1\fBEVP_RAND\-CTR\-DRBG\s0\fR\|(7),
  524. \&\s-1\fBEVP_RAND\-HASH\-DRBG\s0\fR\|(7),
  525. \&\s-1\fBEVP_RAND\-HMAC\-DRBG\s0\fR\|(7),
  526. \&\s-1\fBEVP_RAND\-TEST\-RAND\s0\fR\|(7),
  527. \&\fBprovider\-rand\fR\|(7),
  528. \&\fBlife_cycle\-rand\fR\|(7)
  529. .SH "HISTORY"
  530. .IX Header "HISTORY"
  531. \&\fBEVP_RAND_CTX_up_ref()\fR was added in OpenSSL 3.1.
  532. .PP
  533. The remaining functions were added in OpenSSL 3.0.
  534. .SH "COPYRIGHT"
  535. .IX Header "COPYRIGHT"
  536. Copyright 2020\-2024 The OpenSSL Project Authors. All Rights Reserved.
  537. .PP
  538. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  539. this file except in compliance with the License. You can obtain a copy
  540. in the file \s-1LICENSE\s0 in the source distribution or at
  541. <https://www.openssl.org/source/license.html>.