scrypt.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. /*
  2. * Copyright 2017-2023 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 <stdlib.h>
  10. #include <stdarg.h>
  11. #include <string.h>
  12. #include <openssl/evp.h>
  13. #include <openssl/kdf.h>
  14. #include <openssl/err.h>
  15. #include <openssl/core_names.h>
  16. #include <openssl/proverr.h>
  17. #include "crypto/evp.h"
  18. #include "internal/numbers.h"
  19. #include "prov/implementations.h"
  20. #include "prov/provider_ctx.h"
  21. #include "prov/providercommon.h"
  22. #include "prov/provider_util.h"
  23. #ifndef OPENSSL_NO_SCRYPT
  24. static OSSL_FUNC_kdf_newctx_fn kdf_scrypt_new;
  25. static OSSL_FUNC_kdf_dupctx_fn kdf_scrypt_dup;
  26. static OSSL_FUNC_kdf_freectx_fn kdf_scrypt_free;
  27. static OSSL_FUNC_kdf_reset_fn kdf_scrypt_reset;
  28. static OSSL_FUNC_kdf_derive_fn kdf_scrypt_derive;
  29. static OSSL_FUNC_kdf_settable_ctx_params_fn kdf_scrypt_settable_ctx_params;
  30. static OSSL_FUNC_kdf_set_ctx_params_fn kdf_scrypt_set_ctx_params;
  31. static OSSL_FUNC_kdf_gettable_ctx_params_fn kdf_scrypt_gettable_ctx_params;
  32. static OSSL_FUNC_kdf_get_ctx_params_fn kdf_scrypt_get_ctx_params;
  33. static int scrypt_alg(const char *pass, size_t passlen,
  34. const unsigned char *salt, size_t saltlen,
  35. uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem,
  36. unsigned char *key, size_t keylen, EVP_MD *sha256,
  37. OSSL_LIB_CTX *libctx, const char *propq);
  38. typedef struct {
  39. OSSL_LIB_CTX *libctx;
  40. char *propq;
  41. unsigned char *pass;
  42. size_t pass_len;
  43. unsigned char *salt;
  44. size_t salt_len;
  45. uint64_t N;
  46. uint64_t r, p;
  47. uint64_t maxmem_bytes;
  48. EVP_MD *sha256;
  49. } KDF_SCRYPT;
  50. static void kdf_scrypt_init(KDF_SCRYPT *ctx);
  51. static void *kdf_scrypt_new_inner(OSSL_LIB_CTX *libctx)
  52. {
  53. KDF_SCRYPT *ctx;
  54. if (!ossl_prov_is_running())
  55. return NULL;
  56. ctx = OPENSSL_zalloc(sizeof(*ctx));
  57. if (ctx == NULL)
  58. return NULL;
  59. ctx->libctx = libctx;
  60. kdf_scrypt_init(ctx);
  61. return ctx;
  62. }
  63. static void *kdf_scrypt_new(void *provctx)
  64. {
  65. return kdf_scrypt_new_inner(PROV_LIBCTX_OF(provctx));
  66. }
  67. static void kdf_scrypt_free(void *vctx)
  68. {
  69. KDF_SCRYPT *ctx = (KDF_SCRYPT *)vctx;
  70. if (ctx != NULL) {
  71. OPENSSL_free(ctx->propq);
  72. EVP_MD_free(ctx->sha256);
  73. kdf_scrypt_reset(ctx);
  74. OPENSSL_free(ctx);
  75. }
  76. }
  77. static void kdf_scrypt_reset(void *vctx)
  78. {
  79. KDF_SCRYPT *ctx = (KDF_SCRYPT *)vctx;
  80. OPENSSL_free(ctx->salt);
  81. OPENSSL_clear_free(ctx->pass, ctx->pass_len);
  82. kdf_scrypt_init(ctx);
  83. }
  84. static void *kdf_scrypt_dup(void *vctx)
  85. {
  86. const KDF_SCRYPT *src = (const KDF_SCRYPT *)vctx;
  87. KDF_SCRYPT *dest;
  88. dest = kdf_scrypt_new_inner(src->libctx);
  89. if (dest != NULL) {
  90. if (src->sha256 != NULL && !EVP_MD_up_ref(src->sha256))
  91. goto err;
  92. if (src->propq != NULL) {
  93. dest->propq = OPENSSL_strdup(src->propq);
  94. if (dest->propq == NULL)
  95. goto err;
  96. }
  97. if (!ossl_prov_memdup(src->salt, src->salt_len,
  98. &dest->salt, &dest->salt_len)
  99. || !ossl_prov_memdup(src->pass, src->pass_len,
  100. &dest->pass , &dest->pass_len))
  101. goto err;
  102. dest->N = src->N;
  103. dest->r = src->r;
  104. dest->p = src->p;
  105. dest->maxmem_bytes = src->maxmem_bytes;
  106. dest->sha256 = src->sha256;
  107. }
  108. return dest;
  109. err:
  110. kdf_scrypt_free(dest);
  111. return NULL;
  112. }
  113. static void kdf_scrypt_init(KDF_SCRYPT *ctx)
  114. {
  115. /* Default values are the most conservative recommendation given in the
  116. * original paper of C. Percival. Derivation uses roughly 1 GiB of memory
  117. * for this parameter choice (approx. 128 * r * N * p bytes).
  118. */
  119. ctx->N = 1 << 20;
  120. ctx->r = 8;
  121. ctx->p = 1;
  122. ctx->maxmem_bytes = 1025 * 1024 * 1024;
  123. }
  124. static int scrypt_set_membuf(unsigned char **buffer, size_t *buflen,
  125. const OSSL_PARAM *p)
  126. {
  127. OPENSSL_clear_free(*buffer, *buflen);
  128. *buffer = NULL;
  129. *buflen = 0;
  130. if (p->data_size == 0) {
  131. if ((*buffer = OPENSSL_malloc(1)) == NULL)
  132. return 0;
  133. } else if (p->data != NULL) {
  134. if (!OSSL_PARAM_get_octet_string(p, (void **)buffer, 0, buflen))
  135. return 0;
  136. }
  137. return 1;
  138. }
  139. static int set_digest(KDF_SCRYPT *ctx)
  140. {
  141. EVP_MD_free(ctx->sha256);
  142. ctx->sha256 = EVP_MD_fetch(ctx->libctx, "sha256", ctx->propq);
  143. if (ctx->sha256 == NULL) {
  144. OPENSSL_free(ctx);
  145. ERR_raise(ERR_LIB_PROV, PROV_R_UNABLE_TO_LOAD_SHA256);
  146. return 0;
  147. }
  148. return 1;
  149. }
  150. static int set_property_query(KDF_SCRYPT *ctx, const char *propq)
  151. {
  152. OPENSSL_free(ctx->propq);
  153. ctx->propq = NULL;
  154. if (propq != NULL) {
  155. ctx->propq = OPENSSL_strdup(propq);
  156. if (ctx->propq == NULL)
  157. return 0;
  158. }
  159. return 1;
  160. }
  161. static int kdf_scrypt_derive(void *vctx, unsigned char *key, size_t keylen,
  162. const OSSL_PARAM params[])
  163. {
  164. KDF_SCRYPT *ctx = (KDF_SCRYPT *)vctx;
  165. if (!ossl_prov_is_running() || !kdf_scrypt_set_ctx_params(ctx, params))
  166. return 0;
  167. if (ctx->pass == NULL) {
  168. ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_PASS);
  169. return 0;
  170. }
  171. if (ctx->salt == NULL) {
  172. ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_SALT);
  173. return 0;
  174. }
  175. if (ctx->sha256 == NULL && !set_digest(ctx))
  176. return 0;
  177. return scrypt_alg((char *)ctx->pass, ctx->pass_len, ctx->salt,
  178. ctx->salt_len, ctx->N, ctx->r, ctx->p,
  179. ctx->maxmem_bytes, key, keylen, ctx->sha256,
  180. ctx->libctx, ctx->propq);
  181. }
  182. static int is_power_of_two(uint64_t value)
  183. {
  184. return (value != 0) && ((value & (value - 1)) == 0);
  185. }
  186. static int kdf_scrypt_set_ctx_params(void *vctx, const OSSL_PARAM params[])
  187. {
  188. const OSSL_PARAM *p;
  189. KDF_SCRYPT *ctx = vctx;
  190. uint64_t u64_value;
  191. if (params == NULL)
  192. return 1;
  193. if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_PASSWORD)) != NULL)
  194. if (!scrypt_set_membuf(&ctx->pass, &ctx->pass_len, p))
  195. return 0;
  196. if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SALT)) != NULL)
  197. if (!scrypt_set_membuf(&ctx->salt, &ctx->salt_len, p))
  198. return 0;
  199. if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SCRYPT_N))
  200. != NULL) {
  201. if (!OSSL_PARAM_get_uint64(p, &u64_value)
  202. || u64_value <= 1
  203. || !is_power_of_two(u64_value))
  204. return 0;
  205. ctx->N = u64_value;
  206. }
  207. if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SCRYPT_R))
  208. != NULL) {
  209. if (!OSSL_PARAM_get_uint64(p, &u64_value) || u64_value < 1)
  210. return 0;
  211. ctx->r = u64_value;
  212. }
  213. if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SCRYPT_P))
  214. != NULL) {
  215. if (!OSSL_PARAM_get_uint64(p, &u64_value) || u64_value < 1)
  216. return 0;
  217. ctx->p = u64_value;
  218. }
  219. if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SCRYPT_MAXMEM))
  220. != NULL) {
  221. if (!OSSL_PARAM_get_uint64(p, &u64_value) || u64_value < 1)
  222. return 0;
  223. ctx->maxmem_bytes = u64_value;
  224. }
  225. p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_PROPERTIES);
  226. if (p != NULL) {
  227. if (p->data_type != OSSL_PARAM_UTF8_STRING
  228. || !set_property_query(ctx, p->data)
  229. || !set_digest(ctx))
  230. return 0;
  231. }
  232. return 1;
  233. }
  234. static const OSSL_PARAM *kdf_scrypt_settable_ctx_params(ossl_unused void *ctx,
  235. ossl_unused void *p_ctx)
  236. {
  237. static const OSSL_PARAM known_settable_ctx_params[] = {
  238. OSSL_PARAM_octet_string(OSSL_KDF_PARAM_PASSWORD, NULL, 0),
  239. OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SALT, NULL, 0),
  240. OSSL_PARAM_uint64(OSSL_KDF_PARAM_SCRYPT_N, NULL),
  241. OSSL_PARAM_uint32(OSSL_KDF_PARAM_SCRYPT_R, NULL),
  242. OSSL_PARAM_uint32(OSSL_KDF_PARAM_SCRYPT_P, NULL),
  243. OSSL_PARAM_uint64(OSSL_KDF_PARAM_SCRYPT_MAXMEM, NULL),
  244. OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_PROPERTIES, NULL, 0),
  245. OSSL_PARAM_END
  246. };
  247. return known_settable_ctx_params;
  248. }
  249. static int kdf_scrypt_get_ctx_params(void *vctx, OSSL_PARAM params[])
  250. {
  251. OSSL_PARAM *p;
  252. if ((p = OSSL_PARAM_locate(params, OSSL_KDF_PARAM_SIZE)) != NULL)
  253. return OSSL_PARAM_set_size_t(p, SIZE_MAX);
  254. return -2;
  255. }
  256. static const OSSL_PARAM *kdf_scrypt_gettable_ctx_params(ossl_unused void *ctx,
  257. ossl_unused void *p_ctx)
  258. {
  259. static const OSSL_PARAM known_gettable_ctx_params[] = {
  260. OSSL_PARAM_size_t(OSSL_KDF_PARAM_SIZE, NULL),
  261. OSSL_PARAM_END
  262. };
  263. return known_gettable_ctx_params;
  264. }
  265. const OSSL_DISPATCH ossl_kdf_scrypt_functions[] = {
  266. { OSSL_FUNC_KDF_NEWCTX, (void(*)(void))kdf_scrypt_new },
  267. { OSSL_FUNC_KDF_DUPCTX, (void(*)(void))kdf_scrypt_dup },
  268. { OSSL_FUNC_KDF_FREECTX, (void(*)(void))kdf_scrypt_free },
  269. { OSSL_FUNC_KDF_RESET, (void(*)(void))kdf_scrypt_reset },
  270. { OSSL_FUNC_KDF_DERIVE, (void(*)(void))kdf_scrypt_derive },
  271. { OSSL_FUNC_KDF_SETTABLE_CTX_PARAMS,
  272. (void(*)(void))kdf_scrypt_settable_ctx_params },
  273. { OSSL_FUNC_KDF_SET_CTX_PARAMS, (void(*)(void))kdf_scrypt_set_ctx_params },
  274. { OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS,
  275. (void(*)(void))kdf_scrypt_gettable_ctx_params },
  276. { OSSL_FUNC_KDF_GET_CTX_PARAMS, (void(*)(void))kdf_scrypt_get_ctx_params },
  277. OSSL_DISPATCH_END
  278. };
  279. #define R(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
  280. static void salsa208_word_specification(uint32_t inout[16])
  281. {
  282. int i;
  283. uint32_t x[16];
  284. memcpy(x, inout, sizeof(x));
  285. for (i = 8; i > 0; i -= 2) {
  286. x[4] ^= R(x[0] + x[12], 7);
  287. x[8] ^= R(x[4] + x[0], 9);
  288. x[12] ^= R(x[8] + x[4], 13);
  289. x[0] ^= R(x[12] + x[8], 18);
  290. x[9] ^= R(x[5] + x[1], 7);
  291. x[13] ^= R(x[9] + x[5], 9);
  292. x[1] ^= R(x[13] + x[9], 13);
  293. x[5] ^= R(x[1] + x[13], 18);
  294. x[14] ^= R(x[10] + x[6], 7);
  295. x[2] ^= R(x[14] + x[10], 9);
  296. x[6] ^= R(x[2] + x[14], 13);
  297. x[10] ^= R(x[6] + x[2], 18);
  298. x[3] ^= R(x[15] + x[11], 7);
  299. x[7] ^= R(x[3] + x[15], 9);
  300. x[11] ^= R(x[7] + x[3], 13);
  301. x[15] ^= R(x[11] + x[7], 18);
  302. x[1] ^= R(x[0] + x[3], 7);
  303. x[2] ^= R(x[1] + x[0], 9);
  304. x[3] ^= R(x[2] + x[1], 13);
  305. x[0] ^= R(x[3] + x[2], 18);
  306. x[6] ^= R(x[5] + x[4], 7);
  307. x[7] ^= R(x[6] + x[5], 9);
  308. x[4] ^= R(x[7] + x[6], 13);
  309. x[5] ^= R(x[4] + x[7], 18);
  310. x[11] ^= R(x[10] + x[9], 7);
  311. x[8] ^= R(x[11] + x[10], 9);
  312. x[9] ^= R(x[8] + x[11], 13);
  313. x[10] ^= R(x[9] + x[8], 18);
  314. x[12] ^= R(x[15] + x[14], 7);
  315. x[13] ^= R(x[12] + x[15], 9);
  316. x[14] ^= R(x[13] + x[12], 13);
  317. x[15] ^= R(x[14] + x[13], 18);
  318. }
  319. for (i = 0; i < 16; ++i)
  320. inout[i] += x[i];
  321. OPENSSL_cleanse(x, sizeof(x));
  322. }
  323. static void scryptBlockMix(uint32_t *B_, uint32_t *B, uint64_t r)
  324. {
  325. uint64_t i, j;
  326. uint32_t X[16], *pB;
  327. memcpy(X, B + (r * 2 - 1) * 16, sizeof(X));
  328. pB = B;
  329. for (i = 0; i < r * 2; i++) {
  330. for (j = 0; j < 16; j++)
  331. X[j] ^= *pB++;
  332. salsa208_word_specification(X);
  333. memcpy(B_ + (i / 2 + (i & 1) * r) * 16, X, sizeof(X));
  334. }
  335. OPENSSL_cleanse(X, sizeof(X));
  336. }
  337. static void scryptROMix(unsigned char *B, uint64_t r, uint64_t N,
  338. uint32_t *X, uint32_t *T, uint32_t *V)
  339. {
  340. unsigned char *pB;
  341. uint32_t *pV;
  342. uint64_t i, k;
  343. /* Convert from little endian input */
  344. for (pV = V, i = 0, pB = B; i < 32 * r; i++, pV++) {
  345. *pV = *pB++;
  346. *pV |= *pB++ << 8;
  347. *pV |= *pB++ << 16;
  348. *pV |= (uint32_t)*pB++ << 24;
  349. }
  350. for (i = 1; i < N; i++, pV += 32 * r)
  351. scryptBlockMix(pV, pV - 32 * r, r);
  352. scryptBlockMix(X, V + (N - 1) * 32 * r, r);
  353. for (i = 0; i < N; i++) {
  354. uint32_t j;
  355. j = X[16 * (2 * r - 1)] % N;
  356. pV = V + 32 * r * j;
  357. for (k = 0; k < 32 * r; k++)
  358. T[k] = X[k] ^ *pV++;
  359. scryptBlockMix(X, T, r);
  360. }
  361. /* Convert output to little endian */
  362. for (i = 0, pB = B; i < 32 * r; i++) {
  363. uint32_t xtmp = X[i];
  364. *pB++ = xtmp & 0xff;
  365. *pB++ = (xtmp >> 8) & 0xff;
  366. *pB++ = (xtmp >> 16) & 0xff;
  367. *pB++ = (xtmp >> 24) & 0xff;
  368. }
  369. }
  370. #ifndef SIZE_MAX
  371. # define SIZE_MAX ((size_t)-1)
  372. #endif
  373. /*
  374. * Maximum power of two that will fit in uint64_t: this should work on
  375. * most (all?) platforms.
  376. */
  377. #define LOG2_UINT64_MAX (sizeof(uint64_t) * 8 - 1)
  378. /*
  379. * Maximum value of p * r:
  380. * p <= ((2^32-1) * hLen) / MFLen =>
  381. * p <= ((2^32-1) * 32) / (128 * r) =>
  382. * p * r <= (2^30-1)
  383. */
  384. #define SCRYPT_PR_MAX ((1 << 30) - 1)
  385. static int scrypt_alg(const char *pass, size_t passlen,
  386. const unsigned char *salt, size_t saltlen,
  387. uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem,
  388. unsigned char *key, size_t keylen, EVP_MD *sha256,
  389. OSSL_LIB_CTX *libctx, const char *propq)
  390. {
  391. int rv = 0;
  392. unsigned char *B;
  393. uint32_t *X, *V, *T;
  394. uint64_t i, Blen, Vlen;
  395. /* Sanity check parameters */
  396. /* initial check, r,p must be non zero, N >= 2 and a power of 2 */
  397. if (r == 0 || p == 0 || N < 2 || (N & (N - 1)))
  398. return 0;
  399. /* Check p * r < SCRYPT_PR_MAX avoiding overflow */
  400. if (p > SCRYPT_PR_MAX / r) {
  401. ERR_raise(ERR_LIB_EVP, EVP_R_MEMORY_LIMIT_EXCEEDED);
  402. return 0;
  403. }
  404. /*
  405. * Need to check N: if 2^(128 * r / 8) overflows limit this is
  406. * automatically satisfied since N <= UINT64_MAX.
  407. */
  408. if (16 * r <= LOG2_UINT64_MAX) {
  409. if (N >= (((uint64_t)1) << (16 * r))) {
  410. ERR_raise(ERR_LIB_EVP, EVP_R_MEMORY_LIMIT_EXCEEDED);
  411. return 0;
  412. }
  413. }
  414. /* Memory checks: check total allocated buffer size fits in uint64_t */
  415. /*
  416. * B size in section 5 step 1.S
  417. * Note: we know p * 128 * r < UINT64_MAX because we already checked
  418. * p * r < SCRYPT_PR_MAX
  419. */
  420. Blen = p * 128 * r;
  421. /*
  422. * Yet we pass it as integer to PKCS5_PBKDF2_HMAC... [This would
  423. * have to be revised when/if PKCS5_PBKDF2_HMAC accepts size_t.]
  424. */
  425. if (Blen > INT_MAX) {
  426. ERR_raise(ERR_LIB_EVP, EVP_R_MEMORY_LIMIT_EXCEEDED);
  427. return 0;
  428. }
  429. /*
  430. * Check 32 * r * (N + 2) * sizeof(uint32_t) fits in uint64_t
  431. * This is combined size V, X and T (section 4)
  432. */
  433. i = UINT64_MAX / (32 * sizeof(uint32_t));
  434. if (N + 2 > i / r) {
  435. ERR_raise(ERR_LIB_EVP, EVP_R_MEMORY_LIMIT_EXCEEDED);
  436. return 0;
  437. }
  438. Vlen = 32 * r * (N + 2) * sizeof(uint32_t);
  439. /* check total allocated size fits in uint64_t */
  440. if (Blen > UINT64_MAX - Vlen) {
  441. ERR_raise(ERR_LIB_EVP, EVP_R_MEMORY_LIMIT_EXCEEDED);
  442. return 0;
  443. }
  444. /* Check that the maximum memory doesn't exceed a size_t limits */
  445. if (maxmem > SIZE_MAX)
  446. maxmem = SIZE_MAX;
  447. if (Blen + Vlen > maxmem) {
  448. ERR_raise(ERR_LIB_EVP, EVP_R_MEMORY_LIMIT_EXCEEDED);
  449. return 0;
  450. }
  451. /* If no key return to indicate parameters are OK */
  452. if (key == NULL)
  453. return 1;
  454. B = OPENSSL_malloc((size_t)(Blen + Vlen));
  455. if (B == NULL)
  456. return 0;
  457. X = (uint32_t *)(B + Blen);
  458. T = X + 32 * r;
  459. V = T + 32 * r;
  460. if (ossl_pkcs5_pbkdf2_hmac_ex(pass, passlen, salt, saltlen, 1, sha256,
  461. (int)Blen, B, libctx, propq) == 0)
  462. goto err;
  463. for (i = 0; i < p; i++)
  464. scryptROMix(B + 128 * r * i, r, N, X, T, V);
  465. if (ossl_pkcs5_pbkdf2_hmac_ex(pass, passlen, B, (int)Blen, 1, sha256,
  466. keylen, key, libctx, propq) == 0)
  467. goto err;
  468. rv = 1;
  469. err:
  470. if (rv == 0)
  471. ERR_raise(ERR_LIB_EVP, EVP_R_PBKDF2_ERROR);
  472. OPENSSL_clear_free(B, (size_t)(Blen + Vlen));
  473. return rv;
  474. }
  475. #endif