mbedtls_backend_ecc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /**
  2. * Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #include "sdk_config.h"
  41. #include "nordic_common.h"
  42. #if NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS)
  43. #include <stdbool.h>
  44. #include <string.h>
  45. #include "nrf_crypto_ecc.h"
  46. #include "nrf_crypto_ecdh.h"
  47. #include "nrf_crypto_mem.h"
  48. #include "nrf_crypto_rng.h"
  49. #include "nrf_crypto_shared.h"
  50. #include "nrf_assert.h"
  51. #include "mbedtls_backend_ecc.h"
  52. /*lint -save -e????*/
  53. #if !defined(MBEDTLS_CONFIG_FILE)
  54. #include "mbedtls/config.h"
  55. #else
  56. #include MBEDTLS_CONFIG_FILE
  57. #endif
  58. #include "mbedtls/ecp.h"
  59. #include "mbedtls/bignum.h"
  60. /*lint -restore*/
  61. bool nrf_crypto_backend_mbedtls_ecc_group_load(
  62. mbedtls_ecp_group * p_group,
  63. struct nrf_crypto_ecc_curve_info_s const * p_info)
  64. {
  65. int result;
  66. mbedtls_ecp_group_init(p_group);
  67. result = mbedtls_ecp_group_load(p_group,
  68. (mbedtls_ecp_group_id)(intptr_t)p_info->p_backend_data);
  69. if (result != 0)
  70. {
  71. return false;
  72. }
  73. return true;
  74. }
  75. int nrf_crypto_backend_mbedtls_ecc_mbedtls_rng(void * p_param, unsigned char * p_data, size_t size)
  76. {
  77. #if NRF_MODULE_ENABLED(NRF_CRYPTO_RNG)
  78. ret_code_t result;
  79. result = nrf_crypto_rng_vector_generate(p_data, size);
  80. if (result != NRF_SUCCESS)
  81. {
  82. return MBEDTLS_ERR_ECP_RANDOM_FAILED;
  83. }
  84. return 0;
  85. #else
  86. return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
  87. #endif
  88. }
  89. ret_code_t nrf_crypto_backend_mbedtls_key_pair_generate(
  90. void * p_context,
  91. void * p_private_key,
  92. void * p_public_key)
  93. {
  94. int result;
  95. mbedtls_ecp_group group;
  96. nrf_crypto_backend_mbedtls_ecc_private_key_t * p_prv =
  97. (nrf_crypto_backend_mbedtls_ecc_private_key_t *)p_private_key;
  98. nrf_crypto_backend_mbedtls_ecc_public_key_t * p_pub =
  99. (nrf_crypto_backend_mbedtls_ecc_public_key_t *)p_public_key;
  100. nrf_crypto_ecc_curve_info_t const * p_info = p_pub->header.p_info;
  101. if (!nrf_crypto_backend_mbedtls_ecc_group_load(&group, p_info))
  102. {
  103. return NRF_ERROR_CRYPTO_INTERNAL;
  104. }
  105. mbedtls_ecp_point_init(&p_pub->key);
  106. mbedtls_mpi_init(&p_prv->key);
  107. result = mbedtls_ecp_gen_keypair(&group,
  108. &p_prv->key,
  109. &p_pub->key,
  110. nrf_crypto_backend_mbedtls_ecc_mbedtls_rng,
  111. NULL);
  112. mbedtls_ecp_group_free(&group);
  113. if (result != 0)
  114. {
  115. mbedtls_mpi_free(&p_prv->key);
  116. mbedtls_ecp_point_free(&p_pub->key);
  117. return NRF_ERROR_CRYPTO_INTERNAL;
  118. }
  119. return NRF_SUCCESS;
  120. }
  121. ret_code_t nrf_crypto_backend_mbedtls_public_key_calculate(
  122. void * p_context,
  123. void const * p_private_key,
  124. void * p_public_key)
  125. {
  126. int result;
  127. mbedtls_ecp_group group;
  128. nrf_crypto_backend_mbedtls_ecc_private_key_t const * p_prv =
  129. (nrf_crypto_backend_mbedtls_ecc_private_key_t const *)p_private_key;
  130. nrf_crypto_backend_mbedtls_ecc_public_key_t * p_pub =
  131. (nrf_crypto_backend_mbedtls_ecc_public_key_t *)p_public_key;
  132. nrf_crypto_ecc_curve_info_t const * p_info = p_pub->header.p_info;
  133. if (!nrf_crypto_backend_mbedtls_ecc_group_load(&group, p_info))
  134. {
  135. return NRF_ERROR_CRYPTO_INTERNAL;
  136. }
  137. mbedtls_ecp_point_init(&p_pub->key);
  138. result = mbedtls_ecp_mul(&group,
  139. &p_pub->key,
  140. &p_prv->key,
  141. &group.G,
  142. nrf_crypto_backend_mbedtls_ecc_mbedtls_rng,
  143. NULL);
  144. mbedtls_ecp_group_free(&group);
  145. if (result != 0)
  146. {
  147. mbedtls_ecp_point_free(&p_pub->key);
  148. return NRF_ERROR_CRYPTO_INTERNAL;
  149. }
  150. return NRF_SUCCESS;
  151. }
  152. ret_code_t nrf_crypto_backend_mbedtls_private_key_from_raw(
  153. void * p_private_key,
  154. uint8_t const * p_raw_data)
  155. {
  156. int result;
  157. mbedtls_ecp_group group;
  158. nrf_crypto_backend_mbedtls_ecc_private_key_t * p_prv =
  159. (nrf_crypto_backend_mbedtls_ecc_private_key_t *)p_private_key;
  160. nrf_crypto_ecc_curve_info_t const * p_info = p_prv->header.p_info;
  161. uint8_t const * p_input = p_raw_data;
  162. #if NRF_CRYPTO_ECC_CURVE25519_ENABLED && !NRF_MODULE_ENABLED(NRF_CRYPTO_CURVE25519_BIG_ENDIAN)
  163. uint8_t temp[NRF_CRYPTO_ECC_CURVE25519_RAW_PRIVATE_KEY_SIZE];
  164. if (p_info == &g_nrf_crypto_ecc_curve25519_curve_info)
  165. {
  166. nrf_crypto_internal_swap_endian(temp,
  167. p_raw_data,
  168. NRF_CRYPTO_ECC_CURVE25519_RAW_PRIVATE_KEY_SIZE);
  169. p_input = temp;
  170. }
  171. #endif
  172. if (!nrf_crypto_backend_mbedtls_ecc_group_load(&group, p_info))
  173. {
  174. return NRF_ERROR_CRYPTO_INTERNAL;
  175. }
  176. mbedtls_mpi_init(&p_prv->key);
  177. result = mbedtls_mpi_read_binary(&p_prv->key, p_input, p_info->raw_private_key_size);
  178. if (result == 0)
  179. {
  180. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_CURVE25519)
  181. // Update bits in Curve25519 private key
  182. if (p_prv->header.p_info->curve_type == NRF_CRYPTO_ECC_CURVE25519_CURVE_TYPE)
  183. {
  184. result = mbedtls_mpi_set_bit(&p_prv->key, 0, 0);
  185. ASSERT(result == 0);
  186. result = mbedtls_mpi_set_bit(&p_prv->key, 1, 0);
  187. ASSERT(result == 0);
  188. result = mbedtls_mpi_set_bit(&p_prv->key, 2, 0);
  189. ASSERT(result == 0);
  190. result = mbedtls_mpi_set_bit(&p_prv->key, 254, 1);
  191. ASSERT(result == 0);
  192. result = mbedtls_mpi_set_bit(&p_prv->key, 255, 0);
  193. ASSERT(result == 0);
  194. }
  195. #endif
  196. if (mbedtls_ecp_check_privkey(&group, &p_prv->key) != 0)
  197. {
  198. result = MBEDTLS_ERR_ECP_INVALID_KEY;
  199. }
  200. }
  201. mbedtls_ecp_group_free(&group);
  202. if (result != 0)
  203. {
  204. mbedtls_mpi_free(&p_prv->key);
  205. return NRF_ERROR_CRYPTO_INTERNAL;
  206. }
  207. return NRF_SUCCESS;
  208. }
  209. ret_code_t nrf_crypto_backend_mbedtls_private_key_to_raw(
  210. void const * p_private_key,
  211. uint8_t * p_raw_data)
  212. {
  213. int result;
  214. nrf_crypto_backend_mbedtls_ecc_private_key_t const * p_prv =
  215. (nrf_crypto_backend_mbedtls_ecc_private_key_t const *)p_private_key;
  216. nrf_crypto_ecc_curve_info_t const * p_info = p_prv->header.p_info;
  217. result = mbedtls_mpi_write_binary(&p_prv->key, p_raw_data, p_info->raw_private_key_size);
  218. #if NRF_CRYPTO_ECC_CURVE25519_ENABLED && !NRF_MODULE_ENABLED(NRF_CRYPTO_CURVE25519_BIG_ENDIAN)
  219. if (p_info == &g_nrf_crypto_ecc_curve25519_curve_info)
  220. {
  221. nrf_crypto_internal_swap_endian_in_place(p_raw_data,
  222. NRF_CRYPTO_ECC_CURVE25519_RAW_PRIVATE_KEY_SIZE);
  223. }
  224. #endif
  225. if (result != 0)
  226. {
  227. return NRF_ERROR_CRYPTO_INTERNAL;
  228. }
  229. return NRF_SUCCESS;
  230. }
  231. ret_code_t nrf_crypto_backend_mbedtls_public_key_from_raw(
  232. void * p_public_key,
  233. uint8_t const * p_raw_data)
  234. {
  235. int result;
  236. mbedtls_ecp_group group;
  237. nrf_crypto_backend_mbedtls_ecc_public_key_t * p_pub =
  238. (nrf_crypto_backend_mbedtls_ecc_public_key_t *)p_public_key;
  239. nrf_crypto_ecc_curve_info_t const * p_info = p_pub->header.p_info;
  240. uint8_t const * p_input = p_raw_data;
  241. #if NRF_CRYPTO_ECC_CURVE25519_ENABLED && !NRF_MODULE_ENABLED(NRF_CRYPTO_CURVE25519_BIG_ENDIAN)
  242. uint8_t temp[NRF_CRYPTO_ECC_CURVE25519_RAW_PUBLIC_KEY_SIZE];
  243. if (p_info == &g_nrf_crypto_ecc_curve25519_curve_info)
  244. {
  245. nrf_crypto_internal_swap_endian(temp,
  246. p_raw_data,
  247. NRF_CRYPTO_ECC_CURVE25519_RAW_PUBLIC_KEY_SIZE);
  248. p_input = temp;
  249. }
  250. #endif
  251. mbedtls_ecp_point_init(&p_pub->key);
  252. result = mbedtls_mpi_read_binary(&p_pub->key.X,
  253. p_input,
  254. p_info->raw_private_key_size);
  255. if (result != 0)
  256. {
  257. goto error_exit;
  258. }
  259. if (p_info->raw_public_key_size > p_info->raw_private_key_size)
  260. {
  261. result = mbedtls_mpi_read_binary(&p_pub->key.Y,
  262. &p_raw_data[p_info->raw_private_key_size],
  263. p_info->raw_private_key_size);
  264. }
  265. if (result != 0)
  266. {
  267. goto error_exit;
  268. }
  269. result = mbedtls_mpi_lset(&p_pub->key.Z, 1);
  270. if (result == 0)
  271. {
  272. if (!nrf_crypto_backend_mbedtls_ecc_group_load(&group, p_info))
  273. {
  274. goto error_exit;
  275. }
  276. result = mbedtls_ecp_check_pubkey(&group, &p_pub->key);
  277. mbedtls_ecp_group_free(&group);
  278. }
  279. if (result != 0)
  280. {
  281. goto error_exit;
  282. }
  283. return NRF_SUCCESS;
  284. error_exit:
  285. mbedtls_ecp_point_free(&p_pub->key);
  286. return NRF_ERROR_CRYPTO_INTERNAL;
  287. }
  288. ret_code_t nrf_crypto_backend_mbedtls_public_key_to_raw(
  289. void const * p_public_key,
  290. uint8_t * p_raw_data)
  291. {
  292. int result;
  293. nrf_crypto_backend_mbedtls_ecc_public_key_t const * p_pub =
  294. (nrf_crypto_backend_mbedtls_ecc_public_key_t const *)p_public_key;
  295. nrf_crypto_ecc_curve_info_t const * p_info = p_pub->header.p_info;
  296. result = mbedtls_mpi_write_binary(&p_pub->key.X,
  297. p_raw_data,
  298. p_info->raw_private_key_size);
  299. if (result != 0)
  300. {
  301. return NRF_ERROR_CRYPTO_INTERNAL;
  302. }
  303. if (p_info->raw_public_key_size > p_info->raw_private_key_size)
  304. {
  305. result = mbedtls_mpi_write_binary(&p_pub->key.Y,
  306. &p_raw_data[p_info->raw_private_key_size],
  307. p_info->raw_private_key_size);
  308. }
  309. #if NRF_CRYPTO_ECC_CURVE25519_ENABLED && !NRF_MODULE_ENABLED(NRF_CRYPTO_CURVE25519_BIG_ENDIAN)
  310. if (p_info == &g_nrf_crypto_ecc_curve25519_curve_info)
  311. {
  312. nrf_crypto_internal_swap_endian_in_place(p_raw_data,
  313. NRF_CRYPTO_ECC_CURVE25519_RAW_PUBLIC_KEY_SIZE);
  314. }
  315. #endif
  316. if (result != 0)
  317. {
  318. return NRF_ERROR_CRYPTO_INTERNAL;
  319. }
  320. return NRF_SUCCESS;
  321. }
  322. ret_code_t nrf_crypto_backend_mbedtls_private_key_free(
  323. void * p_private_key)
  324. {
  325. nrf_crypto_backend_mbedtls_ecc_private_key_t * p_prv =
  326. (nrf_crypto_backend_mbedtls_ecc_private_key_t *)p_private_key;
  327. mbedtls_mpi_free(&p_prv->key);
  328. return NRF_SUCCESS;
  329. }
  330. ret_code_t nrf_crypto_backend_mbedtls_public_key_free(
  331. void * p_public_key)
  332. {
  333. nrf_crypto_backend_mbedtls_ecc_public_key_t * p_pub =
  334. (nrf_crypto_backend_mbedtls_ecc_public_key_t *)p_public_key;
  335. mbedtls_ecp_point_free(&p_pub->key);
  336. return NRF_SUCCESS;
  337. }
  338. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP192R1)
  339. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp192r1_curve_info =
  340. {
  341. .public_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_public_key_t),
  342. .private_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_private_key_t),
  343. .curve_type = NRF_CRYPTO_ECC_SECP192R1_CURVE_TYPE,
  344. .raw_private_key_size = NRF_CRYPTO_ECC_SECP192R1_RAW_PRIVATE_KEY_SIZE,
  345. .raw_public_key_size = NRF_CRYPTO_ECC_SECP192R1_RAW_PUBLIC_KEY_SIZE,
  346. .p_backend_data = (void *)MBEDTLS_ECP_DP_SECP192R1,
  347. };
  348. #endif
  349. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP224R1)
  350. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp224r1_curve_info =
  351. {
  352. .public_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_public_key_t),
  353. .private_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_private_key_t),
  354. .curve_type = NRF_CRYPTO_ECC_SECP224R1_CURVE_TYPE,
  355. .raw_private_key_size = NRF_CRYPTO_ECC_SECP224R1_RAW_PRIVATE_KEY_SIZE,
  356. .raw_public_key_size = NRF_CRYPTO_ECC_SECP224R1_RAW_PUBLIC_KEY_SIZE,
  357. .p_backend_data = (void *)MBEDTLS_ECP_DP_SECP224R1,
  358. };
  359. #endif
  360. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP256R1)
  361. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp256r1_curve_info =
  362. {
  363. .public_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_public_key_t),
  364. .private_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_private_key_t),
  365. .curve_type = NRF_CRYPTO_ECC_SECP256R1_CURVE_TYPE,
  366. .raw_private_key_size = NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE,
  367. .raw_public_key_size = NRF_CRYPTO_ECC_SECP256R1_RAW_PUBLIC_KEY_SIZE,
  368. .p_backend_data = (void *)MBEDTLS_ECP_DP_SECP256R1,
  369. };
  370. #endif
  371. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP384R1)
  372. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp384r1_curve_info =
  373. {
  374. .public_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_public_key_t),
  375. .private_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_private_key_t),
  376. .curve_type = NRF_CRYPTO_ECC_SECP384R1_CURVE_TYPE,
  377. .raw_private_key_size = NRF_CRYPTO_ECC_SECP384R1_RAW_PRIVATE_KEY_SIZE,
  378. .raw_public_key_size = NRF_CRYPTO_ECC_SECP384R1_RAW_PUBLIC_KEY_SIZE,
  379. .p_backend_data = (void *)MBEDTLS_ECP_DP_SECP384R1,
  380. };
  381. #endif
  382. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP521R1)
  383. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp521r1_curve_info =
  384. {
  385. .public_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_public_key_t),
  386. .private_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_private_key_t),
  387. .curve_type = NRF_CRYPTO_ECC_SECP521R1_CURVE_TYPE,
  388. .raw_private_key_size = NRF_CRYPTO_ECC_SECP521R1_RAW_PRIVATE_KEY_SIZE,
  389. .raw_public_key_size = NRF_CRYPTO_ECC_SECP521R1_RAW_PUBLIC_KEY_SIZE,
  390. .p_backend_data = (void *)MBEDTLS_ECP_DP_SECP521R1,
  391. };
  392. #endif
  393. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP192K1)
  394. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp192k1_curve_info =
  395. {
  396. .public_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_public_key_t),
  397. .private_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_private_key_t),
  398. .curve_type = NRF_CRYPTO_ECC_SECP192K1_CURVE_TYPE,
  399. .raw_private_key_size = NRF_CRYPTO_ECC_SECP192K1_RAW_PRIVATE_KEY_SIZE,
  400. .raw_public_key_size = NRF_CRYPTO_ECC_SECP192K1_RAW_PUBLIC_KEY_SIZE,
  401. .p_backend_data = (void *)MBEDTLS_ECP_DP_SECP192K1,
  402. };
  403. #endif
  404. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP224K1)
  405. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp224k1_curve_info =
  406. {
  407. .public_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_public_key_t),
  408. .private_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_private_key_t),
  409. .curve_type = NRF_CRYPTO_ECC_SECP224K1_CURVE_TYPE,
  410. .raw_private_key_size = NRF_CRYPTO_ECC_SECP224K1_RAW_PRIVATE_KEY_SIZE,
  411. .raw_public_key_size = NRF_CRYPTO_ECC_SECP224K1_RAW_PUBLIC_KEY_SIZE,
  412. .p_backend_data = (void *)MBEDTLS_ECP_DP_SECP224K1,
  413. };
  414. #endif
  415. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP256K1)
  416. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp256k1_curve_info =
  417. {
  418. .public_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_public_key_t),
  419. .private_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_private_key_t),
  420. .curve_type = NRF_CRYPTO_ECC_SECP256K1_CURVE_TYPE,
  421. .raw_private_key_size = NRF_CRYPTO_ECC_SECP256K1_RAW_PRIVATE_KEY_SIZE,
  422. .raw_public_key_size = NRF_CRYPTO_ECC_SECP256K1_RAW_PUBLIC_KEY_SIZE,
  423. .p_backend_data = (void *)MBEDTLS_ECP_DP_SECP256K1,
  424. };
  425. #endif
  426. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_BP256R1)
  427. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_bp256r1_curve_info =
  428. {
  429. .public_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_public_key_t),
  430. .private_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_private_key_t),
  431. .curve_type = NRF_CRYPTO_ECC_BP256R1_CURVE_TYPE,
  432. .raw_private_key_size = NRF_CRYPTO_ECC_BP256R1_RAW_PRIVATE_KEY_SIZE,
  433. .raw_public_key_size = NRF_CRYPTO_ECC_BP256R1_RAW_PUBLIC_KEY_SIZE,
  434. .p_backend_data = (void *)MBEDTLS_ECP_DP_BP256R1,
  435. };
  436. #endif
  437. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_BP384R1)
  438. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_bp384r1_curve_info =
  439. {
  440. .public_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_public_key_t),
  441. .private_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_private_key_t),
  442. .curve_type = NRF_CRYPTO_ECC_BP384R1_CURVE_TYPE,
  443. .raw_private_key_size = NRF_CRYPTO_ECC_BP384R1_RAW_PRIVATE_KEY_SIZE,
  444. .raw_public_key_size = NRF_CRYPTO_ECC_BP384R1_RAW_PUBLIC_KEY_SIZE,
  445. .p_backend_data = (void *)MBEDTLS_ECP_DP_BP384R1,
  446. };
  447. #endif
  448. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_BP512R1)
  449. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_bp512r1_curve_info =
  450. {
  451. .public_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_public_key_t),
  452. .private_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_private_key_t),
  453. .curve_type = NRF_CRYPTO_ECC_BP512R1_CURVE_TYPE,
  454. .raw_private_key_size = NRF_CRYPTO_ECC_BP512R1_RAW_PRIVATE_KEY_SIZE,
  455. .raw_public_key_size = NRF_CRYPTO_ECC_BP512R1_RAW_PUBLIC_KEY_SIZE,
  456. .p_backend_data = (void *)MBEDTLS_ECP_DP_BP512R1,
  457. };
  458. #endif
  459. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_CURVE25519)
  460. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_curve25519_curve_info =
  461. {
  462. .public_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_public_key_t),
  463. .private_key_size = sizeof(nrf_crypto_backend_mbedtls_ecc_private_key_t),
  464. .curve_type = NRF_CRYPTO_ECC_CURVE25519_CURVE_TYPE,
  465. .raw_private_key_size = NRF_CRYPTO_ECC_CURVE25519_RAW_PRIVATE_KEY_SIZE,
  466. .raw_public_key_size = NRF_CRYPTO_ECC_CURVE25519_RAW_PUBLIC_KEY_SIZE,
  467. .p_backend_data = (void *)MBEDTLS_ECP_DP_CURVE25519,
  468. };
  469. #endif
  470. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS)