psa_crypto_pake.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /*
  2. * PSA PAKE layer on top of Mbed TLS software crypto
  3. */
  4. /*
  5. * Copyright The Mbed TLS Contributors
  6. * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  7. */
  8. #include "common.h"
  9. #if defined(MBEDTLS_PSA_CRYPTO_C)
  10. #include <psa/crypto.h>
  11. #include "psa_crypto_core.h"
  12. #include "psa_crypto_pake.h"
  13. #include "psa_crypto_slot_management.h"
  14. #include <mbedtls/ecjpake.h>
  15. #include "psa_util_internal.h"
  16. #include <mbedtls/platform.h>
  17. #include <mbedtls/error.h>
  18. #include <string.h>
  19. /*
  20. * State sequence:
  21. *
  22. * psa_pake_setup()
  23. * |
  24. * |-- In any order:
  25. * | | psa_pake_set_password_key()
  26. * | | psa_pake_set_user()
  27. * | | psa_pake_set_peer()
  28. * | | psa_pake_set_role()
  29. * |
  30. * |--- In any order: (First round input before or after first round output)
  31. * | |
  32. * | |------ In Order
  33. * | | | psa_pake_output(PSA_PAKE_STEP_KEY_SHARE)
  34. * | | | psa_pake_output(PSA_PAKE_STEP_ZK_PUBLIC)
  35. * | | | psa_pake_output(PSA_PAKE_STEP_ZK_PROOF)
  36. * | | | psa_pake_output(PSA_PAKE_STEP_KEY_SHARE)
  37. * | | | psa_pake_output(PSA_PAKE_STEP_ZK_PUBLIC)
  38. * | | | psa_pake_output(PSA_PAKE_STEP_ZK_PROOF)
  39. * | |
  40. * | |------ In Order:
  41. * | | psa_pake_input(PSA_PAKE_STEP_KEY_SHARE)
  42. * | | psa_pake_input(PSA_PAKE_STEP_ZK_PUBLIC)
  43. * | | psa_pake_input(PSA_PAKE_STEP_ZK_PROOF)
  44. * | | psa_pake_input(PSA_PAKE_STEP_KEY_SHARE)
  45. * | | psa_pake_input(PSA_PAKE_STEP_ZK_PUBLIC)
  46. * | | psa_pake_input(PSA_PAKE_STEP_ZK_PROOF)
  47. * |
  48. * |--- In any order: (Second round input before or after second round output)
  49. * | |
  50. * | |------ In Order
  51. * | | | psa_pake_output(PSA_PAKE_STEP_KEY_SHARE)
  52. * | | | psa_pake_output(PSA_PAKE_STEP_ZK_PUBLIC)
  53. * | | | psa_pake_output(PSA_PAKE_STEP_ZK_PROOF)
  54. * | |
  55. * | |------ In Order:
  56. * | | psa_pake_input(PSA_PAKE_STEP_KEY_SHARE)
  57. * | | psa_pake_input(PSA_PAKE_STEP_ZK_PUBLIC)
  58. * | | psa_pake_input(PSA_PAKE_STEP_ZK_PROOF)
  59. * |
  60. * psa_pake_get_implicit_key()
  61. * psa_pake_abort()
  62. */
  63. /*
  64. * Possible sequence of calls to implementation:
  65. *
  66. * |--- In any order:
  67. * | |
  68. * | |------ In Order
  69. * | | | mbedtls_psa_pake_output(PSA_JPAKE_X1_STEP_KEY_SHARE)
  70. * | | | mbedtls_psa_pake_output(PSA_JPAKE_X1_STEP_ZK_PUBLIC)
  71. * | | | mbedtls_psa_pake_output(PSA_JPAKE_X1_STEP_ZK_PROOF)
  72. * | | | mbedtls_psa_pake_output(PSA_JPAKE_X2_STEP_KEY_SHARE)
  73. * | | | mbedtls_psa_pake_output(PSA_JPAKE_X2_STEP_ZK_PUBLIC)
  74. * | | | mbedtls_psa_pake_output(PSA_JPAKE_X2_STEP_ZK_PROOF)
  75. * | |
  76. * | |------ In Order:
  77. * | | mbedtls_psa_pake_input(PSA_JPAKE_X1_STEP_KEY_SHARE)
  78. * | | mbedtls_psa_pake_input(PSA_JPAKE_X1_STEP_ZK_PUBLIC)
  79. * | | mbedtls_psa_pake_input(PSA_JPAKE_X1_STEP_ZK_PROOF)
  80. * | | mbedtls_psa_pake_input(PSA_JPAKE_X2_STEP_KEY_SHARE)
  81. * | | mbedtls_psa_pake_input(PSA_JPAKE_X2_STEP_ZK_PUBLIC)
  82. * | | mbedtls_psa_pake_input(PSA_JPAKE_X2_STEP_ZK_PROOF)
  83. * |
  84. * |--- In any order:
  85. * | |
  86. * | |------ In Order
  87. * | | | mbedtls_psa_pake_output(PSA_JPAKE_X2S_STEP_KEY_SHARE)
  88. * | | | mbedtls_psa_pake_output(PSA_JPAKE_X2S_STEP_ZK_PUBLIC)
  89. * | | | mbedtls_psa_pake_output(PSA_JPAKE_X2S_STEP_ZK_PROOF)
  90. * | |
  91. * | |------ In Order:
  92. * | | mbedtls_psa_pake_input(PSA_JPAKE_X4S_STEP_KEY_SHARE)
  93. * | | mbedtls_psa_pake_input(PSA_JPAKE_X4S_STEP_ZK_PUBLIC)
  94. * | | mbedtls_psa_pake_input(PSA_JPAKE_X4S_STEP_ZK_PROOF)
  95. */
  96. #if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
  97. static psa_status_t mbedtls_ecjpake_to_psa_error(int ret)
  98. {
  99. switch (ret) {
  100. case MBEDTLS_ERR_MPI_BAD_INPUT_DATA:
  101. case MBEDTLS_ERR_ECP_BAD_INPUT_DATA:
  102. case MBEDTLS_ERR_ECP_INVALID_KEY:
  103. case MBEDTLS_ERR_ECP_VERIFY_FAILED:
  104. return PSA_ERROR_DATA_INVALID;
  105. case MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL:
  106. case MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL:
  107. return PSA_ERROR_BUFFER_TOO_SMALL;
  108. case MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE:
  109. return PSA_ERROR_NOT_SUPPORTED;
  110. case MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED:
  111. return PSA_ERROR_CORRUPTION_DETECTED;
  112. default:
  113. return PSA_ERROR_GENERIC_ERROR;
  114. }
  115. }
  116. #endif
  117. #if defined(MBEDTLS_PSA_BUILTIN_PAKE)
  118. #if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
  119. static psa_status_t psa_pake_ecjpake_setup(mbedtls_psa_pake_operation_t *operation)
  120. {
  121. int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  122. mbedtls_ecjpake_init(&operation->ctx.jpake);
  123. ret = mbedtls_ecjpake_setup(&operation->ctx.jpake,
  124. operation->role,
  125. MBEDTLS_MD_SHA256,
  126. MBEDTLS_ECP_DP_SECP256R1,
  127. operation->password,
  128. operation->password_len);
  129. mbedtls_platform_zeroize(operation->password, operation->password_len);
  130. if (ret != 0) {
  131. return mbedtls_ecjpake_to_psa_error(ret);
  132. }
  133. return PSA_SUCCESS;
  134. }
  135. #endif
  136. /* The only two JPAKE user/peer identifiers supported in built-in implementation. */
  137. static const uint8_t jpake_server_id[] = { 's', 'e', 'r', 'v', 'e', 'r' };
  138. static const uint8_t jpake_client_id[] = { 'c', 'l', 'i', 'e', 'n', 't' };
  139. psa_status_t mbedtls_psa_pake_setup(mbedtls_psa_pake_operation_t *operation,
  140. const psa_crypto_driver_pake_inputs_t *inputs)
  141. {
  142. psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
  143. size_t user_len = 0, peer_len = 0, password_len = 0;
  144. uint8_t *peer = NULL, *user = NULL;
  145. size_t actual_user_len = 0, actual_peer_len = 0, actual_password_len = 0;
  146. psa_pake_cipher_suite_t cipher_suite = psa_pake_cipher_suite_init();
  147. status = psa_crypto_driver_pake_get_password_len(inputs, &password_len);
  148. if (status != PSA_SUCCESS) {
  149. return status;
  150. }
  151. status = psa_crypto_driver_pake_get_user_len(inputs, &user_len);
  152. if (status != PSA_SUCCESS) {
  153. return status;
  154. }
  155. status = psa_crypto_driver_pake_get_peer_len(inputs, &peer_len);
  156. if (status != PSA_SUCCESS) {
  157. return status;
  158. }
  159. status = psa_crypto_driver_pake_get_cipher_suite(inputs, &cipher_suite);
  160. if (status != PSA_SUCCESS) {
  161. return status;
  162. }
  163. operation->password = mbedtls_calloc(1, password_len);
  164. if (operation->password == NULL) {
  165. status = PSA_ERROR_INSUFFICIENT_MEMORY;
  166. goto error;
  167. }
  168. user = mbedtls_calloc(1, user_len);
  169. if (user == NULL) {
  170. status = PSA_ERROR_INSUFFICIENT_MEMORY;
  171. goto error;
  172. }
  173. peer = mbedtls_calloc(1, peer_len);
  174. if (peer == NULL) {
  175. status = PSA_ERROR_INSUFFICIENT_MEMORY;
  176. goto error;
  177. }
  178. status = psa_crypto_driver_pake_get_password(inputs, operation->password,
  179. password_len, &actual_password_len);
  180. if (status != PSA_SUCCESS) {
  181. goto error;
  182. }
  183. status = psa_crypto_driver_pake_get_user(inputs, user,
  184. user_len, &actual_user_len);
  185. if (status != PSA_SUCCESS) {
  186. goto error;
  187. }
  188. status = psa_crypto_driver_pake_get_peer(inputs, peer,
  189. peer_len, &actual_peer_len);
  190. if (status != PSA_SUCCESS) {
  191. goto error;
  192. }
  193. operation->password_len = actual_password_len;
  194. operation->alg = cipher_suite.algorithm;
  195. #if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
  196. if (cipher_suite.algorithm == PSA_ALG_JPAKE) {
  197. if (cipher_suite.type != PSA_PAKE_PRIMITIVE_TYPE_ECC ||
  198. cipher_suite.family != PSA_ECC_FAMILY_SECP_R1 ||
  199. cipher_suite.bits != 256 ||
  200. cipher_suite.hash != PSA_ALG_SHA_256) {
  201. status = PSA_ERROR_NOT_SUPPORTED;
  202. goto error;
  203. }
  204. const size_t user_peer_len = sizeof(jpake_client_id); // client and server have the same length
  205. if (actual_user_len != user_peer_len ||
  206. actual_peer_len != user_peer_len) {
  207. status = PSA_ERROR_NOT_SUPPORTED;
  208. goto error;
  209. }
  210. if (memcmp(user, jpake_client_id, actual_user_len) == 0 &&
  211. memcmp(peer, jpake_server_id, actual_peer_len) == 0) {
  212. operation->role = MBEDTLS_ECJPAKE_CLIENT;
  213. } else
  214. if (memcmp(user, jpake_server_id, actual_user_len) == 0 &&
  215. memcmp(peer, jpake_client_id, actual_peer_len) == 0) {
  216. operation->role = MBEDTLS_ECJPAKE_SERVER;
  217. } else {
  218. status = PSA_ERROR_NOT_SUPPORTED;
  219. goto error;
  220. }
  221. operation->buffer_length = 0;
  222. operation->buffer_offset = 0;
  223. status = psa_pake_ecjpake_setup(operation);
  224. if (status != PSA_SUCCESS) {
  225. goto error;
  226. }
  227. /* Role has been set, release user/peer buffers. */
  228. mbedtls_free(user); mbedtls_free(peer);
  229. return PSA_SUCCESS;
  230. } else
  231. #else
  232. (void) operation;
  233. (void) inputs;
  234. #endif
  235. { status = PSA_ERROR_NOT_SUPPORTED; }
  236. error:
  237. mbedtls_free(user); mbedtls_free(peer);
  238. /* In case of failure of the setup of a multipart operation, the PSA driver interface
  239. * specifies that the core does not call any other driver entry point thus does not
  240. * call mbedtls_psa_pake_abort(). Therefore call it here to do the needed clean
  241. * up like freeing the memory that may have been allocated to store the password.
  242. */
  243. mbedtls_psa_pake_abort(operation);
  244. return status;
  245. }
  246. static psa_status_t mbedtls_psa_pake_output_internal(
  247. mbedtls_psa_pake_operation_t *operation,
  248. psa_crypto_driver_pake_step_t step,
  249. uint8_t *output,
  250. size_t output_size,
  251. size_t *output_length)
  252. {
  253. int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  254. size_t length;
  255. (void) step; // Unused parameter
  256. #if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
  257. /*
  258. * The PSA CRYPTO PAKE and Mbed TLS JPAKE API have a different
  259. * handling of output sequencing.
  260. *
  261. * The Mbed TLS JPAKE API outputs the whole X1+X2 and X2S steps data
  262. * at once, on the other side the PSA CRYPTO PAKE api requires
  263. * the KEY_SHARE/ZP_PUBLIC/ZK_PROOF parts of X1, X2 & X2S to be
  264. * retrieved in sequence.
  265. *
  266. * In order to achieve API compatibility, the whole X1+X2 or X2S steps
  267. * data is stored in an intermediate buffer at first step output call,
  268. * and data is sliced down by parsing the ECPoint records in order
  269. * to return the right parts on each step.
  270. */
  271. if (operation->alg == PSA_ALG_JPAKE) {
  272. /* Initialize & write round on KEY_SHARE sequences */
  273. if (step == PSA_JPAKE_X1_STEP_KEY_SHARE) {
  274. ret = mbedtls_ecjpake_write_round_one(&operation->ctx.jpake,
  275. operation->buffer,
  276. sizeof(operation->buffer),
  277. &operation->buffer_length,
  278. mbedtls_psa_get_random,
  279. MBEDTLS_PSA_RANDOM_STATE);
  280. if (ret != 0) {
  281. return mbedtls_ecjpake_to_psa_error(ret);
  282. }
  283. operation->buffer_offset = 0;
  284. } else if (step == PSA_JPAKE_X2S_STEP_KEY_SHARE) {
  285. ret = mbedtls_ecjpake_write_round_two(&operation->ctx.jpake,
  286. operation->buffer,
  287. sizeof(operation->buffer),
  288. &operation->buffer_length,
  289. mbedtls_psa_get_random,
  290. MBEDTLS_PSA_RANDOM_STATE);
  291. if (ret != 0) {
  292. return mbedtls_ecjpake_to_psa_error(ret);
  293. }
  294. operation->buffer_offset = 0;
  295. }
  296. /*
  297. * mbedtls_ecjpake_write_round_xxx() outputs thing in the format
  298. * defined by draft-cragie-tls-ecjpake-01 section 7. The summary is
  299. * that the data for each step is prepended with a length byte, and
  300. * then they're concatenated. Additionally, the server's second round
  301. * output is prepended with a 3-bytes ECParameters structure.
  302. *
  303. * In PSA, we output each step separately, and don't prepend the
  304. * output with a length byte, even less a curve identifier, as that
  305. * information is already available.
  306. */
  307. if (step == PSA_JPAKE_X2S_STEP_KEY_SHARE &&
  308. operation->role == MBEDTLS_ECJPAKE_SERVER) {
  309. /* Skip ECParameters, with is 3 bytes (RFC 8422) */
  310. operation->buffer_offset += 3;
  311. }
  312. /* Read the length byte then move past it to the data */
  313. length = operation->buffer[operation->buffer_offset];
  314. operation->buffer_offset += 1;
  315. if (operation->buffer_offset + length > operation->buffer_length) {
  316. return PSA_ERROR_DATA_CORRUPT;
  317. }
  318. if (output_size < length) {
  319. return PSA_ERROR_BUFFER_TOO_SMALL;
  320. }
  321. memcpy(output,
  322. operation->buffer + operation->buffer_offset,
  323. length);
  324. *output_length = length;
  325. operation->buffer_offset += length;
  326. /* Reset buffer after ZK_PROOF sequence */
  327. if ((step == PSA_JPAKE_X2_STEP_ZK_PROOF) ||
  328. (step == PSA_JPAKE_X2S_STEP_ZK_PROOF)) {
  329. mbedtls_platform_zeroize(operation->buffer, sizeof(operation->buffer));
  330. operation->buffer_length = 0;
  331. operation->buffer_offset = 0;
  332. }
  333. return PSA_SUCCESS;
  334. } else
  335. #else
  336. (void) step;
  337. (void) output;
  338. (void) output_size;
  339. (void) output_length;
  340. #endif
  341. { return PSA_ERROR_NOT_SUPPORTED; }
  342. }
  343. psa_status_t mbedtls_psa_pake_output(mbedtls_psa_pake_operation_t *operation,
  344. psa_crypto_driver_pake_step_t step,
  345. uint8_t *output,
  346. size_t output_size,
  347. size_t *output_length)
  348. {
  349. psa_status_t status = mbedtls_psa_pake_output_internal(
  350. operation, step, output, output_size, output_length);
  351. return status;
  352. }
  353. static psa_status_t mbedtls_psa_pake_input_internal(
  354. mbedtls_psa_pake_operation_t *operation,
  355. psa_crypto_driver_pake_step_t step,
  356. const uint8_t *input,
  357. size_t input_length)
  358. {
  359. int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  360. (void) step; // Unused parameter
  361. #if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
  362. /*
  363. * The PSA CRYPTO PAKE and Mbed TLS JPAKE API have a different
  364. * handling of input sequencing.
  365. *
  366. * The Mbed TLS JPAKE API takes the whole X1+X2 or X4S steps data
  367. * at once as input, on the other side the PSA CRYPTO PAKE api requires
  368. * the KEY_SHARE/ZP_PUBLIC/ZK_PROOF parts of X1, X2 & X4S to be
  369. * given in sequence.
  370. *
  371. * In order to achieve API compatibility, each X1+X2 or X4S step data
  372. * is stored sequentially in an intermediate buffer and given to the
  373. * Mbed TLS JPAKE API on the last step.
  374. *
  375. * This causes any input error to be only detected on the last step.
  376. */
  377. if (operation->alg == PSA_ALG_JPAKE) {
  378. /*
  379. * Copy input to local buffer and format it as the Mbed TLS API
  380. * expects, i.e. as defined by draft-cragie-tls-ecjpake-01 section 7.
  381. * The summary is that the data for each step is prepended with a
  382. * length byte, and then they're concatenated. Additionally, the
  383. * server's second round output is prepended with a 3-bytes
  384. * ECParameters structure - which means we have to prepend that when
  385. * we're a client.
  386. */
  387. if (step == PSA_JPAKE_X4S_STEP_KEY_SHARE &&
  388. operation->role == MBEDTLS_ECJPAKE_CLIENT) {
  389. /* We only support secp256r1. */
  390. /* This is the ECParameters structure defined by RFC 8422. */
  391. unsigned char ecparameters[3] = {
  392. 3, /* named_curve */
  393. 0, 23 /* secp256r1 */
  394. };
  395. if (operation->buffer_length + sizeof(ecparameters) >
  396. sizeof(operation->buffer)) {
  397. return PSA_ERROR_BUFFER_TOO_SMALL;
  398. }
  399. memcpy(operation->buffer + operation->buffer_length,
  400. ecparameters, sizeof(ecparameters));
  401. operation->buffer_length += sizeof(ecparameters);
  402. }
  403. /*
  404. * The core checks that input_length is smaller than
  405. * PSA_PAKE_INPUT_MAX_SIZE.
  406. * Thus no risk of integer overflow here.
  407. */
  408. if (operation->buffer_length + input_length + 1 > sizeof(operation->buffer)) {
  409. return PSA_ERROR_BUFFER_TOO_SMALL;
  410. }
  411. /* Write the length byte */
  412. operation->buffer[operation->buffer_length] = (uint8_t) input_length;
  413. operation->buffer_length += 1;
  414. /* Finally copy the data */
  415. memcpy(operation->buffer + operation->buffer_length,
  416. input, input_length);
  417. operation->buffer_length += input_length;
  418. /* Load buffer at each last round ZK_PROOF */
  419. if (step == PSA_JPAKE_X2_STEP_ZK_PROOF) {
  420. ret = mbedtls_ecjpake_read_round_one(&operation->ctx.jpake,
  421. operation->buffer,
  422. operation->buffer_length);
  423. mbedtls_platform_zeroize(operation->buffer, sizeof(operation->buffer));
  424. operation->buffer_length = 0;
  425. if (ret != 0) {
  426. return mbedtls_ecjpake_to_psa_error(ret);
  427. }
  428. } else if (step == PSA_JPAKE_X4S_STEP_ZK_PROOF) {
  429. ret = mbedtls_ecjpake_read_round_two(&operation->ctx.jpake,
  430. operation->buffer,
  431. operation->buffer_length);
  432. mbedtls_platform_zeroize(operation->buffer, sizeof(operation->buffer));
  433. operation->buffer_length = 0;
  434. if (ret != 0) {
  435. return mbedtls_ecjpake_to_psa_error(ret);
  436. }
  437. }
  438. return PSA_SUCCESS;
  439. } else
  440. #else
  441. (void) step;
  442. (void) input;
  443. (void) input_length;
  444. #endif
  445. { return PSA_ERROR_NOT_SUPPORTED; }
  446. }
  447. psa_status_t mbedtls_psa_pake_input(mbedtls_psa_pake_operation_t *operation,
  448. psa_crypto_driver_pake_step_t step,
  449. const uint8_t *input,
  450. size_t input_length)
  451. {
  452. psa_status_t status = mbedtls_psa_pake_input_internal(
  453. operation, step, input, input_length);
  454. return status;
  455. }
  456. psa_status_t mbedtls_psa_pake_get_implicit_key(
  457. mbedtls_psa_pake_operation_t *operation,
  458. uint8_t *output, size_t output_size,
  459. size_t *output_length)
  460. {
  461. int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  462. #if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
  463. if (operation->alg == PSA_ALG_JPAKE) {
  464. ret = mbedtls_ecjpake_write_shared_key(&operation->ctx.jpake,
  465. output,
  466. output_size,
  467. output_length,
  468. mbedtls_psa_get_random,
  469. MBEDTLS_PSA_RANDOM_STATE);
  470. if (ret != 0) {
  471. return mbedtls_ecjpake_to_psa_error(ret);
  472. }
  473. return PSA_SUCCESS;
  474. } else
  475. #else
  476. (void) output;
  477. #endif
  478. { return PSA_ERROR_NOT_SUPPORTED; }
  479. }
  480. psa_status_t mbedtls_psa_pake_abort(mbedtls_psa_pake_operation_t *operation)
  481. {
  482. mbedtls_zeroize_and_free(operation->password, operation->password_len);
  483. operation->password = NULL;
  484. operation->password_len = 0;
  485. #if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
  486. if (operation->alg == PSA_ALG_JPAKE) {
  487. operation->role = MBEDTLS_ECJPAKE_NONE;
  488. mbedtls_platform_zeroize(operation->buffer, sizeof(operation->buffer));
  489. operation->buffer_length = 0;
  490. operation->buffer_offset = 0;
  491. mbedtls_ecjpake_free(&operation->ctx.jpake);
  492. }
  493. #endif
  494. operation->alg = PSA_ALG_NONE;
  495. return PSA_SUCCESS;
  496. }
  497. #endif /* MBEDTLS_PSA_BUILTIN_PAKE */
  498. #endif /* MBEDTLS_PSA_CRYPTO_C */