cc310_backend_ecc.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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_CC310)
  43. #include <string.h>
  44. #include "nrf_crypto_mem.h"
  45. #include "nrf_crypto_ecc.h"
  46. #include "cc310_backend_ecc.h"
  47. #include "cc310_backend_shared.h"
  48. #include "cc310_backend_mutex.h"
  49. #include "crys_ecpki_kg.h"
  50. #include "crys_ecpki_domain.h"
  51. #include "crys_ecpki_build.h"
  52. #include "crys_ecpki_error.h"
  53. #include "crys_rnd_error.h"
  54. #include "crys_ec_mont_api.h"
  55. #include "crys_ec_edw_api.h"
  56. #include "crys_ec_mont_edw_error.h"
  57. #include "nrf_crypto_shared.h"
  58. #define CC310_UNCOMPRESSED_PUBLIC_KEY_ID_BYTE 0x04 /**< @brief @internal Byte value used by CC310 library to prefix uncompressed public key. */
  59. ret_code_t nrf_crypto_backend_cc310_ecc_error_convert(uint32_t crys_error)
  60. {
  61. switch (crys_error)
  62. {
  63. case CRYS_OK:
  64. return NRF_SUCCESS;
  65. case CRYS_ECDSA_VERIFY_INCONSISTENT_VERIFY_ERROR:
  66. case CRYS_ECEDW_SIGN_VERIFY_FAILED_ERROR:
  67. return NRF_ERROR_CRYPTO_ECDSA_INVALID_SIGNATURE;
  68. case CRYS_RND_INSTANTIATION_NOT_DONE_ERROR:
  69. return NRF_ERROR_CRYPTO_CONTEXT_NOT_INITIALIZED;
  70. default:
  71. return NRF_ERROR_CRYPTO_INTERNAL;
  72. }
  73. }
  74. /** @internal @brief Returns domain value from @ref CRYS_ECPKI_DomainID_t enum based on
  75. * value from info structure.
  76. *
  77. * @param[in] p_info Curve info.
  78. * @returns Pointer to CC310 domain.
  79. */
  80. static CRYS_ECPKI_Domain_t const * get_domain(nrf_crypto_ecc_curve_info_t const * p_info)
  81. {
  82. CRYS_ECPKI_DomainID_t domain_id = (CRYS_ECPKI_DomainID_t)(intptr_t)p_info->p_backend_data;
  83. const CRYS_ECPKI_Domain_t * domain = CRYS_ECPKI_GetEcDomain(domain_id);
  84. return domain;
  85. }
  86. ret_code_t nrf_crypto_backend_cc310_ecc_public_key_convert(
  87. nrf_crypto_backend_cc310_ecc_public_key_t * p_pub,
  88. CRYS_ECPKI_BUILD_TempData_t * p_temp_data)
  89. {
  90. ret_code_t result;
  91. CRYSError_t crys_error;
  92. CRYS_ECPKI_Domain_t const * p_domain;
  93. uint8_t ucompressed_key[NRF_CRYPTO_ECC_RAW_PUBLIC_KEY_MAX_SIZE + 1];
  94. bool mutex_locked;
  95. nrf_crypto_ecc_curve_info_t const * p_info = p_pub->header.p_info;
  96. if (p_pub->key_converted)
  97. {
  98. return NRF_SUCCESS;
  99. }
  100. p_domain = get_domain(p_info);
  101. // Tell CC310 library that this is raw public key in uncompressed format.
  102. ucompressed_key[0] = CC310_UNCOMPRESSED_PUBLIC_KEY_ID_BYTE;
  103. memcpy(&ucompressed_key[1], p_pub->key.raw_public_key, p_info->raw_public_key_size);
  104. mutex_locked = cc310_backend_mutex_trylock();
  105. if (!mutex_locked)
  106. {
  107. return NRF_ERROR_CRYPTO_BUSY;
  108. }
  109. crys_error = CRYS_ECPKI_BuildPublKeyPartlyCheck(p_domain,
  110. ucompressed_key,
  111. p_info->raw_public_key_size + 1,
  112. &p_pub->key.cc310_public_key,
  113. p_temp_data);
  114. cc310_backend_mutex_unlock();
  115. result = nrf_crypto_backend_cc310_ecc_error_convert(crys_error);
  116. if (result == NRF_SUCCESS)
  117. {
  118. p_pub->key_converted = true;
  119. }
  120. else
  121. {
  122. memcpy(p_pub->key.raw_public_key, &ucompressed_key[1], p_info->raw_public_key_size);
  123. }
  124. return result;
  125. }
  126. ret_code_t nrf_crypto_backend_cc310_key_pair_generate(
  127. void * p_context,
  128. void * p_private_key,
  129. void * p_public_key)
  130. {
  131. ret_code_t result;
  132. CRYSError_t crys_error;
  133. CRYS_ECPKI_Domain_t const * p_domain;
  134. bool mutex_locked;
  135. nrf_crypto_backend_cc310_key_pair_generate_context_t * p_ctx =
  136. (nrf_crypto_backend_cc310_key_pair_generate_context_t *)p_context;
  137. nrf_crypto_backend_cc310_ecc_private_key_t * p_prv =
  138. (nrf_crypto_backend_cc310_ecc_private_key_t *)p_private_key;
  139. nrf_crypto_backend_cc310_ecc_public_key_t * p_pub =
  140. (nrf_crypto_backend_cc310_ecc_public_key_t *)p_public_key;
  141. p_domain = get_domain(p_prv->header.p_info);
  142. mutex_locked = cc310_backend_mutex_trylock();
  143. VERIFY_TRUE(mutex_locked, NRF_ERROR_CRYPTO_BUSY);
  144. crys_error = CRYS_ECPKI_GenKeyPair(p_context,
  145. nrf_crypto_backend_cc310_rng,
  146. p_domain,
  147. &p_prv->private_key,
  148. &p_pub->key.cc310_public_key,
  149. &p_ctx->temp_data,
  150. NULL);
  151. cc310_backend_mutex_unlock();
  152. p_pub->key_converted = true;
  153. result = nrf_crypto_backend_cc310_ecc_error_convert(crys_error);
  154. return result;
  155. }
  156. ret_code_t nrf_crypto_backend_cc310_private_key_from_raw(
  157. void * p_private_key,
  158. uint8_t const * p_raw_data)
  159. {
  160. ret_code_t result;
  161. CRYSError_t crys_error;
  162. CRYS_ECPKI_Domain_t const * p_domain;
  163. bool mutex_locked;
  164. nrf_crypto_backend_cc310_ecc_private_key_t * p_prv =
  165. (nrf_crypto_backend_cc310_ecc_private_key_t *)p_private_key;
  166. nrf_crypto_ecc_curve_info_t const * p_info = p_prv->header.p_info;
  167. p_domain = get_domain(p_info);
  168. mutex_locked = cc310_backend_mutex_trylock();
  169. VERIFY_TRUE(mutex_locked, NRF_ERROR_CRYPTO_BUSY);
  170. crys_error = CRYS_ECPKI_BuildPrivKey(p_domain,
  171. p_raw_data,
  172. p_info->raw_private_key_size,
  173. &p_prv->private_key);
  174. cc310_backend_mutex_unlock();
  175. result = nrf_crypto_backend_cc310_ecc_error_convert(crys_error);
  176. return result;
  177. }
  178. ret_code_t nrf_crypto_backend_cc310_private_key_to_raw(
  179. void const * p_private_key,
  180. uint8_t * p_raw_data)
  181. {
  182. ret_code_t result;
  183. CRYSError_t crys_error;
  184. uint32_t key_size;
  185. nrf_crypto_backend_cc310_ecc_private_key_t * p_prv =
  186. (nrf_crypto_backend_cc310_ecc_private_key_t *)p_private_key;
  187. nrf_crypto_ecc_curve_info_t const * p_info = p_prv->header.p_info;
  188. key_size = p_info->raw_private_key_size;
  189. crys_error = CRYS_ECPKI_ExportPrivKey(&p_prv->private_key,
  190. p_raw_data,
  191. &key_size);
  192. if (key_size != p_info->raw_private_key_size)
  193. {
  194. return NRF_ERROR_CRYPTO_INTERNAL;
  195. }
  196. result = nrf_crypto_backend_cc310_ecc_error_convert(crys_error);
  197. return result;
  198. }
  199. ret_code_t nrf_crypto_backend_cc310_public_key_from_raw(
  200. void * p_public_key,
  201. uint8_t const * p_raw_data)
  202. {
  203. nrf_crypto_backend_cc310_ecc_public_key_t * p_pub =
  204. (nrf_crypto_backend_cc310_ecc_public_key_t *)p_public_key;
  205. nrf_crypto_ecc_curve_info_t const * p_info = p_pub->header.p_info;
  206. memcpy(p_pub->key.raw_public_key, p_raw_data, p_info->raw_public_key_size);
  207. p_pub->key_converted = false;
  208. return NRF_SUCCESS;
  209. }
  210. ret_code_t nrf_crypto_backend_cc310_public_key_to_raw(
  211. void const * p_public_key,
  212. uint8_t * p_raw_data)
  213. {
  214. ret_code_t result;
  215. CRYSError_t crys_error;
  216. uint8_t ucompressed_key[NRF_CRYPTO_ECC_RAW_PUBLIC_KEY_MAX_SIZE + 1];
  217. uint32_t key_size;
  218. bool mutex_locked;
  219. nrf_crypto_backend_cc310_ecc_public_key_t * p_pub =
  220. (nrf_crypto_backend_cc310_ecc_public_key_t *)p_public_key;
  221. nrf_crypto_ecc_curve_info_t const * p_info = p_pub->header.p_info;
  222. if (!p_pub->key_converted)
  223. {
  224. memcpy(p_raw_data, p_pub->key.raw_public_key, p_info->raw_public_key_size);
  225. return NRF_SUCCESS;
  226. }
  227. mutex_locked = cc310_backend_mutex_trylock();
  228. if (!mutex_locked)
  229. {
  230. return NRF_ERROR_CRYPTO_BUSY;
  231. }
  232. key_size = p_info->raw_public_key_size + 1;
  233. crys_error = CRYS_ECPKI_ExportPublKey(&p_pub->key.cc310_public_key,
  234. CRYS_EC_PointUncompressed,
  235. ucompressed_key,
  236. &key_size);
  237. cc310_backend_mutex_unlock();
  238. if ((key_size != p_info->raw_public_key_size + 1)
  239. || (ucompressed_key[0] != CC310_UNCOMPRESSED_PUBLIC_KEY_ID_BYTE))
  240. {
  241. return NRF_ERROR_CRYPTO_INTERNAL;
  242. }
  243. memcpy(p_raw_data, &ucompressed_key[1], p_info->raw_public_key_size);
  244. result = nrf_crypto_backend_cc310_ecc_error_convert(crys_error);
  245. return result;
  246. }
  247. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_CURVE25519)
  248. ret_code_t nrf_crypto_backend_cc310_curve25519_key_pair_generate(
  249. void * p_context,
  250. void * p_private_key,
  251. void * p_public_key)
  252. {
  253. ret_code_t result;
  254. CRYSError_t crys_error;
  255. bool mutex_locked;
  256. nrf_crypto_backend_cc310_curve25519_context_t * p_ctx =
  257. (nrf_crypto_backend_cc310_curve25519_context_t *)p_context;
  258. nrf_crypto_backend_curve25519_private_key_t * p_prv =
  259. (nrf_crypto_backend_curve25519_private_key_t *)p_private_key;
  260. nrf_crypto_backend_curve25519_public_key_t * p_pub =
  261. (nrf_crypto_backend_curve25519_public_key_t *)p_public_key;
  262. size_t pub_key_size = sizeof(p_pub->key);
  263. size_t prv_key_size = sizeof(p_prv->key);
  264. mutex_locked = cc310_backend_mutex_trylock();
  265. VERIFY_TRUE(mutex_locked, NRF_ERROR_CRYPTO_BUSY);
  266. crys_error = CRYS_ECMONT_KeyPair(p_pub->key,
  267. &pub_key_size,
  268. p_prv->key,
  269. &prv_key_size,
  270. p_context,
  271. nrf_crypto_backend_cc310_rng,
  272. &p_ctx->temp_data);
  273. cc310_backend_mutex_unlock();
  274. result = nrf_crypto_backend_cc310_ecc_error_convert(crys_error);
  275. return result;
  276. }
  277. ret_code_t nrf_crypto_backend_cc310_curve25519_key_from_raw(
  278. void * p_key,
  279. uint8_t const * p_raw_data)
  280. {
  281. nrf_crypto_backend_curve25519_key_t * p_internal_key =
  282. (nrf_crypto_backend_curve25519_key_t *)p_key;
  283. #if NRF_MODULE_ENABLED(NRF_CRYPTO_CURVE25519_BIG_ENDIAN)
  284. nrf_crypto_internal_swap_endian(p_internal_key->key, p_raw_data, sizeof(p_internal_key->key));
  285. #else
  286. memcpy(p_internal_key->key, p_raw_data, sizeof(p_internal_key->key));
  287. #endif
  288. return NRF_SUCCESS;
  289. }
  290. ret_code_t nrf_crypto_backend_cc310_curve25519_key_to_raw(
  291. void const * p_key,
  292. uint8_t * p_raw_data)
  293. {
  294. nrf_crypto_backend_curve25519_key_t * p_internal_key =
  295. (nrf_crypto_backend_curve25519_key_t *)p_key;
  296. #if NRF_MODULE_ENABLED(NRF_CRYPTO_CURVE25519_BIG_ENDIAN)
  297. nrf_crypto_internal_swap_endian(p_raw_data, p_internal_key->key, sizeof(p_internal_key->key));
  298. #else
  299. memcpy(p_raw_data, p_internal_key->key, sizeof(p_internal_key->key));
  300. #endif
  301. return NRF_SUCCESS;
  302. }
  303. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_CURVE25519)
  304. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_ED25519)
  305. ret_code_t nrf_crypto_backend_cc310_ed25519_key_pair_generate(
  306. void * p_context,
  307. void * p_private_key,
  308. void * p_public_key)
  309. {
  310. ret_code_t result;
  311. CRYSError_t crys_error;
  312. bool mutex_locked;
  313. nrf_crypto_backend_cc310_ed25519_context_t * p_ctx =
  314. (nrf_crypto_backend_cc310_ed25519_context_t *)p_context;
  315. nrf_crypto_backend_ed25519_private_key_t * p_prv =
  316. (nrf_crypto_backend_ed25519_private_key_t *)p_private_key;
  317. nrf_crypto_backend_ed25519_public_key_t * p_pub =
  318. (nrf_crypto_backend_ed25519_public_key_t *)p_public_key;
  319. size_t pub_key_size = sizeof(p_pub->key);
  320. size_t prv_key_size = sizeof(p_prv->key);
  321. mutex_locked = cc310_backend_mutex_trylock();
  322. VERIFY_TRUE(mutex_locked, NRF_ERROR_CRYPTO_BUSY);
  323. crys_error = CRYS_ECEDW_KeyPair(p_prv->key,
  324. &prv_key_size,
  325. p_pub->key,
  326. &pub_key_size,
  327. p_context,
  328. nrf_crypto_backend_cc310_rng,
  329. &p_ctx->temp_data);
  330. cc310_backend_mutex_unlock();
  331. result = nrf_crypto_backend_cc310_ecc_error_convert(crys_error);
  332. return result;
  333. }
  334. ret_code_t nrf_crypto_backend_cc310_ed25519_private_key_from_raw(
  335. void * p_key,
  336. uint8_t const * p_raw_data)
  337. {
  338. uint8_t pub_key_dummy[CRYS_ECEDW_ORD_SIZE_IN_BYTES]; // Throw away buffer
  339. CRYSError_t crys_error;
  340. bool mutex_locked;
  341. ret_code_t result;
  342. CRYS_ECEDW_TempBuff_t * p_temp_data = NULL;
  343. nrf_crypto_backend_ed25519_private_key_t * p_internal_prv_key =
  344. (nrf_crypto_backend_ed25519_private_key_t *)p_key;
  345. size_t prv_key_size = sizeof(p_internal_prv_key->key);
  346. size_t pub_key_size = sizeof(pub_key_dummy);
  347. // Generate public key using CRYS_ECEDW_SeedKeyPair
  348. mutex_locked = cc310_backend_mutex_trylock();
  349. VERIFY_TRUE(mutex_locked, NRF_ERROR_CRYPTO_BUSY);
  350. // Use memory allocation (instead of stack) for the temporary data, as it is ~700 bytes.
  351. p_temp_data = NRF_CRYPTO_ALLOC(sizeof(CRYS_ECEDW_TempBuff_t));
  352. if (p_temp_data == NULL)
  353. {
  354. return NRF_ERROR_CRYPTO_ALLOC_FAILED;
  355. }
  356. crys_error = CRYS_ECEDW_SeedKeyPair(p_raw_data,
  357. CRYS_ECEDW_ORD_SIZE_IN_BYTES,
  358. p_internal_prv_key->key,
  359. &prv_key_size,
  360. pub_key_dummy,
  361. &pub_key_size,
  362. p_temp_data);
  363. cc310_backend_mutex_unlock();
  364. NRF_CRYPTO_FREE(p_temp_data);
  365. result = nrf_crypto_backend_cc310_ecc_error_convert(crys_error);
  366. return result;
  367. }
  368. ret_code_t nrf_crypto_backend_cc310_ed25519_private_key_to_raw(
  369. void const * p_key,
  370. uint8_t * p_raw_data)
  371. {
  372. nrf_crypto_backend_ed25519_private_key_t * p_internal_key =
  373. (nrf_crypto_backend_ed25519_private_key_t *)p_key;
  374. memcpy(p_raw_data, p_internal_key->key, CRYS_ECEDW_ORD_SIZE_IN_BYTES);
  375. return NRF_SUCCESS;
  376. }
  377. ret_code_t nrf_crypto_backend_cc310_ed25519_public_key_from_raw(
  378. void * p_key,
  379. uint8_t const * p_raw_data)
  380. {
  381. nrf_crypto_backend_ed25519_public_key_t * p_internal_key =
  382. (nrf_crypto_backend_ed25519_public_key_t *)p_key;
  383. memcpy(p_internal_key->key, p_raw_data, sizeof(p_internal_key->key));
  384. return NRF_SUCCESS;
  385. }
  386. ret_code_t nrf_crypto_backend_cc310_ed25519_public_key_to_raw(
  387. void const * p_key,
  388. uint8_t * p_raw_data)
  389. {
  390. nrf_crypto_backend_ed25519_public_key_t * p_internal_key =
  391. (nrf_crypto_backend_ed25519_public_key_t *)p_key;
  392. memcpy(p_raw_data, p_internal_key->key, sizeof(p_internal_key->key));
  393. return NRF_SUCCESS;
  394. }
  395. ret_code_t nrf_crypto_backend_ed25519_public_key_calculate(
  396. void * p_context,
  397. void const * p_private_key,
  398. void * p_public_key)
  399. {
  400. nrf_crypto_backend_ed25519_private_key_t * p_prv =
  401. (nrf_crypto_backend_ed25519_private_key_t *)p_private_key;
  402. nrf_crypto_backend_ed25519_public_key_t * p_pub =
  403. (nrf_crypto_backend_ed25519_public_key_t *)p_public_key;
  404. memcpy(p_pub->key, p_prv->key+CRYS_ECEDW_ORD_SIZE_IN_BYTES, CRYS_ECEDW_ORD_SIZE_IN_BYTES);
  405. return NRF_SUCCESS;
  406. }
  407. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_ED25519)
  408. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_SECP160R1)
  409. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp160r1_curve_info =
  410. {
  411. .public_key_size = sizeof(nrf_crypto_backend_cc310_ecc_public_key_t),
  412. .private_key_size = sizeof(nrf_crypto_backend_cc310_ecc_private_key_t),
  413. .curve_type = NRF_CRYPTO_ECC_SECP160R1_CURVE_TYPE,
  414. .raw_private_key_size = NRF_CRYPTO_ECC_SECP160R1_RAW_PRIVATE_KEY_SIZE,
  415. .raw_public_key_size = NRF_CRYPTO_ECC_SECP160R1_RAW_PUBLIC_KEY_SIZE,
  416. .p_backend_data = (void *)CRYS_ECPKI_DomainID_secp160r1,
  417. };
  418. #endif
  419. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_SECP160R2)
  420. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp160r2_curve_info =
  421. {
  422. .public_key_size = sizeof(nrf_crypto_backend_cc310_ecc_public_key_t),
  423. .private_key_size = sizeof(nrf_crypto_backend_cc310_ecc_private_key_t),
  424. .curve_type = NRF_CRYPTO_ECC_SECP160R2_CURVE_TYPE,
  425. .raw_private_key_size = NRF_CRYPTO_ECC_SECP160R2_RAW_PRIVATE_KEY_SIZE,
  426. .raw_public_key_size = NRF_CRYPTO_ECC_SECP160R2_RAW_PUBLIC_KEY_SIZE,
  427. .p_backend_data = (void *)CRYS_ECPKI_DomainID_secp160r2,
  428. };
  429. #endif
  430. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_SECP192R1)
  431. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp192r1_curve_info =
  432. {
  433. .public_key_size = sizeof(nrf_crypto_backend_cc310_ecc_public_key_t),
  434. .private_key_size = sizeof(nrf_crypto_backend_cc310_ecc_private_key_t),
  435. .curve_type = NRF_CRYPTO_ECC_SECP192R1_CURVE_TYPE,
  436. .raw_private_key_size = NRF_CRYPTO_ECC_SECP192R1_RAW_PRIVATE_KEY_SIZE,
  437. .raw_public_key_size = NRF_CRYPTO_ECC_SECP192R1_RAW_PUBLIC_KEY_SIZE,
  438. .p_backend_data = (void *)CRYS_ECPKI_DomainID_secp192r1,
  439. };
  440. #endif
  441. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_SECP224R1)
  442. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp224r1_curve_info =
  443. {
  444. .public_key_size = sizeof(nrf_crypto_backend_cc310_ecc_public_key_t),
  445. .private_key_size = sizeof(nrf_crypto_backend_cc310_ecc_private_key_t),
  446. .curve_type = NRF_CRYPTO_ECC_SECP224R1_CURVE_TYPE,
  447. .raw_private_key_size = NRF_CRYPTO_ECC_SECP224R1_RAW_PRIVATE_KEY_SIZE,
  448. .raw_public_key_size = NRF_CRYPTO_ECC_SECP224R1_RAW_PUBLIC_KEY_SIZE,
  449. .p_backend_data = (void *)CRYS_ECPKI_DomainID_secp224r1,
  450. };
  451. #endif
  452. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_SECP256R1)
  453. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp256r1_curve_info =
  454. {
  455. .public_key_size = sizeof(nrf_crypto_backend_cc310_ecc_public_key_t),
  456. .private_key_size = sizeof(nrf_crypto_backend_cc310_ecc_private_key_t),
  457. .curve_type = NRF_CRYPTO_ECC_SECP256R1_CURVE_TYPE,
  458. .raw_private_key_size = NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE,
  459. .raw_public_key_size = NRF_CRYPTO_ECC_SECP256R1_RAW_PUBLIC_KEY_SIZE,
  460. .p_backend_data = (void *)CRYS_ECPKI_DomainID_secp256r1,
  461. };
  462. #endif
  463. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_SECP384R1)
  464. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp384r1_curve_info =
  465. {
  466. .public_key_size = sizeof(nrf_crypto_backend_cc310_ecc_public_key_t),
  467. .private_key_size = sizeof(nrf_crypto_backend_cc310_ecc_private_key_t),
  468. .curve_type = NRF_CRYPTO_ECC_SECP384R1_CURVE_TYPE,
  469. .raw_private_key_size = NRF_CRYPTO_ECC_SECP384R1_RAW_PRIVATE_KEY_SIZE,
  470. .raw_public_key_size = NRF_CRYPTO_ECC_SECP384R1_RAW_PUBLIC_KEY_SIZE,
  471. .p_backend_data = (void *)CRYS_ECPKI_DomainID_secp384r1,
  472. };
  473. #endif
  474. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_SECP521R1)
  475. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp521r1_curve_info =
  476. {
  477. .public_key_size = sizeof(nrf_crypto_backend_cc310_ecc_public_key_t),
  478. .private_key_size = sizeof(nrf_crypto_backend_cc310_ecc_private_key_t),
  479. .curve_type = NRF_CRYPTO_ECC_SECP521R1_CURVE_TYPE,
  480. .raw_private_key_size = NRF_CRYPTO_ECC_SECP521R1_RAW_PRIVATE_KEY_SIZE,
  481. .raw_public_key_size = NRF_CRYPTO_ECC_SECP521R1_RAW_PUBLIC_KEY_SIZE,
  482. .p_backend_data = (void *)CRYS_ECPKI_DomainID_secp521r1,
  483. };
  484. #endif
  485. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_SECP160K1)
  486. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp160k1_curve_info =
  487. {
  488. .public_key_size = sizeof(nrf_crypto_backend_cc310_ecc_public_key_t),
  489. .private_key_size = sizeof(nrf_crypto_backend_cc310_ecc_private_key_t),
  490. .curve_type = NRF_CRYPTO_ECC_SECP160K1_CURVE_TYPE,
  491. .raw_private_key_size = NRF_CRYPTO_ECC_SECP160K1_RAW_PRIVATE_KEY_SIZE,
  492. .raw_public_key_size = NRF_CRYPTO_ECC_SECP160K1_RAW_PUBLIC_KEY_SIZE,
  493. .p_backend_data = (void *)CRYS_ECPKI_DomainID_secp160k1,
  494. };
  495. #endif
  496. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_SECP192K1)
  497. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp192k1_curve_info =
  498. {
  499. .public_key_size = sizeof(nrf_crypto_backend_cc310_ecc_public_key_t),
  500. .private_key_size = sizeof(nrf_crypto_backend_cc310_ecc_private_key_t),
  501. .curve_type = NRF_CRYPTO_ECC_SECP192K1_CURVE_TYPE,
  502. .raw_private_key_size = NRF_CRYPTO_ECC_SECP192K1_RAW_PRIVATE_KEY_SIZE,
  503. .raw_public_key_size = NRF_CRYPTO_ECC_SECP192K1_RAW_PUBLIC_KEY_SIZE,
  504. .p_backend_data = (void *)CRYS_ECPKI_DomainID_secp192k1,
  505. };
  506. #endif
  507. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_SECP224K1)
  508. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp224k1_curve_info =
  509. {
  510. .public_key_size = sizeof(nrf_crypto_backend_cc310_ecc_public_key_t),
  511. .private_key_size = sizeof(nrf_crypto_backend_cc310_ecc_private_key_t),
  512. .curve_type = NRF_CRYPTO_ECC_SECP224K1_CURVE_TYPE,
  513. .raw_private_key_size = NRF_CRYPTO_ECC_SECP224K1_RAW_PRIVATE_KEY_SIZE,
  514. .raw_public_key_size = NRF_CRYPTO_ECC_SECP224K1_RAW_PUBLIC_KEY_SIZE,
  515. .p_backend_data = (void *)CRYS_ECPKI_DomainID_secp224k1,
  516. };
  517. #endif
  518. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_SECP256K1)
  519. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp256k1_curve_info =
  520. {
  521. .public_key_size = sizeof(nrf_crypto_backend_cc310_ecc_public_key_t),
  522. .private_key_size = sizeof(nrf_crypto_backend_cc310_ecc_private_key_t),
  523. .curve_type = NRF_CRYPTO_ECC_SECP256K1_CURVE_TYPE,
  524. .raw_private_key_size = NRF_CRYPTO_ECC_SECP256K1_RAW_PRIVATE_KEY_SIZE,
  525. .raw_public_key_size = NRF_CRYPTO_ECC_SECP256K1_RAW_PUBLIC_KEY_SIZE,
  526. .p_backend_data = (void *)CRYS_ECPKI_DomainID_secp256k1,
  527. };
  528. #endif
  529. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_CURVE25519)
  530. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_curve25519_curve_info =
  531. {
  532. .public_key_size = sizeof(nrf_crypto_backend_curve25519_public_key_t),
  533. .private_key_size = sizeof(nrf_crypto_backend_curve25519_private_key_t),
  534. .curve_type = NRF_CRYPTO_ECC_CURVE25519_CURVE_TYPE,
  535. .raw_private_key_size = NRF_CRYPTO_ECC_CURVE25519_RAW_PRIVATE_KEY_SIZE,
  536. .raw_public_key_size = NRF_CRYPTO_ECC_CURVE25519_RAW_PUBLIC_KEY_SIZE,
  537. .p_backend_data = (void *)CRYS_ECMONT_DOMAIN_CURVE_25519,
  538. };
  539. #endif
  540. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_ECC_ED25519)
  541. const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_ed25519_curve_info =
  542. {
  543. .public_key_size = sizeof(nrf_crypto_backend_ed25519_public_key_t),
  544. .private_key_size = sizeof(nrf_crypto_backend_ed25519_private_key_t),
  545. .curve_type = NRF_CRYPTO_ECC_ED25519_CURVE_TYPE,
  546. .raw_private_key_size = NRF_CRYPTO_ECC_ED25519_RAW_PRIVATE_KEY_SIZE,
  547. .raw_public_key_size = NRF_CRYPTO_ECC_ED25519_RAW_PUBLIC_KEY_SIZE,
  548. .p_backend_data = NULL,
  549. };
  550. #endif
  551. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310)