sskdf.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /*
  2. * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
  4. *
  5. * Licensed under the Apache License 2.0 (the "License"). You may not use
  6. * this file except in compliance with the License. You can obtain a copy
  7. * in the file LICENSE in the source distribution or at
  8. * https://www.openssl.org/source/license.html
  9. */
  10. /*
  11. * Refer to https://csrc.nist.gov/publications/detail/sp/800-56c/rev-1/final
  12. * Section 4.1.
  13. *
  14. * The Single Step KDF algorithm is given by:
  15. *
  16. * Result(0) = empty bit string (i.e., the null string).
  17. * For i = 1 to reps, do the following:
  18. * Increment counter by 1.
  19. * Result(i) = Result(i - 1) || H(counter || Z || FixedInfo).
  20. * DKM = LeftmostBits(Result(reps), L))
  21. *
  22. * NOTES:
  23. * Z is a shared secret required to produce the derived key material.
  24. * counter is a 4 byte buffer.
  25. * FixedInfo is a bit string containing context specific data.
  26. * DKM is the output derived key material.
  27. * L is the required size of the DKM.
  28. * reps = [L / H_outputBits]
  29. * H(x) is the auxiliary function that can be either a hash, HMAC or KMAC.
  30. * H_outputBits is the length of the output of the auxiliary function H(x).
  31. *
  32. * Currently there is not a comprehensive list of test vectors for this
  33. * algorithm, especially for H(x) = HMAC and H(x) = KMAC.
  34. * Test vectors for H(x) = Hash are indirectly used by CAVS KAS tests.
  35. */
  36. #include <stdlib.h>
  37. #include <stdarg.h>
  38. #include <string.h>
  39. #include <openssl/hmac.h>
  40. #include <openssl/evp.h>
  41. #include <openssl/kdf.h>
  42. #include <openssl/core_names.h>
  43. #include <openssl/params.h>
  44. #include <openssl/proverr.h>
  45. #include "internal/cryptlib.h"
  46. #include "internal/numbers.h"
  47. #include "crypto/evp.h"
  48. #include "prov/provider_ctx.h"
  49. #include "prov/providercommon.h"
  50. #include "prov/implementations.h"
  51. #include "prov/provider_util.h"
  52. typedef struct {
  53. void *provctx;
  54. EVP_MAC_CTX *macctx; /* H(x) = HMAC_hash OR H(x) = KMAC */
  55. PROV_DIGEST digest; /* H(x) = hash(x) */
  56. unsigned char *secret;
  57. size_t secret_len;
  58. unsigned char *info;
  59. size_t info_len;
  60. unsigned char *salt;
  61. size_t salt_len;
  62. size_t out_len; /* optional KMAC parameter */
  63. } KDF_SSKDF;
  64. #define SSKDF_MAX_INLEN (1<<30)
  65. #define SSKDF_KMAC128_DEFAULT_SALT_SIZE (168 - 4)
  66. #define SSKDF_KMAC256_DEFAULT_SALT_SIZE (136 - 4)
  67. /* KMAC uses a Customisation string of 'KDF' */
  68. static const unsigned char kmac_custom_str[] = { 0x4B, 0x44, 0x46 };
  69. static OSSL_FUNC_kdf_newctx_fn sskdf_new;
  70. static OSSL_FUNC_kdf_dupctx_fn sskdf_dup;
  71. static OSSL_FUNC_kdf_freectx_fn sskdf_free;
  72. static OSSL_FUNC_kdf_reset_fn sskdf_reset;
  73. static OSSL_FUNC_kdf_derive_fn sskdf_derive;
  74. static OSSL_FUNC_kdf_derive_fn x963kdf_derive;
  75. static OSSL_FUNC_kdf_settable_ctx_params_fn sskdf_settable_ctx_params;
  76. static OSSL_FUNC_kdf_set_ctx_params_fn sskdf_set_ctx_params;
  77. static OSSL_FUNC_kdf_gettable_ctx_params_fn sskdf_gettable_ctx_params;
  78. static OSSL_FUNC_kdf_get_ctx_params_fn sskdf_get_ctx_params;
  79. /*
  80. * Refer to https://csrc.nist.gov/publications/detail/sp/800-56c/rev-1/final
  81. * Section 4. One-Step Key Derivation using H(x) = hash(x)
  82. * Note: X9.63 also uses this code with the only difference being that the
  83. * counter is appended to the secret 'z'.
  84. * i.e.
  85. * result[i] = Hash(counter || z || info) for One Step OR
  86. * result[i] = Hash(z || counter || info) for X9.63.
  87. */
  88. static int SSKDF_hash_kdm(const EVP_MD *kdf_md,
  89. const unsigned char *z, size_t z_len,
  90. const unsigned char *info, size_t info_len,
  91. unsigned int append_ctr,
  92. unsigned char *derived_key, size_t derived_key_len)
  93. {
  94. int ret = 0, hlen;
  95. size_t counter, out_len, len = derived_key_len;
  96. unsigned char c[4];
  97. unsigned char mac[EVP_MAX_MD_SIZE];
  98. unsigned char *out = derived_key;
  99. EVP_MD_CTX *ctx = NULL, *ctx_init = NULL;
  100. if (z_len > SSKDF_MAX_INLEN || info_len > SSKDF_MAX_INLEN
  101. || derived_key_len > SSKDF_MAX_INLEN
  102. || derived_key_len == 0)
  103. return 0;
  104. hlen = EVP_MD_get_size(kdf_md);
  105. if (hlen <= 0)
  106. return 0;
  107. out_len = (size_t)hlen;
  108. ctx = EVP_MD_CTX_create();
  109. ctx_init = EVP_MD_CTX_create();
  110. if (ctx == NULL || ctx_init == NULL)
  111. goto end;
  112. if (!EVP_DigestInit(ctx_init, kdf_md))
  113. goto end;
  114. for (counter = 1;; counter++) {
  115. c[0] = (unsigned char)((counter >> 24) & 0xff);
  116. c[1] = (unsigned char)((counter >> 16) & 0xff);
  117. c[2] = (unsigned char)((counter >> 8) & 0xff);
  118. c[3] = (unsigned char)(counter & 0xff);
  119. if (!(EVP_MD_CTX_copy_ex(ctx, ctx_init)
  120. && (append_ctr || EVP_DigestUpdate(ctx, c, sizeof(c)))
  121. && EVP_DigestUpdate(ctx, z, z_len)
  122. && (!append_ctr || EVP_DigestUpdate(ctx, c, sizeof(c)))
  123. && EVP_DigestUpdate(ctx, info, info_len)))
  124. goto end;
  125. if (len >= out_len) {
  126. if (!EVP_DigestFinal_ex(ctx, out, NULL))
  127. goto end;
  128. out += out_len;
  129. len -= out_len;
  130. if (len == 0)
  131. break;
  132. } else {
  133. if (!EVP_DigestFinal_ex(ctx, mac, NULL))
  134. goto end;
  135. memcpy(out, mac, len);
  136. break;
  137. }
  138. }
  139. ret = 1;
  140. end:
  141. EVP_MD_CTX_destroy(ctx);
  142. EVP_MD_CTX_destroy(ctx_init);
  143. OPENSSL_cleanse(mac, sizeof(mac));
  144. return ret;
  145. }
  146. static int kmac_init(EVP_MAC_CTX *ctx, const unsigned char *custom,
  147. size_t custom_len, size_t kmac_out_len,
  148. size_t derived_key_len, unsigned char **out)
  149. {
  150. OSSL_PARAM params[2];
  151. /* Only KMAC has custom data - so return if not KMAC */
  152. if (custom == NULL)
  153. return 1;
  154. params[0] = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_CUSTOM,
  155. (void *)custom, custom_len);
  156. params[1] = OSSL_PARAM_construct_end();
  157. if (!EVP_MAC_CTX_set_params(ctx, params))
  158. return 0;
  159. /* By default only do one iteration if kmac_out_len is not specified */
  160. if (kmac_out_len == 0)
  161. kmac_out_len = derived_key_len;
  162. /* otherwise check the size is valid */
  163. else if (!(kmac_out_len == derived_key_len
  164. || kmac_out_len == 20
  165. || kmac_out_len == 28
  166. || kmac_out_len == 32
  167. || kmac_out_len == 48
  168. || kmac_out_len == 64))
  169. return 0;
  170. params[0] = OSSL_PARAM_construct_size_t(OSSL_MAC_PARAM_SIZE,
  171. &kmac_out_len);
  172. if (EVP_MAC_CTX_set_params(ctx, params) <= 0)
  173. return 0;
  174. /*
  175. * For kmac the output buffer can be larger than EVP_MAX_MD_SIZE: so
  176. * alloc a buffer for this case.
  177. */
  178. if (kmac_out_len > EVP_MAX_MD_SIZE) {
  179. *out = OPENSSL_zalloc(kmac_out_len);
  180. if (*out == NULL)
  181. return 0;
  182. }
  183. return 1;
  184. }
  185. /*
  186. * Refer to https://csrc.nist.gov/publications/detail/sp/800-56c/rev-1/final
  187. * Section 4. One-Step Key Derivation using MAC: i.e either
  188. * H(x) = HMAC-hash(salt, x) OR
  189. * H(x) = KMAC#(salt, x, outbits, CustomString='KDF')
  190. */
  191. static int SSKDF_mac_kdm(EVP_MAC_CTX *ctx_init,
  192. const unsigned char *kmac_custom,
  193. size_t kmac_custom_len, size_t kmac_out_len,
  194. const unsigned char *salt, size_t salt_len,
  195. const unsigned char *z, size_t z_len,
  196. const unsigned char *info, size_t info_len,
  197. unsigned char *derived_key, size_t derived_key_len)
  198. {
  199. int ret = 0;
  200. size_t counter, out_len, len;
  201. unsigned char c[4];
  202. unsigned char mac_buf[EVP_MAX_MD_SIZE];
  203. unsigned char *out = derived_key;
  204. EVP_MAC_CTX *ctx = NULL;
  205. unsigned char *mac = mac_buf, *kmac_buffer = NULL;
  206. if (z_len > SSKDF_MAX_INLEN || info_len > SSKDF_MAX_INLEN
  207. || derived_key_len > SSKDF_MAX_INLEN
  208. || derived_key_len == 0)
  209. return 0;
  210. if (!kmac_init(ctx_init, kmac_custom, kmac_custom_len, kmac_out_len,
  211. derived_key_len, &kmac_buffer))
  212. goto end;
  213. if (kmac_buffer != NULL)
  214. mac = kmac_buffer;
  215. if (!EVP_MAC_init(ctx_init, salt, salt_len, NULL))
  216. goto end;
  217. out_len = EVP_MAC_CTX_get_mac_size(ctx_init); /* output size */
  218. if (out_len <= 0 || (mac == mac_buf && out_len > sizeof(mac_buf)))
  219. goto end;
  220. len = derived_key_len;
  221. for (counter = 1;; counter++) {
  222. c[0] = (unsigned char)((counter >> 24) & 0xff);
  223. c[1] = (unsigned char)((counter >> 16) & 0xff);
  224. c[2] = (unsigned char)((counter >> 8) & 0xff);
  225. c[3] = (unsigned char)(counter & 0xff);
  226. ctx = EVP_MAC_CTX_dup(ctx_init);
  227. if (!(ctx != NULL
  228. && EVP_MAC_update(ctx, c, sizeof(c))
  229. && EVP_MAC_update(ctx, z, z_len)
  230. && EVP_MAC_update(ctx, info, info_len)))
  231. goto end;
  232. if (len >= out_len) {
  233. if (!EVP_MAC_final(ctx, out, NULL, len))
  234. goto end;
  235. out += out_len;
  236. len -= out_len;
  237. if (len == 0)
  238. break;
  239. } else {
  240. if (!EVP_MAC_final(ctx, mac, NULL, out_len))
  241. goto end;
  242. memcpy(out, mac, len);
  243. break;
  244. }
  245. EVP_MAC_CTX_free(ctx);
  246. ctx = NULL;
  247. }
  248. ret = 1;
  249. end:
  250. if (kmac_buffer != NULL)
  251. OPENSSL_clear_free(kmac_buffer, kmac_out_len);
  252. else
  253. OPENSSL_cleanse(mac_buf, sizeof(mac_buf));
  254. EVP_MAC_CTX_free(ctx);
  255. return ret;
  256. }
  257. static void *sskdf_new(void *provctx)
  258. {
  259. KDF_SSKDF *ctx;
  260. if (!ossl_prov_is_running())
  261. return NULL;
  262. if ((ctx = OPENSSL_zalloc(sizeof(*ctx))) == NULL)
  263. ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
  264. ctx->provctx = provctx;
  265. return ctx;
  266. }
  267. static void sskdf_reset(void *vctx)
  268. {
  269. KDF_SSKDF *ctx = (KDF_SSKDF *)vctx;
  270. void *provctx = ctx->provctx;
  271. EVP_MAC_CTX_free(ctx->macctx);
  272. ossl_prov_digest_reset(&ctx->digest);
  273. OPENSSL_clear_free(ctx->secret, ctx->secret_len);
  274. OPENSSL_clear_free(ctx->info, ctx->info_len);
  275. OPENSSL_clear_free(ctx->salt, ctx->salt_len);
  276. memset(ctx, 0, sizeof(*ctx));
  277. ctx->provctx = provctx;
  278. }
  279. static void sskdf_free(void *vctx)
  280. {
  281. KDF_SSKDF *ctx = (KDF_SSKDF *)vctx;
  282. if (ctx != NULL) {
  283. sskdf_reset(ctx);
  284. OPENSSL_free(ctx);
  285. }
  286. }
  287. static void *sskdf_dup(void *vctx)
  288. {
  289. const KDF_SSKDF *src = (const KDF_SSKDF *)vctx;
  290. KDF_SSKDF *dest;
  291. dest = sskdf_new(src->provctx);
  292. if (dest != NULL) {
  293. if (src->macctx != NULL) {
  294. dest->macctx = EVP_MAC_CTX_dup(src->macctx);
  295. if (dest->macctx == NULL)
  296. goto err;
  297. }
  298. if (!ossl_prov_memdup(src->info, src->info_len,
  299. &dest->info, &dest->info_len)
  300. || !ossl_prov_memdup(src->salt, src->salt_len,
  301. &dest->salt , &dest->salt_len)
  302. || !ossl_prov_memdup(src->secret, src->secret_len,
  303. &dest->secret, &dest->secret_len)
  304. || !ossl_prov_digest_copy(&dest->digest, &src->digest))
  305. goto err;
  306. dest->out_len = src->out_len;
  307. }
  308. return dest;
  309. err:
  310. sskdf_free(dest);
  311. return NULL;
  312. }
  313. static int sskdf_set_buffer(unsigned char **out, size_t *out_len,
  314. const OSSL_PARAM *p)
  315. {
  316. if (p->data == NULL || p->data_size == 0)
  317. return 1;
  318. OPENSSL_free(*out);
  319. *out = NULL;
  320. return OSSL_PARAM_get_octet_string(p, (void **)out, 0, out_len);
  321. }
  322. static size_t sskdf_size(KDF_SSKDF *ctx)
  323. {
  324. int len;
  325. const EVP_MD *md = ossl_prov_digest_md(&ctx->digest);
  326. if (md == NULL) {
  327. ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
  328. return 0;
  329. }
  330. len = EVP_MD_get_size(md);
  331. return (len <= 0) ? 0 : (size_t)len;
  332. }
  333. static int sskdf_derive(void *vctx, unsigned char *key, size_t keylen,
  334. const OSSL_PARAM params[])
  335. {
  336. KDF_SSKDF *ctx = (KDF_SSKDF *)vctx;
  337. const EVP_MD *md;
  338. if (!ossl_prov_is_running() || !sskdf_set_ctx_params(ctx, params))
  339. return 0;
  340. if (ctx->secret == NULL) {
  341. ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_SECRET);
  342. return 0;
  343. }
  344. md = ossl_prov_digest_md(&ctx->digest);
  345. if (ctx->macctx != NULL) {
  346. /* H(x) = KMAC or H(x) = HMAC */
  347. int ret;
  348. const unsigned char *custom = NULL;
  349. size_t custom_len = 0;
  350. int default_salt_len;
  351. EVP_MAC *mac = EVP_MAC_CTX_get0_mac(ctx->macctx);
  352. if (EVP_MAC_is_a(mac, OSSL_MAC_NAME_HMAC)) {
  353. /* H(x) = HMAC(x, salt, hash) */
  354. if (md == NULL) {
  355. ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
  356. return 0;
  357. }
  358. default_salt_len = EVP_MD_get_size(md);
  359. if (default_salt_len <= 0)
  360. return 0;
  361. } else if (EVP_MAC_is_a(mac, OSSL_MAC_NAME_KMAC128)
  362. || EVP_MAC_is_a(mac, OSSL_MAC_NAME_KMAC256)) {
  363. /* H(x) = KMACzzz(x, salt, custom) */
  364. custom = kmac_custom_str;
  365. custom_len = sizeof(kmac_custom_str);
  366. if (EVP_MAC_is_a(mac, OSSL_MAC_NAME_KMAC128))
  367. default_salt_len = SSKDF_KMAC128_DEFAULT_SALT_SIZE;
  368. else
  369. default_salt_len = SSKDF_KMAC256_DEFAULT_SALT_SIZE;
  370. } else {
  371. ERR_raise(ERR_LIB_PROV, PROV_R_UNSUPPORTED_MAC_TYPE);
  372. return 0;
  373. }
  374. /* If no salt is set then use a default_salt of zeros */
  375. if (ctx->salt == NULL || ctx->salt_len <= 0) {
  376. ctx->salt = OPENSSL_zalloc(default_salt_len);
  377. if (ctx->salt == NULL) {
  378. ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
  379. return 0;
  380. }
  381. ctx->salt_len = default_salt_len;
  382. }
  383. ret = SSKDF_mac_kdm(ctx->macctx,
  384. custom, custom_len, ctx->out_len,
  385. ctx->salt, ctx->salt_len,
  386. ctx->secret, ctx->secret_len,
  387. ctx->info, ctx->info_len, key, keylen);
  388. return ret;
  389. } else {
  390. /* H(x) = hash */
  391. if (md == NULL) {
  392. ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
  393. return 0;
  394. }
  395. return SSKDF_hash_kdm(md, ctx->secret, ctx->secret_len,
  396. ctx->info, ctx->info_len, 0, key, keylen);
  397. }
  398. }
  399. static int x963kdf_derive(void *vctx, unsigned char *key, size_t keylen,
  400. const OSSL_PARAM params[])
  401. {
  402. KDF_SSKDF *ctx = (KDF_SSKDF *)vctx;
  403. const EVP_MD *md;
  404. if (!ossl_prov_is_running() || !sskdf_set_ctx_params(ctx, params))
  405. return 0;
  406. if (ctx->secret == NULL) {
  407. ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_SECRET);
  408. return 0;
  409. }
  410. if (ctx->macctx != NULL) {
  411. ERR_raise(ERR_LIB_PROV, PROV_R_NOT_SUPPORTED);
  412. return 0;
  413. }
  414. /* H(x) = hash */
  415. md = ossl_prov_digest_md(&ctx->digest);
  416. if (md == NULL) {
  417. ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
  418. return 0;
  419. }
  420. return SSKDF_hash_kdm(md, ctx->secret, ctx->secret_len,
  421. ctx->info, ctx->info_len, 1, key, keylen);
  422. }
  423. static int sskdf_set_ctx_params(void *vctx, const OSSL_PARAM params[])
  424. {
  425. const OSSL_PARAM *p;
  426. KDF_SSKDF *ctx = vctx;
  427. OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx);
  428. size_t sz;
  429. if (params == NULL)
  430. return 1;
  431. if (!ossl_prov_digest_load_from_params(&ctx->digest, params, libctx))
  432. return 0;
  433. if (!ossl_prov_macctx_load_from_params(&ctx->macctx, params,
  434. NULL, NULL, NULL, libctx))
  435. return 0;
  436. if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SECRET)) != NULL
  437. || (p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_KEY)) != NULL)
  438. if (!sskdf_set_buffer(&ctx->secret, &ctx->secret_len, p))
  439. return 0;
  440. if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_INFO)) != NULL)
  441. if (!sskdf_set_buffer(&ctx->info, &ctx->info_len, p))
  442. return 0;
  443. if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SALT)) != NULL)
  444. if (!sskdf_set_buffer(&ctx->salt, &ctx->salt_len, p))
  445. return 0;
  446. if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_MAC_SIZE))
  447. != NULL) {
  448. if (!OSSL_PARAM_get_size_t(p, &sz) || sz == 0)
  449. return 0;
  450. ctx->out_len = sz;
  451. }
  452. return 1;
  453. }
  454. static const OSSL_PARAM *sskdf_settable_ctx_params(ossl_unused void *ctx,
  455. ossl_unused void *provctx)
  456. {
  457. static const OSSL_PARAM known_settable_ctx_params[] = {
  458. OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SECRET, NULL, 0),
  459. OSSL_PARAM_octet_string(OSSL_KDF_PARAM_KEY, NULL, 0),
  460. OSSL_PARAM_octet_string(OSSL_KDF_PARAM_INFO, NULL, 0),
  461. OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_PROPERTIES, NULL, 0),
  462. OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_DIGEST, NULL, 0),
  463. OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_MAC, NULL, 0),
  464. OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SALT, NULL, 0),
  465. OSSL_PARAM_size_t(OSSL_KDF_PARAM_MAC_SIZE, NULL),
  466. OSSL_PARAM_END
  467. };
  468. return known_settable_ctx_params;
  469. }
  470. static int sskdf_get_ctx_params(void *vctx, OSSL_PARAM params[])
  471. {
  472. KDF_SSKDF *ctx = (KDF_SSKDF *)vctx;
  473. OSSL_PARAM *p;
  474. if ((p = OSSL_PARAM_locate(params, OSSL_KDF_PARAM_SIZE)) != NULL)
  475. return OSSL_PARAM_set_size_t(p, sskdf_size(ctx));
  476. return -2;
  477. }
  478. static const OSSL_PARAM *sskdf_gettable_ctx_params(ossl_unused void *ctx,
  479. ossl_unused void *provctx)
  480. {
  481. static const OSSL_PARAM known_gettable_ctx_params[] = {
  482. OSSL_PARAM_size_t(OSSL_KDF_PARAM_SIZE, NULL),
  483. OSSL_PARAM_END
  484. };
  485. return known_gettable_ctx_params;
  486. }
  487. const OSSL_DISPATCH ossl_kdf_sskdf_functions[] = {
  488. { OSSL_FUNC_KDF_NEWCTX, (void(*)(void))sskdf_new },
  489. { OSSL_FUNC_KDF_DUPCTX, (void(*)(void))sskdf_dup },
  490. { OSSL_FUNC_KDF_FREECTX, (void(*)(void))sskdf_free },
  491. { OSSL_FUNC_KDF_RESET, (void(*)(void))sskdf_reset },
  492. { OSSL_FUNC_KDF_DERIVE, (void(*)(void))sskdf_derive },
  493. { OSSL_FUNC_KDF_SETTABLE_CTX_PARAMS,
  494. (void(*)(void))sskdf_settable_ctx_params },
  495. { OSSL_FUNC_KDF_SET_CTX_PARAMS, (void(*)(void))sskdf_set_ctx_params },
  496. { OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS,
  497. (void(*)(void))sskdf_gettable_ctx_params },
  498. { OSSL_FUNC_KDF_GET_CTX_PARAMS, (void(*)(void))sskdf_get_ctx_params },
  499. { 0, NULL }
  500. };
  501. const OSSL_DISPATCH ossl_kdf_x963_kdf_functions[] = {
  502. { OSSL_FUNC_KDF_NEWCTX, (void(*)(void))sskdf_new },
  503. { OSSL_FUNC_KDF_DUPCTX, (void(*)(void))sskdf_dup },
  504. { OSSL_FUNC_KDF_FREECTX, (void(*)(void))sskdf_free },
  505. { OSSL_FUNC_KDF_RESET, (void(*)(void))sskdf_reset },
  506. { OSSL_FUNC_KDF_DERIVE, (void(*)(void))x963kdf_derive },
  507. { OSSL_FUNC_KDF_SETTABLE_CTX_PARAMS,
  508. (void(*)(void))sskdf_settable_ctx_params },
  509. { OSSL_FUNC_KDF_SET_CTX_PARAMS, (void(*)(void))sskdf_set_ctx_params },
  510. { OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS,
  511. (void(*)(void))sskdf_gettable_ctx_params },
  512. { OSSL_FUNC_KDF_GET_CTX_PARAMS, (void(*)(void))sskdf_get_ctx_params },
  513. { 0, NULL }
  514. };