drbg_hash.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. /*
  2. * Copyright 2011-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <assert.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <openssl/sha.h>
  13. #include <openssl/crypto.h>
  14. #include <openssl/err.h>
  15. #include <openssl/rand.h>
  16. #include <openssl/core_dispatch.h>
  17. #include <openssl/proverr.h>
  18. #include "internal/thread_once.h"
  19. #include "prov/providercommon.h"
  20. #include "prov/provider_ctx.h"
  21. #include "prov/provider_util.h"
  22. #include "prov/implementations.h"
  23. #include "drbg_local.h"
  24. static OSSL_FUNC_rand_newctx_fn drbg_hash_new_wrapper;
  25. static OSSL_FUNC_rand_freectx_fn drbg_hash_free;
  26. static OSSL_FUNC_rand_instantiate_fn drbg_hash_instantiate_wrapper;
  27. static OSSL_FUNC_rand_uninstantiate_fn drbg_hash_uninstantiate_wrapper;
  28. static OSSL_FUNC_rand_generate_fn drbg_hash_generate_wrapper;
  29. static OSSL_FUNC_rand_reseed_fn drbg_hash_reseed_wrapper;
  30. static OSSL_FUNC_rand_settable_ctx_params_fn drbg_hash_settable_ctx_params;
  31. static OSSL_FUNC_rand_set_ctx_params_fn drbg_hash_set_ctx_params;
  32. static OSSL_FUNC_rand_gettable_ctx_params_fn drbg_hash_gettable_ctx_params;
  33. static OSSL_FUNC_rand_get_ctx_params_fn drbg_hash_get_ctx_params;
  34. static OSSL_FUNC_rand_verify_zeroization_fn drbg_hash_verify_zeroization;
  35. /* 888 bits from SP800-90Ar1 10.1 table 2 */
  36. #define HASH_PRNG_MAX_SEEDLEN (888/8)
  37. /* 440 bits from SP800-90Ar1 10.1 table 2 */
  38. #define HASH_PRNG_SMALL_SEEDLEN (440/8)
  39. /* Determine what seedlen to use based on the block length */
  40. #define MAX_BLOCKLEN_USING_SMALL_SEEDLEN (256/8)
  41. #define INBYTE_IGNORE ((unsigned char)0xFF)
  42. typedef struct rand_drbg_hash_st {
  43. PROV_DIGEST digest;
  44. EVP_MD_CTX *ctx;
  45. size_t blocklen;
  46. unsigned char V[HASH_PRNG_MAX_SEEDLEN];
  47. unsigned char C[HASH_PRNG_MAX_SEEDLEN];
  48. /* Temporary value storage: should always exceed max digest length */
  49. unsigned char vtmp[HASH_PRNG_MAX_SEEDLEN];
  50. } PROV_DRBG_HASH;
  51. /*
  52. * SP800-90Ar1 10.3.1 Derivation function using a Hash Function (Hash_df).
  53. * The input string used is composed of:
  54. * inbyte - An optional leading byte (ignore if equal to INBYTE_IGNORE)
  55. * in - input string 1 (A Non NULL value).
  56. * in2 - optional input string (Can be NULL).
  57. * in3 - optional input string (Can be NULL).
  58. * These are concatenated as part of the DigestUpdate process.
  59. */
  60. static int hash_df(PROV_DRBG *drbg, unsigned char *out,
  61. const unsigned char inbyte,
  62. const unsigned char *in, size_t inlen,
  63. const unsigned char *in2, size_t in2len,
  64. const unsigned char *in3, size_t in3len)
  65. {
  66. PROV_DRBG_HASH *hash = (PROV_DRBG_HASH *)drbg->data;
  67. EVP_MD_CTX *ctx = hash->ctx;
  68. unsigned char *vtmp = hash->vtmp;
  69. /* tmp = counter || num_bits_returned || [inbyte] */
  70. unsigned char tmp[1 + 4 + 1];
  71. int tmp_sz = 0;
  72. size_t outlen = drbg->seedlen;
  73. size_t num_bits_returned = outlen * 8;
  74. /*
  75. * No need to check outlen size here, as the standard only ever needs
  76. * seedlen bytes which is always less than the maximum permitted.
  77. */
  78. /* (Step 3) counter = 1 (tmp[0] is the 8 bit counter) */
  79. tmp[tmp_sz++] = 1;
  80. /* tmp[1..4] is the fixed 32 bit no_of_bits_to_return */
  81. tmp[tmp_sz++] = (unsigned char)((num_bits_returned >> 24) & 0xff);
  82. tmp[tmp_sz++] = (unsigned char)((num_bits_returned >> 16) & 0xff);
  83. tmp[tmp_sz++] = (unsigned char)((num_bits_returned >> 8) & 0xff);
  84. tmp[tmp_sz++] = (unsigned char)(num_bits_returned & 0xff);
  85. /* Tack the additional input byte onto the end of tmp if it exists */
  86. if (inbyte != INBYTE_IGNORE)
  87. tmp[tmp_sz++] = inbyte;
  88. /* (Step 4) */
  89. for (;;) {
  90. /*
  91. * (Step 4.1) out = out || Hash(tmp || in || [in2] || [in3])
  92. * (where tmp = counter || num_bits_returned || [inbyte])
  93. */
  94. if (!(EVP_DigestInit_ex(ctx, ossl_prov_digest_md(&hash->digest), NULL)
  95. && EVP_DigestUpdate(ctx, tmp, tmp_sz)
  96. && EVP_DigestUpdate(ctx, in, inlen)
  97. && (in2 == NULL || EVP_DigestUpdate(ctx, in2, in2len))
  98. && (in3 == NULL || EVP_DigestUpdate(ctx, in3, in3len))))
  99. return 0;
  100. if (outlen < hash->blocklen) {
  101. if (!EVP_DigestFinal(ctx, vtmp, NULL))
  102. return 0;
  103. memcpy(out, vtmp, outlen);
  104. OPENSSL_cleanse(vtmp, hash->blocklen);
  105. break;
  106. } else if (!EVP_DigestFinal(ctx, out, NULL)) {
  107. return 0;
  108. }
  109. outlen -= hash->blocklen;
  110. if (outlen == 0)
  111. break;
  112. /* (Step 4.2) counter++ */
  113. tmp[0]++;
  114. out += hash->blocklen;
  115. }
  116. return 1;
  117. }
  118. /* Helper function that just passes 2 input parameters to hash_df() */
  119. static int hash_df1(PROV_DRBG *drbg, unsigned char *out,
  120. const unsigned char in_byte,
  121. const unsigned char *in1, size_t in1len)
  122. {
  123. return hash_df(drbg, out, in_byte, in1, in1len, NULL, 0, NULL, 0);
  124. }
  125. /*
  126. * Add 2 byte buffers together. The first elements in each buffer are the top
  127. * most bytes. The result is stored in the dst buffer.
  128. * The final carry is ignored i.e: dst = (dst + in) mod (2^seedlen_bits).
  129. * where dst size is drbg->seedlen, and inlen <= drbg->seedlen.
  130. */
  131. static int add_bytes(PROV_DRBG *drbg, unsigned char *dst,
  132. unsigned char *in, size_t inlen)
  133. {
  134. size_t i;
  135. int result;
  136. const unsigned char *add;
  137. unsigned char carry = 0, *d;
  138. assert(drbg->seedlen >= 1 && inlen >= 1 && inlen <= drbg->seedlen);
  139. d = &dst[drbg->seedlen - 1];
  140. add = &in[inlen - 1];
  141. for (i = inlen; i > 0; i--, d--, add--) {
  142. result = *d + *add + carry;
  143. carry = (unsigned char)(result >> 8);
  144. *d = (unsigned char)(result & 0xff);
  145. }
  146. if (carry != 0) {
  147. /* Add the carry to the top of the dst if inlen is not the same size */
  148. for (i = drbg->seedlen - inlen; i > 0; --i, d--) {
  149. *d += 1; /* Carry can only be 1 */
  150. if (*d != 0) /* exit if carry doesnt propagate to the next byte */
  151. break;
  152. }
  153. }
  154. return 1;
  155. }
  156. /* V = (V + Hash(inbyte || V || [additional_input]) mod (2^seedlen) */
  157. static int add_hash_to_v(PROV_DRBG *drbg, unsigned char inbyte,
  158. const unsigned char *adin, size_t adinlen)
  159. {
  160. PROV_DRBG_HASH *hash = (PROV_DRBG_HASH *)drbg->data;
  161. EVP_MD_CTX *ctx = hash->ctx;
  162. return EVP_DigestInit_ex(ctx, ossl_prov_digest_md(&hash->digest), NULL)
  163. && EVP_DigestUpdate(ctx, &inbyte, 1)
  164. && EVP_DigestUpdate(ctx, hash->V, drbg->seedlen)
  165. && (adin == NULL || EVP_DigestUpdate(ctx, adin, adinlen))
  166. && EVP_DigestFinal(ctx, hash->vtmp, NULL)
  167. && add_bytes(drbg, hash->V, hash->vtmp, hash->blocklen);
  168. }
  169. /*
  170. * The Hashgen() as listed in SP800-90Ar1 10.1.1.4 Hash_DRBG_Generate_Process.
  171. *
  172. * drbg contains the current value of V.
  173. * outlen is the requested number of bytes.
  174. * out is a buffer to return the generated bits.
  175. *
  176. * The algorithm to generate the bits is:
  177. * data = V
  178. * w = NULL
  179. * for (i = 1 to m) {
  180. * W = W || Hash(data)
  181. * data = (data + 1) mod (2^seedlen)
  182. * }
  183. * out = Leftmost(W, outlen)
  184. *
  185. * Returns zero if an error occurs otherwise it returns 1.
  186. */
  187. static int hash_gen(PROV_DRBG *drbg, unsigned char *out, size_t outlen)
  188. {
  189. PROV_DRBG_HASH *hash = (PROV_DRBG_HASH *)drbg->data;
  190. unsigned char one = 1;
  191. if (outlen == 0)
  192. return 1;
  193. memcpy(hash->vtmp, hash->V, drbg->seedlen);
  194. for (;;) {
  195. if (!EVP_DigestInit_ex(hash->ctx, ossl_prov_digest_md(&hash->digest),
  196. NULL)
  197. || !EVP_DigestUpdate(hash->ctx, hash->vtmp, drbg->seedlen))
  198. return 0;
  199. if (outlen < hash->blocklen) {
  200. if (!EVP_DigestFinal(hash->ctx, hash->vtmp, NULL))
  201. return 0;
  202. memcpy(out, hash->vtmp, outlen);
  203. return 1;
  204. } else {
  205. if (!EVP_DigestFinal(hash->ctx, out, NULL))
  206. return 0;
  207. outlen -= hash->blocklen;
  208. if (outlen == 0)
  209. break;
  210. out += hash->blocklen;
  211. }
  212. add_bytes(drbg, hash->vtmp, &one, 1);
  213. }
  214. return 1;
  215. }
  216. /*
  217. * SP800-90Ar1 10.1.1.2 Hash_DRBG_Instantiate_Process:
  218. *
  219. * ent is entropy input obtained from a randomness source of length ent_len.
  220. * nonce is a string of bytes of length nonce_len.
  221. * pstr is a personalization string received from an application. May be NULL.
  222. *
  223. * Returns zero if an error occurs otherwise it returns 1.
  224. */
  225. static int drbg_hash_instantiate(PROV_DRBG *drbg,
  226. const unsigned char *ent, size_t ent_len,
  227. const unsigned char *nonce, size_t nonce_len,
  228. const unsigned char *pstr, size_t pstr_len)
  229. {
  230. PROV_DRBG_HASH *hash = (PROV_DRBG_HASH *)drbg->data;
  231. EVP_MD_CTX_free(hash->ctx);
  232. hash->ctx = EVP_MD_CTX_new();
  233. /* (Step 1-3) V = Hash_df(entropy||nonce||pers, seedlen) */
  234. return hash->ctx != NULL
  235. && hash_df(drbg, hash->V, INBYTE_IGNORE,
  236. ent, ent_len, nonce, nonce_len, pstr, pstr_len)
  237. /* (Step 4) C = Hash_df(0x00||V, seedlen) */
  238. && hash_df1(drbg, hash->C, 0x00, hash->V, drbg->seedlen);
  239. }
  240. static int drbg_hash_instantiate_wrapper(void *vdrbg, unsigned int strength,
  241. int prediction_resistance,
  242. const unsigned char *pstr,
  243. size_t pstr_len,
  244. const OSSL_PARAM params[])
  245. {
  246. PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
  247. if (!ossl_prov_is_running() || !drbg_hash_set_ctx_params(drbg, params))
  248. return 0;
  249. return ossl_prov_drbg_instantiate(drbg, strength, prediction_resistance,
  250. pstr, pstr_len);
  251. }
  252. /*
  253. * SP800-90Ar1 10.1.1.3 Hash_DRBG_Reseed_Process:
  254. *
  255. * ent is entropy input bytes obtained from a randomness source.
  256. * addin is additional input received from an application. May be NULL.
  257. *
  258. * Returns zero if an error occurs otherwise it returns 1.
  259. */
  260. static int drbg_hash_reseed(PROV_DRBG *drbg,
  261. const unsigned char *ent, size_t ent_len,
  262. const unsigned char *adin, size_t adin_len)
  263. {
  264. PROV_DRBG_HASH *hash = (PROV_DRBG_HASH *)drbg->data;
  265. /* (Step 1-2) V = Hash_df(0x01 || V || entropy_input || additional_input) */
  266. /* V about to be updated so use C as output instead */
  267. if (!hash_df(drbg, hash->C, 0x01, hash->V, drbg->seedlen, ent, ent_len,
  268. adin, adin_len))
  269. return 0;
  270. memcpy(hash->V, hash->C, drbg->seedlen);
  271. /* (Step 4) C = Hash_df(0x00||V, seedlen) */
  272. return hash_df1(drbg, hash->C, 0x00, hash->V, drbg->seedlen);
  273. }
  274. static int drbg_hash_reseed_wrapper(void *vdrbg, int prediction_resistance,
  275. const unsigned char *ent, size_t ent_len,
  276. const unsigned char *adin, size_t adin_len)
  277. {
  278. PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
  279. return ossl_prov_drbg_reseed(drbg, prediction_resistance, ent, ent_len,
  280. adin, adin_len);
  281. }
  282. /*
  283. * SP800-90Ar1 10.1.1.4 Hash_DRBG_Generate_Process:
  284. *
  285. * Generates pseudo random bytes using the drbg.
  286. * out is a buffer to fill with outlen bytes of pseudo random data.
  287. * addin is additional input received from an application. May be NULL.
  288. *
  289. * Returns zero if an error occurs otherwise it returns 1.
  290. */
  291. static int drbg_hash_generate(PROV_DRBG *drbg,
  292. unsigned char *out, size_t outlen,
  293. const unsigned char *adin, size_t adin_len)
  294. {
  295. PROV_DRBG_HASH *hash = (PROV_DRBG_HASH *)drbg->data;
  296. unsigned char counter[4];
  297. int reseed_counter = drbg->generate_counter;
  298. counter[0] = (unsigned char)((reseed_counter >> 24) & 0xff);
  299. counter[1] = (unsigned char)((reseed_counter >> 16) & 0xff);
  300. counter[2] = (unsigned char)((reseed_counter >> 8) & 0xff);
  301. counter[3] = (unsigned char)(reseed_counter & 0xff);
  302. return hash->ctx != NULL
  303. && (adin == NULL
  304. /* (Step 2) if adin != NULL then V = V + Hash(0x02||V||adin) */
  305. || adin_len == 0
  306. || add_hash_to_v(drbg, 0x02, adin, adin_len))
  307. /* (Step 3) Hashgen(outlen, V) */
  308. && hash_gen(drbg, out, outlen)
  309. /* (Step 4/5) H = V = (V + Hash(0x03||V) mod (2^seedlen_bits) */
  310. && add_hash_to_v(drbg, 0x03, NULL, 0)
  311. /* (Step 5) V = (V + H + C + reseed_counter) mod (2^seedlen_bits) */
  312. /* V = (V + C) mod (2^seedlen_bits) */
  313. && add_bytes(drbg, hash->V, hash->C, drbg->seedlen)
  314. /* V = (V + reseed_counter) mod (2^seedlen_bits) */
  315. && add_bytes(drbg, hash->V, counter, 4);
  316. }
  317. static int drbg_hash_generate_wrapper
  318. (void *vdrbg, unsigned char *out, size_t outlen, unsigned int strength,
  319. int prediction_resistance, const unsigned char *adin, size_t adin_len)
  320. {
  321. PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
  322. return ossl_prov_drbg_generate(drbg, out, outlen, strength,
  323. prediction_resistance, adin, adin_len);
  324. }
  325. static int drbg_hash_uninstantiate(PROV_DRBG *drbg)
  326. {
  327. PROV_DRBG_HASH *hash = (PROV_DRBG_HASH *)drbg->data;
  328. OPENSSL_cleanse(hash->V, sizeof(hash->V));
  329. OPENSSL_cleanse(hash->C, sizeof(hash->C));
  330. OPENSSL_cleanse(hash->vtmp, sizeof(hash->vtmp));
  331. return ossl_prov_drbg_uninstantiate(drbg);
  332. }
  333. static int drbg_hash_uninstantiate_wrapper(void *vdrbg)
  334. {
  335. return drbg_hash_uninstantiate((PROV_DRBG *)vdrbg);
  336. }
  337. static int drbg_hash_verify_zeroization(void *vdrbg)
  338. {
  339. PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
  340. PROV_DRBG_HASH *hash = (PROV_DRBG_HASH *)drbg->data;
  341. PROV_DRBG_VERYIFY_ZEROIZATION(hash->V);
  342. PROV_DRBG_VERYIFY_ZEROIZATION(hash->C);
  343. PROV_DRBG_VERYIFY_ZEROIZATION(hash->vtmp);
  344. return 1;
  345. }
  346. static int drbg_hash_new(PROV_DRBG *ctx)
  347. {
  348. PROV_DRBG_HASH *hash;
  349. hash = OPENSSL_secure_zalloc(sizeof(*hash));
  350. if (hash == NULL) {
  351. ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
  352. return 0;
  353. }
  354. ctx->data = hash;
  355. ctx->seedlen = HASH_PRNG_MAX_SEEDLEN;
  356. ctx->max_entropylen = DRBG_MAX_LENGTH;
  357. ctx->max_noncelen = DRBG_MAX_LENGTH;
  358. ctx->max_perslen = DRBG_MAX_LENGTH;
  359. ctx->max_adinlen = DRBG_MAX_LENGTH;
  360. /* Maximum number of bits per request = 2^19 = 2^16 bytes */
  361. ctx->max_request = 1 << 16;
  362. return 1;
  363. }
  364. static void *drbg_hash_new_wrapper(void *provctx, void *parent,
  365. const OSSL_DISPATCH *parent_dispatch)
  366. {
  367. return ossl_rand_drbg_new(provctx, parent, parent_dispatch, &drbg_hash_new,
  368. &drbg_hash_instantiate, &drbg_hash_uninstantiate,
  369. &drbg_hash_reseed, &drbg_hash_generate);
  370. }
  371. static void drbg_hash_free(void *vdrbg)
  372. {
  373. PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
  374. PROV_DRBG_HASH *hash;
  375. if (drbg != NULL && (hash = (PROV_DRBG_HASH *)drbg->data) != NULL) {
  376. EVP_MD_CTX_free(hash->ctx);
  377. ossl_prov_digest_reset(&hash->digest);
  378. OPENSSL_secure_clear_free(hash, sizeof(*hash));
  379. }
  380. ossl_rand_drbg_free(drbg);
  381. }
  382. static int drbg_hash_get_ctx_params(void *vdrbg, OSSL_PARAM params[])
  383. {
  384. PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
  385. PROV_DRBG_HASH *hash = (PROV_DRBG_HASH *)drbg->data;
  386. const EVP_MD *md;
  387. OSSL_PARAM *p;
  388. p = OSSL_PARAM_locate(params, OSSL_DRBG_PARAM_DIGEST);
  389. if (p != NULL) {
  390. md = ossl_prov_digest_md(&hash->digest);
  391. if (md == NULL || !OSSL_PARAM_set_utf8_string(p, EVP_MD_get0_name(md)))
  392. return 0;
  393. }
  394. return ossl_drbg_get_ctx_params(drbg, params);
  395. }
  396. static const OSSL_PARAM *drbg_hash_gettable_ctx_params(ossl_unused void *vctx,
  397. ossl_unused void *p_ctx)
  398. {
  399. static const OSSL_PARAM known_gettable_ctx_params[] = {
  400. OSSL_PARAM_utf8_string(OSSL_DRBG_PARAM_DIGEST, NULL, 0),
  401. OSSL_PARAM_DRBG_GETTABLE_CTX_COMMON,
  402. OSSL_PARAM_END
  403. };
  404. return known_gettable_ctx_params;
  405. }
  406. static int drbg_hash_set_ctx_params(void *vctx, const OSSL_PARAM params[])
  407. {
  408. PROV_DRBG *ctx = (PROV_DRBG *)vctx;
  409. PROV_DRBG_HASH *hash = (PROV_DRBG_HASH *)ctx->data;
  410. OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx);
  411. const EVP_MD *md;
  412. if (!ossl_prov_digest_load_from_params(&hash->digest, params, libctx))
  413. return 0;
  414. md = ossl_prov_digest_md(&hash->digest);
  415. if (md != NULL) {
  416. if ((EVP_MD_get_flags(md) & EVP_MD_FLAG_XOF) != 0) {
  417. ERR_raise(ERR_LIB_PROV, PROV_R_XOF_DIGESTS_NOT_ALLOWED);
  418. return 0;
  419. }
  420. /* These are taken from SP 800-90 10.1 Table 2 */
  421. hash->blocklen = EVP_MD_get_size(md);
  422. /* See SP800-57 Part1 Rev4 5.6.1 Table 3 */
  423. ctx->strength = 64 * (hash->blocklen >> 3);
  424. if (ctx->strength > 256)
  425. ctx->strength = 256;
  426. if (hash->blocklen > MAX_BLOCKLEN_USING_SMALL_SEEDLEN)
  427. ctx->seedlen = HASH_PRNG_MAX_SEEDLEN;
  428. else
  429. ctx->seedlen = HASH_PRNG_SMALL_SEEDLEN;
  430. ctx->min_entropylen = ctx->strength / 8;
  431. ctx->min_noncelen = ctx->min_entropylen / 2;
  432. }
  433. return ossl_drbg_set_ctx_params(ctx, params);
  434. }
  435. static const OSSL_PARAM *drbg_hash_settable_ctx_params(ossl_unused void *vctx,
  436. ossl_unused void *p_ctx)
  437. {
  438. static const OSSL_PARAM known_settable_ctx_params[] = {
  439. OSSL_PARAM_utf8_string(OSSL_DRBG_PARAM_PROPERTIES, NULL, 0),
  440. OSSL_PARAM_utf8_string(OSSL_DRBG_PARAM_DIGEST, NULL, 0),
  441. OSSL_PARAM_DRBG_SETTABLE_CTX_COMMON,
  442. OSSL_PARAM_END
  443. };
  444. return known_settable_ctx_params;
  445. }
  446. const OSSL_DISPATCH ossl_drbg_hash_functions[] = {
  447. { OSSL_FUNC_RAND_NEWCTX, (void(*)(void))drbg_hash_new_wrapper },
  448. { OSSL_FUNC_RAND_FREECTX, (void(*)(void))drbg_hash_free },
  449. { OSSL_FUNC_RAND_INSTANTIATE,
  450. (void(*)(void))drbg_hash_instantiate_wrapper },
  451. { OSSL_FUNC_RAND_UNINSTANTIATE,
  452. (void(*)(void))drbg_hash_uninstantiate_wrapper },
  453. { OSSL_FUNC_RAND_GENERATE, (void(*)(void))drbg_hash_generate_wrapper },
  454. { OSSL_FUNC_RAND_RESEED, (void(*)(void))drbg_hash_reseed_wrapper },
  455. { OSSL_FUNC_RAND_ENABLE_LOCKING, (void(*)(void))ossl_drbg_enable_locking },
  456. { OSSL_FUNC_RAND_LOCK, (void(*)(void))ossl_drbg_lock },
  457. { OSSL_FUNC_RAND_UNLOCK, (void(*)(void))ossl_drbg_unlock },
  458. { OSSL_FUNC_RAND_SETTABLE_CTX_PARAMS,
  459. (void(*)(void))drbg_hash_settable_ctx_params },
  460. { OSSL_FUNC_RAND_SET_CTX_PARAMS, (void(*)(void))drbg_hash_set_ctx_params },
  461. { OSSL_FUNC_RAND_GETTABLE_CTX_PARAMS,
  462. (void(*)(void))drbg_hash_gettable_ctx_params },
  463. { OSSL_FUNC_RAND_GET_CTX_PARAMS, (void(*)(void))drbg_hash_get_ctx_params },
  464. { OSSL_FUNC_RAND_VERIFY_ZEROIZATION,
  465. (void(*)(void))drbg_hash_verify_zeroization },
  466. { OSSL_FUNC_RAND_GET_SEED, (void(*)(void))ossl_drbg_get_seed },
  467. { OSSL_FUNC_RAND_CLEAR_SEED, (void(*)(void))ossl_drbg_clear_seed },
  468. { 0, NULL }
  469. };