nrf_crypto_ecc.h 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  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. #ifndef NRF_CRYPTO_ECC_H__
  41. #define NRF_CRYPTO_ECC_H__
  42. /** @addtogroup nrf_crypto
  43. * @{
  44. * @addtogroup nrf_crypto_ecc Elliptic Curve Cryptography Key Management
  45. * @{
  46. * @brief Provides elliptic curve cryptography API for public and private key management.
  47. *
  48. * @addtogroup nrf_crypto_ecc_secp160r1 Definitions specific to secp160r1 (NIST 160-bit)
  49. * @addtogroup nrf_crypto_ecc_secp160r2 Definitions specific to secp160r2 (NIST 160-bit)
  50. * @addtogroup nrf_crypto_ecc_secp192r1 Definitions specific to secp192r1 (NIST 192-bit)
  51. * @addtogroup nrf_crypto_ecc_secp224r1 Definitions specific to secp224r1 (NIST 224-bit)
  52. * @addtogroup nrf_crypto_ecc_secp256r1 Definitions specific to secp256r1 (NIST 256-bit)
  53. * @addtogroup nrf_crypto_ecc_secp384r1 Definitions specific to secp384r1 (NIST 384-bit)
  54. * @addtogroup nrf_crypto_ecc_secp521r1 Definitions specific to secp521r1 (NIST 521-bit)
  55. * @addtogroup nrf_crypto_ecc_secp160k1 Definitions specific to secp160k1 (Koblitz 160-bit)
  56. * @addtogroup nrf_crypto_ecc_secp192k1 Definitions specific to secp192k1 (Koblitz 192-bit)
  57. * @addtogroup nrf_crypto_ecc_secp224k1 Definitions specific to secp224k1 (Koblitz 224-bit)
  58. * @addtogroup nrf_crypto_ecc_secp256k1 Definitions specific to secp256k1 (Koblitz 256-bit)
  59. * @addtogroup nrf_crypto_ecc_bp256r1 Definitions specific to bp256r1 (Brainpool 256-bit)
  60. * @addtogroup nrf_crypto_ecc_bp384r1 Definitions specific to bp384r1 (Brainpool 384-bit)
  61. * @addtogroup nrf_crypto_ecc_bp512r1 Definitions specific to bp512r1 (Brainpool 512-bit)
  62. * @addtogroup nrf_crypto_ecc_curve25519 Definitions specific to Curve25519
  63. * @addtogroup nrf_crypto_ecc_ed25519 Definitions specific to Ed25519
  64. */
  65. #include <stdint.h>
  66. #include <stddef.h>
  67. #include "nrf_crypto_error.h"
  68. #include "nrf_crypto_ecc_shared.h"
  69. #include "nrf_crypto_ecc_backend.h"
  70. #ifdef __cplusplus
  71. extern "C" {
  72. #endif
  73. #if defined(__SDK_DOXYGEN__)
  74. #define NRF_CRYPTO_ECC_SECP160R1_ENABLED 1 /**< @brief Defined as 1 if secp160r1 (NIST 160-bit) is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_secp160r1 */
  75. #define NRF_CRYPTO_ECC_SECP160R2_ENABLED 1 /**< @brief Defined as 1 if secp160r2 (NIST 160-bit) is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_secp160r2 */
  76. #define NRF_CRYPTO_ECC_SECP192R1_ENABLED 1 /**< @brief Defined as 1 if secp192r1 (NIST 192-bit) is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_secp192r1 */
  77. #define NRF_CRYPTO_ECC_SECP224R1_ENABLED 1 /**< @brief Defined as 1 if secp224r1 (NIST 224-bit) is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_secp224r1 */
  78. #define NRF_CRYPTO_ECC_SECP256R1_ENABLED 1 /**< @brief Defined as 1 if secp256r1 (NIST 256-bit) is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_secp256r1 */
  79. #define NRF_CRYPTO_ECC_SECP384R1_ENABLED 1 /**< @brief Defined as 1 if secp384r1 (NIST 384-bit) is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_secp384r1 */
  80. #define NRF_CRYPTO_ECC_SECP521R1_ENABLED 1 /**< @brief Defined as 1 if secp521r1 (NIST 521-bit) is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_secp521r1 */
  81. #define NRF_CRYPTO_ECC_SECP160K1_ENABLED 1 /**< @brief Defined as 1 if secp160k1 (Koblitz 160-bit) is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_secp160k1 */
  82. #define NRF_CRYPTO_ECC_SECP192K1_ENABLED 1 /**< @brief Defined as 1 if secp192k1 (Koblitz 192-bit) is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_secp192k1 */
  83. #define NRF_CRYPTO_ECC_SECP224K1_ENABLED 1 /**< @brief Defined as 1 if secp224k1 (Koblitz 224-bit) is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_secp224k1 */
  84. #define NRF_CRYPTO_ECC_SECP256K1_ENABLED 1 /**< @brief Defined as 1 if secp256k1 (Koblitz 256-bit) is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_secp256k1 */
  85. #define NRF_CRYPTO_ECC_BP256R1_ENABLED 1 /**< @brief Defined as 1 if bp256r1 (Brainpool 256-bit) is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_bp256r1 */
  86. #define NRF_CRYPTO_ECC_BP384R1_ENABLED 1 /**< @brief Defined as 1 if bp384r1 (Brainpool 384-bit) is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_bp384r1 */
  87. #define NRF_CRYPTO_ECC_BP512R1_ENABLED 1 /**< @brief Defined as 1 if bp512r1 (Brainpool 512-bit) is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_bp512r1 */
  88. #define NRF_CRYPTO_ECC_CURVE25519_ENABLED 1 /**< @brief Defined as 1 if Curve25519 is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_curve25519 */
  89. #define NRF_CRYPTO_ECC_ED25519_ENABLED 1 /**< @brief Defined as 1 if Ed25519 is enabled in any of the backends and it is usable in the API, 0 otherwise. @ingroup nrf_crypto_ecc_ed25519 */
  90. #endif
  91. #define NRF_CRYPTO_ECC_SECP160R1_RAW_PRIVATE_KEY_SIZE (160 / 8) /**< @brief Raw private key size for secp160r1 (NIST 160-bit). @ingroup nrf_crypto_ecc_secp160r1 */
  92. #define NRF_CRYPTO_ECC_SECP160R2_RAW_PRIVATE_KEY_SIZE (160 / 8) /**< @brief Raw private key size for secp160r2 (NIST 160-bit). @ingroup nrf_crypto_ecc_secp160r2 */
  93. #define NRF_CRYPTO_ECC_SECP192R1_RAW_PRIVATE_KEY_SIZE (192 / 8) /**< @brief Raw private key size for secp192r1 (NIST 192-bit). @ingroup nrf_crypto_ecc_secp192r1 */
  94. #define NRF_CRYPTO_ECC_SECP224R1_RAW_PRIVATE_KEY_SIZE (224 / 8) /**< @brief Raw private key size for secp224r1 (NIST 224-bit). @ingroup nrf_crypto_ecc_secp224r1 */
  95. #define NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE (256 / 8) /**< @brief Raw private key size for secp256r1 (NIST 256-bit). @ingroup nrf_crypto_ecc_secp256r1 */
  96. #define NRF_CRYPTO_ECC_SECP384R1_RAW_PRIVATE_KEY_SIZE (384 / 8) /**< @brief Raw private key size for secp384r1 (NIST 384-bit). @ingroup nrf_crypto_ecc_secp384r1 */
  97. #define NRF_CRYPTO_ECC_SECP521R1_RAW_PRIVATE_KEY_SIZE (528 / 8) /**< @brief Raw private key size for secp521r1 (NIST 521-bit). @ingroup nrf_crypto_ecc_secp521r1 */
  98. #define NRF_CRYPTO_ECC_SECP160K1_RAW_PRIVATE_KEY_SIZE (160 / 8) /**< @brief Raw private key size for secp160k1 (Koblitz 160-bit). @ingroup nrf_crypto_ecc_secp160k1 */
  99. #define NRF_CRYPTO_ECC_SECP192K1_RAW_PRIVATE_KEY_SIZE (192 / 8) /**< @brief Raw private key size for secp192k1 (Koblitz 192-bit). @ingroup nrf_crypto_ecc_secp192k1 */
  100. #define NRF_CRYPTO_ECC_SECP224K1_RAW_PRIVATE_KEY_SIZE (224 / 8) /**< @brief Raw private key size for secp224k1 (Koblitz 224-bit). @ingroup nrf_crypto_ecc_secp224k1 */
  101. #define NRF_CRYPTO_ECC_SECP256K1_RAW_PRIVATE_KEY_SIZE (256 / 8) /**< @brief Raw private key size for secp256k1 (Koblitz 256-bit). @ingroup nrf_crypto_ecc_secp256k1 */
  102. #define NRF_CRYPTO_ECC_BP256R1_RAW_PRIVATE_KEY_SIZE (256 / 8) /**< @brief Raw private key size for bp256r1 (Brainpool 256-bit). @ingroup nrf_crypto_ecc_bp256r1 */
  103. #define NRF_CRYPTO_ECC_BP384R1_RAW_PRIVATE_KEY_SIZE (384 / 8) /**< @brief Raw private key size for bp384r1 (Brainpool 384-bit). @ingroup nrf_crypto_ecc_bp384r1 */
  104. #define NRF_CRYPTO_ECC_BP512R1_RAW_PRIVATE_KEY_SIZE (512 / 8) /**< @brief Raw private key size for bp512r1 (Brainpool 512-bit). @ingroup nrf_crypto_ecc_bp512r1 */
  105. #define NRF_CRYPTO_ECC_CURVE25519_RAW_PRIVATE_KEY_SIZE (256 / 8) /**< @brief Raw private key size for Curve25519. @ingroup nrf_crypto_ecc_curve25519 */
  106. #define NRF_CRYPTO_ECC_ED25519_RAW_PRIVATE_KEY_SIZE (256 / 8) /**< @brief Raw private key size for Ed25519. @ingroup nrf_crypto_ecc_ed25519 */
  107. #define NRF_CRYPTO_ECC_SECP160R1_RAW_PUBLIC_KEY_SIZE (2 * 160 / 8) /**< @brief Raw public key size for curve secp160r1 (NIST 160-bit). @ingroup nrf_crypto_ecc_secp160r1 */
  108. #define NRF_CRYPTO_ECC_SECP160R2_RAW_PUBLIC_KEY_SIZE (2 * 160 / 8) /**< @brief Raw public key size for curve secp160r2 (NIST 160-bit). @ingroup nrf_crypto_ecc_secp160r2 */
  109. #define NRF_CRYPTO_ECC_SECP192R1_RAW_PUBLIC_KEY_SIZE (2 * 192 / 8) /**< @brief Raw public key size for curve secp192r1 (NIST 192-bit). @ingroup nrf_crypto_ecc_secp192r1 */
  110. #define NRF_CRYPTO_ECC_SECP224R1_RAW_PUBLIC_KEY_SIZE (2 * 224 / 8) /**< @brief Raw public key size for curve secp224r1 (NIST 224-bit). @ingroup nrf_crypto_ecc_secp224r1 */
  111. #define NRF_CRYPTO_ECC_SECP256R1_RAW_PUBLIC_KEY_SIZE (2 * 256 / 8) /**< @brief Raw public key size for curve secp256r1 (NIST 256-bit). @ingroup nrf_crypto_ecc_secp256r1 */
  112. #define NRF_CRYPTO_ECC_SECP384R1_RAW_PUBLIC_KEY_SIZE (2 * 384 / 8) /**< @brief Raw public key size for curve secp384r1 (NIST 384-bit). @ingroup nrf_crypto_ecc_secp384r1 */
  113. #define NRF_CRYPTO_ECC_SECP521R1_RAW_PUBLIC_KEY_SIZE (2 * 528 / 8) /**< @brief Raw public key size for curve secp521r1 (NIST 521-bit). @ingroup nrf_crypto_ecc_secp521r1 */
  114. #define NRF_CRYPTO_ECC_SECP160K1_RAW_PUBLIC_KEY_SIZE (2 * 160 / 8) /**< @brief Raw public key size for curve secp160k1 (Koblitz 160-bit). @ingroup nrf_crypto_ecc_secp160k1 */
  115. #define NRF_CRYPTO_ECC_SECP192K1_RAW_PUBLIC_KEY_SIZE (2 * 192 / 8) /**< @brief Raw public key size for curve secp192k1 (Koblitz 192-bit). @ingroup nrf_crypto_ecc_secp192k1 */
  116. #define NRF_CRYPTO_ECC_SECP224K1_RAW_PUBLIC_KEY_SIZE (2 * 224 / 8) /**< @brief Raw public key size for curve secp224k1 (Koblitz 224-bit). @ingroup nrf_crypto_ecc_secp224k1 */
  117. #define NRF_CRYPTO_ECC_SECP256K1_RAW_PUBLIC_KEY_SIZE (2 * 256 / 8) /**< @brief Raw public key size for curve secp256k1 (Koblitz 256-bit). @ingroup nrf_crypto_ecc_secp256k1 */
  118. #define NRF_CRYPTO_ECC_BP256R1_RAW_PUBLIC_KEY_SIZE (2 * 256 / 8) /**< @brief Raw public key size for curve bp256r1 (Brainpool 256-bit). @ingroup nrf_crypto_ecc_bp256r1 */
  119. #define NRF_CRYPTO_ECC_BP384R1_RAW_PUBLIC_KEY_SIZE (2 * 384 / 8) /**< @brief Raw public key size for curve bp384r1 (Brainpool 384-bit). @ingroup nrf_crypto_ecc_bp384r1 */
  120. #define NRF_CRYPTO_ECC_BP512R1_RAW_PUBLIC_KEY_SIZE (2 * 512 / 8) /**< @brief Raw public key size for curve bp512r1 (Brainpool 512-bit). @ingroup nrf_crypto_ecc_bp512r1 */
  121. #define NRF_CRYPTO_ECC_CURVE25519_RAW_PUBLIC_KEY_SIZE (256 / 8) /**< @brief Raw public key size for curve Curve25519. @ingroup nrf_crypto_ecc_curve25519 */
  122. #define NRF_CRYPTO_ECC_ED25519_RAW_PUBLIC_KEY_SIZE (256 / 8) /**< @brief Raw public key size for curve Ed25519. @ingroup nrf_crypto_ecc_ed25519 */
  123. #define NRF_CRYPTO_ECC_RAW_PRIVATE_KEY_MAX_SIZE NRF_CRYPTO_BACKEND_ECC_RAW_PRIVATE_KEY_MAX_SIZE /**< @brief Maximum size of a raw private key for all enabled curves. */
  124. #define NRF_CRYPTO_ECC_RAW_PUBLIC_KEY_MAX_SIZE NRF_CRYPTO_BACKEND_ECC_RAW_PUBLIC_KEY_MAX_SIZE /**< @brief Maximum size of a raw public key for all enabled curves. */
  125. /** @brief Defines type of ECC curve.
  126. */
  127. typedef enum
  128. {
  129. #if NRF_CRYPTO_ECC_SECP160R1_ENABLED
  130. NRF_CRYPTO_ECC_SECP160R1_CURVE_TYPE, /**< secp160r1 (NIST 160-bit) */
  131. #endif
  132. #if NRF_CRYPTO_ECC_SECP160R2_ENABLED
  133. NRF_CRYPTO_ECC_SECP160R2_CURVE_TYPE, /**< secp160r2 (NIST 160-bit) */
  134. #endif
  135. #if NRF_CRYPTO_ECC_SECP192R1_ENABLED
  136. NRF_CRYPTO_ECC_SECP192R1_CURVE_TYPE, /**< secp192r1 (NIST 192-bit) */
  137. #endif
  138. #if NRF_CRYPTO_ECC_SECP224R1_ENABLED
  139. NRF_CRYPTO_ECC_SECP224R1_CURVE_TYPE, /**< secp224r1 (NIST 224-bit) */
  140. #endif
  141. #if NRF_CRYPTO_ECC_SECP256R1_ENABLED
  142. NRF_CRYPTO_ECC_SECP256R1_CURVE_TYPE, /**< secp256r1 (NIST 256-bit) */
  143. #endif
  144. #if NRF_CRYPTO_ECC_SECP384R1_ENABLED
  145. NRF_CRYPTO_ECC_SECP384R1_CURVE_TYPE, /**< secp384r1 (NIST 384-bit) */
  146. #endif
  147. #if NRF_CRYPTO_ECC_SECP521R1_ENABLED
  148. NRF_CRYPTO_ECC_SECP521R1_CURVE_TYPE, /**< secp521r1 (NIST 521-bit) */
  149. #endif
  150. #if NRF_CRYPTO_ECC_SECP160K1_ENABLED
  151. NRF_CRYPTO_ECC_SECP160K1_CURVE_TYPE, /**< secp160k1 (Koblitz 160-bit) */
  152. #endif
  153. #if NRF_CRYPTO_ECC_SECP192K1_ENABLED
  154. NRF_CRYPTO_ECC_SECP192K1_CURVE_TYPE, /**< secp192k1 (Koblitz 192-bit) */
  155. #endif
  156. #if NRF_CRYPTO_ECC_SECP224K1_ENABLED
  157. NRF_CRYPTO_ECC_SECP224K1_CURVE_TYPE, /**< secp224k1 (Koblitz 224-bit) */
  158. #endif
  159. #if NRF_CRYPTO_ECC_SECP256K1_ENABLED
  160. NRF_CRYPTO_ECC_SECP256K1_CURVE_TYPE, /**< secp256k1 (Koblitz 256-bit) */
  161. #endif
  162. #if NRF_CRYPTO_ECC_BP256R1_ENABLED
  163. NRF_CRYPTO_ECC_BP256R1_CURVE_TYPE, /**< bp256r1 (Brainpool 256-bit) */
  164. #endif
  165. #if NRF_CRYPTO_ECC_BP384R1_ENABLED
  166. NRF_CRYPTO_ECC_BP384R1_CURVE_TYPE, /**< bp384r1 (Brainpool 384-bit) */
  167. #endif
  168. #if NRF_CRYPTO_ECC_BP512R1_ENABLED
  169. NRF_CRYPTO_ECC_BP512R1_CURVE_TYPE, /**< bp512r1 (Brainpool 512-bit) */
  170. #endif
  171. #if NRF_CRYPTO_ECC_CURVE25519_ENABLED
  172. NRF_CRYPTO_ECC_CURVE25519_CURVE_TYPE, /**< Curve25519 */
  173. #endif
  174. #if NRF_CRYPTO_ECC_ED25519_ENABLED
  175. NRF_CRYPTO_ECC_ED25519_CURVE_TYPE, /**< Ed25519 */
  176. #endif
  177. #if !NRF_CRYPTO_ECC_SECP160R1_ENABLED
  178. NRF_CRYPTO_ECC_SECP160R1_CURVE_TYPE, /**< secp160r1 (NIST 160-bit) */
  179. #endif
  180. #if !NRF_CRYPTO_ECC_SECP160R2_ENABLED
  181. NRF_CRYPTO_ECC_SECP160R2_CURVE_TYPE, /**< secp160r2 (NIST 160-bit) */
  182. #endif
  183. #if !NRF_CRYPTO_ECC_SECP192R1_ENABLED
  184. NRF_CRYPTO_ECC_SECP192R1_CURVE_TYPE, /**< secp192r1 (NIST 192-bit) */
  185. #endif
  186. #if !NRF_CRYPTO_ECC_SECP224R1_ENABLED
  187. NRF_CRYPTO_ECC_SECP224R1_CURVE_TYPE, /**< secp224r1 (NIST 224-bit) */
  188. #endif
  189. #if !NRF_CRYPTO_ECC_SECP256R1_ENABLED
  190. NRF_CRYPTO_ECC_SECP256R1_CURVE_TYPE, /**< secp256r1 (NIST 256-bit) */
  191. #endif
  192. #if !NRF_CRYPTO_ECC_SECP384R1_ENABLED
  193. NRF_CRYPTO_ECC_SECP384R1_CURVE_TYPE, /**< secp384r1 (NIST 384-bit) */
  194. #endif
  195. #if !NRF_CRYPTO_ECC_SECP521R1_ENABLED
  196. NRF_CRYPTO_ECC_SECP521R1_CURVE_TYPE, /**< secp521r1 (NIST 521-bit) */
  197. #endif
  198. #if !NRF_CRYPTO_ECC_SECP160K1_ENABLED
  199. NRF_CRYPTO_ECC_SECP160K1_CURVE_TYPE, /**< secp160k1 (Koblitz 160-bit) */
  200. #endif
  201. #if !NRF_CRYPTO_ECC_SECP192K1_ENABLED
  202. NRF_CRYPTO_ECC_SECP192K1_CURVE_TYPE, /**< secp192k1 (Koblitz 192-bit) */
  203. #endif
  204. #if !NRF_CRYPTO_ECC_SECP224K1_ENABLED
  205. NRF_CRYPTO_ECC_SECP224K1_CURVE_TYPE, /**< secp224k1 (Koblitz 224-bit) */
  206. #endif
  207. #if !NRF_CRYPTO_ECC_SECP256K1_ENABLED
  208. NRF_CRYPTO_ECC_SECP256K1_CURVE_TYPE, /**< secp256k1 (Koblitz 256-bit) */
  209. #endif
  210. #if !NRF_CRYPTO_ECC_BP256R1_ENABLED
  211. NRF_CRYPTO_ECC_BP256R1_CURVE_TYPE, /**< bp256r1 (Brainpool 256-bit) */
  212. #endif
  213. #if !NRF_CRYPTO_ECC_BP384R1_ENABLED
  214. NRF_CRYPTO_ECC_BP384R1_CURVE_TYPE, /**< bp384r1 (Brainpool 384-bit) */
  215. #endif
  216. #if !NRF_CRYPTO_ECC_BP512R1_ENABLED
  217. NRF_CRYPTO_ECC_BP512R1_CURVE_TYPE, /**< bp512r1 (Brainpool 512-bit) */
  218. #endif
  219. #if !NRF_CRYPTO_ECC_CURVE25519_ENABLED
  220. NRF_CRYPTO_ECC_CURVE25519_CURVE_TYPE, /**< Curve25519 */
  221. #endif
  222. #if !NRF_CRYPTO_ECC_ED25519_ENABLED
  223. NRF_CRYPTO_ECC_ED25519_CURVE_TYPE, /**< Ed25519 */
  224. #endif
  225. } nrf_crypto_ecc_curve_type_t;
  226. /** @brief Structure holding information on a specific curve.
  227. *
  228. * @note This structure cannot be used to create a new variable. Only the variables defined by this
  229. * library can be used, e.g. @ref g_nrf_crypto_ecc_secp256r1_curve_info.
  230. */
  231. typedef struct nrf_crypto_ecc_curve_info_s
  232. {
  233. uint16_t public_key_size; /**< @brief Size of a structure holding internal public key. */
  234. uint16_t private_key_size; /**< @brief Size of a structure holding internal private key. */
  235. nrf_crypto_ecc_curve_type_t curve_type; /**< @brief Type of the curve. */
  236. uint8_t raw_private_key_size; /**< @brief Size of a buffer containing raw private key. */
  237. uint8_t raw_public_key_size; /**< @brief Size of a buffer containing raw public key. */
  238. void * p_backend_data; /**< @brief Field to hold backend specific internal data. */
  239. } nrf_crypto_ecc_curve_info_t;
  240. /** @addtogroup nrf_crypto_ecc_secp160r1
  241. * @{ */
  242. typedef nrf_crypto_backend_secp160r1_key_pair_generate_context_t
  243. nrf_crypto_ecc_secp160r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp160r1 (NIST 160-bit). */
  244. typedef nrf_crypto_backend_secp160r1_public_key_calculate_context_t
  245. nrf_crypto_ecc_secp160r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp160r1 (NIST 160-bit). */
  246. typedef nrf_crypto_backend_secp160r1_private_key_t
  247. nrf_crypto_ecc_secp160r1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp160r1 (NIST 160-bit) */
  248. typedef nrf_crypto_backend_secp160r1_public_key_t
  249. nrf_crypto_ecc_secp160r1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp160r1 (NIST 160-bit) */
  250. typedef uint8_t nrf_crypto_ecc_secp160r1_raw_private_key_t
  251. [NRF_CRYPTO_ECC_SECP160R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp160r1 (NIST 160-bit) */
  252. typedef uint8_t nrf_crypto_ecc_secp160r1_raw_public_key_t
  253. [NRF_CRYPTO_ECC_SECP160R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp160r1 (NIST 160-bit) */
  254. /** @brief Variable containing information on secp160r1 (NIST 160-bit).
  255. *
  256. * It can be used as a parameter for the functions creating secp160r1 (NIST 160-bit) keys.
  257. */
  258. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp160r1_curve_info;
  259. /** @} */
  260. /** @addtogroup nrf_crypto_ecc_secp160r2
  261. * @{ */
  262. typedef nrf_crypto_backend_secp160r2_key_pair_generate_context_t
  263. nrf_crypto_ecc_secp160r2_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp160r2 (NIST 160-bit). */
  264. typedef nrf_crypto_backend_secp160r2_public_key_calculate_context_t
  265. nrf_crypto_ecc_secp160r2_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp160r2 (NIST 160-bit). */
  266. typedef nrf_crypto_backend_secp160r2_private_key_t
  267. nrf_crypto_ecc_secp160r2_private_key_t; /**< @brief Structure holding internal representation of a private key for secp160r2 (NIST 160-bit) */
  268. typedef nrf_crypto_backend_secp160r2_public_key_t
  269. nrf_crypto_ecc_secp160r2_public_key_t; /**< @brief Structure holding internal representation of a public key for secp160r2 (NIST 160-bit) */
  270. typedef uint8_t nrf_crypto_ecc_secp160r2_raw_private_key_t
  271. [NRF_CRYPTO_ECC_SECP160R2_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp160r2 (NIST 160-bit) */
  272. typedef uint8_t nrf_crypto_ecc_secp160r2_raw_public_key_t
  273. [NRF_CRYPTO_ECC_SECP160R2_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp160r2 (NIST 160-bit) */
  274. /** @brief Variable containing information on secp160r2 (NIST 160-bit).
  275. *
  276. * It can be used as a parameter for the functions creating secp160r2 (NIST 160-bit) keys.
  277. */
  278. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp160r2_curve_info;
  279. /** @} */
  280. /** @addtogroup nrf_crypto_ecc_secp192r1
  281. * @{ */
  282. typedef nrf_crypto_backend_secp192r1_key_pair_generate_context_t
  283. nrf_crypto_ecc_secp192r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp192r1 (NIST 192-bit). */
  284. typedef nrf_crypto_backend_secp192r1_public_key_calculate_context_t
  285. nrf_crypto_ecc_secp192r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp192r1 (NIST 192-bit). */
  286. typedef nrf_crypto_backend_secp192r1_private_key_t
  287. nrf_crypto_ecc_secp192r1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp192r1 (NIST 192-bit) */
  288. typedef nrf_crypto_backend_secp192r1_public_key_t
  289. nrf_crypto_ecc_secp192r1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp192r1 (NIST 192-bit) */
  290. typedef uint8_t nrf_crypto_ecc_secp192r1_raw_private_key_t
  291. [NRF_CRYPTO_ECC_SECP192R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp192r1 (NIST 192-bit) */
  292. typedef uint8_t nrf_crypto_ecc_secp192r1_raw_public_key_t
  293. [NRF_CRYPTO_ECC_SECP192R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp192r1 (NIST 192-bit) */
  294. /** @brief Variable containing information on secp192r1 (NIST 192-bit).
  295. *
  296. * It can be used as a parameter for the functions creating secp192r1 (NIST 192-bit) keys.
  297. */
  298. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp192r1_curve_info;
  299. /** @} */
  300. /** @addtogroup nrf_crypto_ecc_secp224r1
  301. * @{ */
  302. typedef nrf_crypto_backend_secp224r1_key_pair_generate_context_t
  303. nrf_crypto_ecc_secp224r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp224r1 (NIST 224-bit). */
  304. typedef nrf_crypto_backend_secp224r1_public_key_calculate_context_t
  305. nrf_crypto_ecc_secp224r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp224r1 (NIST 224-bit). */
  306. typedef nrf_crypto_backend_secp224r1_private_key_t
  307. nrf_crypto_ecc_secp224r1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp224r1 (NIST 224-bit) */
  308. typedef nrf_crypto_backend_secp224r1_public_key_t
  309. nrf_crypto_ecc_secp224r1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp224r1 (NIST 224-bit) */
  310. typedef uint8_t nrf_crypto_ecc_secp224r1_raw_private_key_t
  311. [NRF_CRYPTO_ECC_SECP224R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp224r1 (NIST 224-bit) */
  312. typedef uint8_t nrf_crypto_ecc_secp224r1_raw_public_key_t
  313. [NRF_CRYPTO_ECC_SECP224R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp224r1 (NIST 224-bit) */
  314. /** @brief Variable containing information on secp224r1 (NIST 224-bit).
  315. *
  316. * It can be used as a parameter for the functions creating secp224r1 (NIST 224-bit) keys.
  317. */
  318. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp224r1_curve_info;
  319. /** @} */
  320. /** @addtogroup nrf_crypto_ecc_secp256r1
  321. * @{ */
  322. typedef nrf_crypto_backend_secp256r1_key_pair_generate_context_t
  323. nrf_crypto_ecc_secp256r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp256r1 (NIST 256-bit). */
  324. typedef nrf_crypto_backend_secp256r1_public_key_calculate_context_t
  325. nrf_crypto_ecc_secp256r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp256r1 (NIST 256-bit). */
  326. typedef nrf_crypto_backend_secp256r1_private_key_t
  327. nrf_crypto_ecc_secp256r1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp256r1 (NIST 256-bit) */
  328. typedef nrf_crypto_backend_secp256r1_public_key_t
  329. nrf_crypto_ecc_secp256r1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp256r1 (NIST 256-bit) */
  330. typedef uint8_t nrf_crypto_ecc_secp256r1_raw_private_key_t
  331. [NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp256r1 (NIST 256-bit) */
  332. typedef uint8_t nrf_crypto_ecc_secp256r1_raw_public_key_t
  333. [NRF_CRYPTO_ECC_SECP256R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp256r1 (NIST 256-bit) */
  334. /** @brief Variable containing information on secp256r1 (NIST 256-bit).
  335. *
  336. * It can be used as a parameter for the functions creating secp256r1 (NIST 256-bit) keys.
  337. */
  338. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp256r1_curve_info;
  339. /** @} */
  340. /** @addtogroup nrf_crypto_ecc_secp384r1
  341. * @{ */
  342. typedef nrf_crypto_backend_secp384r1_key_pair_generate_context_t
  343. nrf_crypto_ecc_secp384r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp384r1 (NIST 384-bit). */
  344. typedef nrf_crypto_backend_secp384r1_public_key_calculate_context_t
  345. nrf_crypto_ecc_secp384r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp384r1 (NIST 384-bit). */
  346. typedef nrf_crypto_backend_secp384r1_private_key_t
  347. nrf_crypto_ecc_secp384r1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp384r1 (NIST 384-bit) */
  348. typedef nrf_crypto_backend_secp384r1_public_key_t
  349. nrf_crypto_ecc_secp384r1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp384r1 (NIST 384-bit) */
  350. typedef uint8_t nrf_crypto_ecc_secp384r1_raw_private_key_t
  351. [NRF_CRYPTO_ECC_SECP384R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp384r1 (NIST 384-bit) */
  352. typedef uint8_t nrf_crypto_ecc_secp384r1_raw_public_key_t
  353. [NRF_CRYPTO_ECC_SECP384R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp384r1 (NIST 384-bit) */
  354. /** @brief Variable containing information on secp384r1 (NIST 384-bit).
  355. *
  356. * It can be used as a parameter for the functions creating secp384r1 (NIST 384-bit) keys.
  357. */
  358. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp384r1_curve_info;
  359. /** @} */
  360. /** @addtogroup nrf_crypto_ecc_secp521r1
  361. * @{ */
  362. typedef nrf_crypto_backend_secp521r1_key_pair_generate_context_t
  363. nrf_crypto_ecc_secp521r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp521r1 (NIST 521-bit). */
  364. typedef nrf_crypto_backend_secp521r1_public_key_calculate_context_t
  365. nrf_crypto_ecc_secp521r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp521r1 (NIST 521-bit). */
  366. typedef nrf_crypto_backend_secp521r1_private_key_t
  367. nrf_crypto_ecc_secp521r1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp521r1 (NIST 521-bit) */
  368. typedef nrf_crypto_backend_secp521r1_public_key_t
  369. nrf_crypto_ecc_secp521r1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp521r1 (NIST 521-bit) */
  370. typedef uint8_t nrf_crypto_ecc_secp521r1_raw_private_key_t
  371. [NRF_CRYPTO_ECC_SECP521R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp521r1 (NIST 521-bit) */
  372. typedef uint8_t nrf_crypto_ecc_secp521r1_raw_public_key_t
  373. [NRF_CRYPTO_ECC_SECP521R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp521r1 (NIST 521-bit) */
  374. /** @brief Variable containing information on secp521r1 (NIST 521-bit).
  375. *
  376. * It can be used as a parameter for the functions creating secp521r1 (NIST 521-bit) keys.
  377. */
  378. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp521r1_curve_info;
  379. /** @} */
  380. /** @addtogroup nrf_crypto_ecc_secp160k1
  381. * @{ */
  382. typedef nrf_crypto_backend_secp160k1_key_pair_generate_context_t
  383. nrf_crypto_ecc_secp160k1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp160k1 (Koblitz 160-bit). */
  384. typedef nrf_crypto_backend_secp160k1_public_key_calculate_context_t
  385. nrf_crypto_ecc_secp160k1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp160k1 (Koblitz 160-bit). */
  386. typedef nrf_crypto_backend_secp160k1_private_key_t
  387. nrf_crypto_ecc_secp160k1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp160k1 (Koblitz 160-bit) */
  388. typedef nrf_crypto_backend_secp160k1_public_key_t
  389. nrf_crypto_ecc_secp160k1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp160k1 (Koblitz 160-bit) */
  390. typedef uint8_t nrf_crypto_ecc_secp160k1_raw_private_key_t
  391. [NRF_CRYPTO_ECC_SECP160K1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp160k1 (Koblitz 160-bit) */
  392. typedef uint8_t nrf_crypto_ecc_secp160k1_raw_public_key_t
  393. [NRF_CRYPTO_ECC_SECP160K1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp160k1 (Koblitz 160-bit) */
  394. /** @brief Variable containing information on secp160k1 (Koblitz 160-bit).
  395. *
  396. * It can be used as a parameter for the functions creating secp160k1 (Koblitz 160-bit) keys.
  397. */
  398. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp160k1_curve_info;
  399. /** @} */
  400. /** @addtogroup nrf_crypto_ecc_secp192k1
  401. * @{ */
  402. typedef nrf_crypto_backend_secp192k1_key_pair_generate_context_t
  403. nrf_crypto_ecc_secp192k1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp192k1 (Koblitz 192-bit). */
  404. typedef nrf_crypto_backend_secp192k1_public_key_calculate_context_t
  405. nrf_crypto_ecc_secp192k1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp192k1 (Koblitz 192-bit). */
  406. typedef nrf_crypto_backend_secp192k1_private_key_t
  407. nrf_crypto_ecc_secp192k1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp192k1 (Koblitz 192-bit) */
  408. typedef nrf_crypto_backend_secp192k1_public_key_t
  409. nrf_crypto_ecc_secp192k1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp192k1 (Koblitz 192-bit) */
  410. typedef uint8_t nrf_crypto_ecc_secp192k1_raw_private_key_t
  411. [NRF_CRYPTO_ECC_SECP192K1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp192k1 (Koblitz 192-bit) */
  412. typedef uint8_t nrf_crypto_ecc_secp192k1_raw_public_key_t
  413. [NRF_CRYPTO_ECC_SECP192K1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp192k1 (Koblitz 192-bit) */
  414. /** @brief Variable containing information on secp192k1 (Koblitz 192-bit).
  415. *
  416. * It can be used as a parameter for the functions creating secp192k1 (Koblitz 192-bit) keys.
  417. */
  418. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp192k1_curve_info;
  419. /** @} */
  420. /** @addtogroup nrf_crypto_ecc_secp224k1
  421. * @{ */
  422. typedef nrf_crypto_backend_secp224k1_key_pair_generate_context_t
  423. nrf_crypto_ecc_secp224k1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp224k1 (Koblitz 224-bit). */
  424. typedef nrf_crypto_backend_secp224k1_public_key_calculate_context_t
  425. nrf_crypto_ecc_secp224k1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp224k1 (Koblitz 224-bit). */
  426. typedef nrf_crypto_backend_secp224k1_private_key_t
  427. nrf_crypto_ecc_secp224k1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp224k1 (Koblitz 224-bit) */
  428. typedef nrf_crypto_backend_secp224k1_public_key_t
  429. nrf_crypto_ecc_secp224k1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp224k1 (Koblitz 224-bit) */
  430. typedef uint8_t nrf_crypto_ecc_secp224k1_raw_private_key_t
  431. [NRF_CRYPTO_ECC_SECP224K1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp224k1 (Koblitz 224-bit) */
  432. typedef uint8_t nrf_crypto_ecc_secp224k1_raw_public_key_t
  433. [NRF_CRYPTO_ECC_SECP224K1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp224k1 (Koblitz 224-bit) */
  434. /** @brief Variable containing information on secp224k1 (Koblitz 224-bit).
  435. *
  436. * It can be used as a parameter for the functions creating secp224k1 (Koblitz 224-bit) keys.
  437. */
  438. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp224k1_curve_info;
  439. /** @} */
  440. /** @addtogroup nrf_crypto_ecc_secp256k1
  441. * @{ */
  442. typedef nrf_crypto_backend_secp256k1_key_pair_generate_context_t
  443. nrf_crypto_ecc_secp256k1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp256k1 (Koblitz 256-bit). */
  444. typedef nrf_crypto_backend_secp256k1_public_key_calculate_context_t
  445. nrf_crypto_ecc_secp256k1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp256k1 (Koblitz 256-bit). */
  446. typedef nrf_crypto_backend_secp256k1_private_key_t
  447. nrf_crypto_ecc_secp256k1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp256k1 (Koblitz 256-bit) */
  448. typedef nrf_crypto_backend_secp256k1_public_key_t
  449. nrf_crypto_ecc_secp256k1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp256k1 (Koblitz 256-bit) */
  450. typedef uint8_t nrf_crypto_ecc_secp256k1_raw_private_key_t
  451. [NRF_CRYPTO_ECC_SECP256K1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp256k1 (Koblitz 256-bit) */
  452. typedef uint8_t nrf_crypto_ecc_secp256k1_raw_public_key_t
  453. [NRF_CRYPTO_ECC_SECP256K1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp256k1 (Koblitz 256-bit) */
  454. /** @brief Variable containing information on secp256k1 (Koblitz 256-bit).
  455. *
  456. * It can be used as a parameter for the functions creating secp256k1 (Koblitz 256-bit) keys.
  457. */
  458. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp256k1_curve_info;
  459. /** @} */
  460. /** @addtogroup nrf_crypto_ecc_bp256r1
  461. * @{ */
  462. typedef nrf_crypto_backend_bp256r1_key_pair_generate_context_t
  463. nrf_crypto_ecc_bp256r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using bp256r1 (Brainpool 256-bit). */
  464. typedef nrf_crypto_backend_bp256r1_public_key_calculate_context_t
  465. nrf_crypto_ecc_bp256r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using bp256r1 (Brainpool 256-bit). */
  466. typedef nrf_crypto_backend_bp256r1_private_key_t
  467. nrf_crypto_ecc_bp256r1_private_key_t; /**< @brief Structure holding internal representation of a private key for bp256r1 (Brainpool 256-bit) */
  468. typedef nrf_crypto_backend_bp256r1_public_key_t
  469. nrf_crypto_ecc_bp256r1_public_key_t; /**< @brief Structure holding internal representation of a public key for bp256r1 (Brainpool 256-bit) */
  470. typedef uint8_t nrf_crypto_ecc_bp256r1_raw_private_key_t
  471. [NRF_CRYPTO_ECC_BP256R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for bp256r1 (Brainpool 256-bit) */
  472. typedef uint8_t nrf_crypto_ecc_bp256r1_raw_public_key_t
  473. [NRF_CRYPTO_ECC_BP256R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for bp256r1 (Brainpool 256-bit) */
  474. /** @brief Variable containing information on bp256r1 (Brainpool 256-bit).
  475. *
  476. * It can be used as a parameter for the functions creating bp256r1 (Brainpool 256-bit) keys.
  477. */
  478. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_bp256r1_curve_info;
  479. /** @} */
  480. /** @addtogroup nrf_crypto_ecc_bp384r1
  481. * @{ */
  482. typedef nrf_crypto_backend_bp384r1_key_pair_generate_context_t
  483. nrf_crypto_ecc_bp384r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using bp384r1 (Brainpool 384-bit). */
  484. typedef nrf_crypto_backend_bp384r1_public_key_calculate_context_t
  485. nrf_crypto_ecc_bp384r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using bp384r1 (Brainpool 384-bit). */
  486. typedef nrf_crypto_backend_bp384r1_private_key_t
  487. nrf_crypto_ecc_bp384r1_private_key_t; /**< @brief Structure holding internal representation of a private key for bp384r1 (Brainpool 384-bit) */
  488. typedef nrf_crypto_backend_bp384r1_public_key_t
  489. nrf_crypto_ecc_bp384r1_public_key_t; /**< @brief Structure holding internal representation of a public key for bp384r1 (Brainpool 384-bit) */
  490. typedef uint8_t nrf_crypto_ecc_bp384r1_raw_private_key_t
  491. [NRF_CRYPTO_ECC_BP384R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for bp384r1 (Brainpool 384-bit) */
  492. typedef uint8_t nrf_crypto_ecc_bp384r1_raw_public_key_t
  493. [NRF_CRYPTO_ECC_BP384R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for bp384r1 (Brainpool 384-bit) */
  494. /** @brief Variable containing information on bp384r1 (Brainpool 384-bit).
  495. *
  496. * It can be used as a parameter for the functions creating bp384r1 (Brainpool 384-bit) keys.
  497. */
  498. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_bp384r1_curve_info;
  499. /** @} */
  500. /** @addtogroup nrf_crypto_ecc_bp512r1
  501. * @{ */
  502. typedef nrf_crypto_backend_bp512r1_key_pair_generate_context_t
  503. nrf_crypto_ecc_bp512r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using bp512r1 (Brainpool 512-bit). */
  504. typedef nrf_crypto_backend_bp512r1_public_key_calculate_context_t
  505. nrf_crypto_ecc_bp512r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using bp512r1 (Brainpool 512-bit). */
  506. typedef nrf_crypto_backend_bp512r1_private_key_t
  507. nrf_crypto_ecc_bp512r1_private_key_t; /**< @brief Structure holding internal representation of a private key for bp512r1 (Brainpool 512-bit) */
  508. typedef nrf_crypto_backend_bp512r1_public_key_t
  509. nrf_crypto_ecc_bp512r1_public_key_t; /**< @brief Structure holding internal representation of a public key for bp512r1 (Brainpool 512-bit) */
  510. typedef uint8_t nrf_crypto_ecc_bp512r1_raw_private_key_t
  511. [NRF_CRYPTO_ECC_BP512R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for bp512r1 (Brainpool 512-bit) */
  512. typedef uint8_t nrf_crypto_ecc_bp512r1_raw_public_key_t
  513. [NRF_CRYPTO_ECC_BP512R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for bp512r1 (Brainpool 512-bit) */
  514. /** @brief Variable containing information on bp512r1 (Brainpool 512-bit).
  515. *
  516. * It can be used as a parameter for the functions creating bp512r1 (Brainpool 512-bit) keys.
  517. */
  518. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_bp512r1_curve_info;
  519. /** @} */
  520. /** @addtogroup nrf_crypto_ecc_curve25519
  521. * @{ */
  522. typedef nrf_crypto_backend_curve25519_key_pair_generate_context_t
  523. nrf_crypto_ecc_curve25519_key_pair_generate_context_t; /**< @brief Context structure for key generation using Curve25519. */
  524. typedef nrf_crypto_backend_curve25519_public_key_calculate_context_t
  525. nrf_crypto_ecc_curve25519_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using Curve25519. */
  526. typedef nrf_crypto_backend_curve25519_private_key_t
  527. nrf_crypto_ecc_curve25519_private_key_t; /**< @brief Structure holding internal representation of a private key for Curve25519 */
  528. typedef nrf_crypto_backend_curve25519_public_key_t
  529. nrf_crypto_ecc_curve25519_public_key_t; /**< @brief Structure holding internal representation of a public key for Curve25519 */
  530. typedef uint8_t nrf_crypto_ecc_curve25519_raw_private_key_t
  531. [NRF_CRYPTO_ECC_CURVE25519_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for Curve25519 */
  532. typedef uint8_t nrf_crypto_ecc_curve25519_raw_public_key_t
  533. [NRF_CRYPTO_ECC_CURVE25519_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for Curve25519 */
  534. /** @brief Variable containing information on Curve25519.
  535. *
  536. * It can be used as a parameter for the functions creating Curve25519 keys.
  537. */
  538. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_curve25519_curve_info;
  539. /** @} */
  540. /** @addtogroup nrf_crypto_ecc_ed25519
  541. * @{ */
  542. typedef nrf_crypto_backend_ed25519_key_pair_generate_context_t
  543. nrf_crypto_ecc_ed25519_key_pair_generate_context_t; /**< @brief Context structure for key generation using Ed25519. */
  544. typedef nrf_crypto_backend_ed25519_public_key_calculate_context_t
  545. nrf_crypto_ecc_ed25519_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using Ed25519. */
  546. typedef nrf_crypto_backend_ed25519_private_key_t
  547. nrf_crypto_ecc_ed25519_private_key_t; /**< @brief Structure holding internal representation of a private key for Ed25519 */
  548. typedef nrf_crypto_backend_ed25519_public_key_t
  549. nrf_crypto_ecc_ed25519_public_key_t; /**< @brief Structure holding internal representation of a public key for Ed25519 */
  550. typedef uint8_t nrf_crypto_ecc_ed25519_raw_private_key_t
  551. [NRF_CRYPTO_ECC_ED25519_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for Ed25519 */
  552. typedef uint8_t nrf_crypto_ecc_ed25519_raw_public_key_t
  553. [NRF_CRYPTO_ECC_ED25519_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for Ed25519 */
  554. /** @brief Variable containing information on Ed25519.
  555. *
  556. * It can be used as a parameter for the functions creating Ed25519 keys.
  557. */
  558. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_ed25519_curve_info;
  559. /** @} */
  560. typedef uint8_t nrf_crypto_ecc_raw_private_key_t[NRF_CRYPTO_ECC_RAW_PRIVATE_KEY_MAX_SIZE]; /**< @brief Type big enough to hold a raw private key for any the enabled curves. */
  561. typedef uint8_t nrf_crypto_ecc_raw_public_key_t [NRF_CRYPTO_ECC_RAW_PUBLIC_KEY_MAX_SIZE]; /**< @brief Type big enough to hold a raw public key for any the enabled curves. */
  562. /** @brief Union holding a context for a key pair generation.
  563. */
  564. typedef union
  565. {
  566. nrf_crypto_ecc_secp160r1_key_pair_generate_context_t context_secp160r1; /**< @brief Holds context for secp160r1 (NIST 160-bit). */
  567. nrf_crypto_ecc_secp160r2_key_pair_generate_context_t context_secp160r2; /**< @brief Holds context for secp160r2 (NIST 160-bit). */
  568. nrf_crypto_ecc_secp192r1_key_pair_generate_context_t context_secp192r1; /**< @brief Holds context for secp192r1 (NIST 192-bit). */
  569. nrf_crypto_ecc_secp224r1_key_pair_generate_context_t context_secp224r1; /**< @brief Holds context for secp224r1 (NIST 224-bit). */
  570. nrf_crypto_ecc_secp256r1_key_pair_generate_context_t context_secp256r1; /**< @brief Holds context for secp256r1 (NIST 256-bit). */
  571. nrf_crypto_ecc_secp384r1_key_pair_generate_context_t context_secp384r1; /**< @brief Holds context for secp384r1 (NIST 384-bit). */
  572. nrf_crypto_ecc_secp521r1_key_pair_generate_context_t context_secp521r1; /**< @brief Holds context for secp521r1 (NIST 521-bit). */
  573. nrf_crypto_ecc_secp160k1_key_pair_generate_context_t context_secp160k1; /**< @brief Holds context for secp160k1 (Koblitz 160-bit). */
  574. nrf_crypto_ecc_secp192k1_key_pair_generate_context_t context_secp192k1; /**< @brief Holds context for secp192k1 (Koblitz 192-bit). */
  575. nrf_crypto_ecc_secp224k1_key_pair_generate_context_t context_secp224k1; /**< @brief Holds context for secp224k1 (Koblitz 224-bit). */
  576. nrf_crypto_ecc_secp256k1_key_pair_generate_context_t context_secp256k1; /**< @brief Holds context for secp256k1 (Koblitz 256-bit). */
  577. nrf_crypto_ecc_bp256r1_key_pair_generate_context_t context_bp256r1; /**< @brief Holds context for bp256r1 (Brainpool 256-bit). */
  578. nrf_crypto_ecc_bp384r1_key_pair_generate_context_t context_bp384r1; /**< @brief Holds context for bp384r1 (Brainpool 384-bit). */
  579. nrf_crypto_ecc_bp512r1_key_pair_generate_context_t context_bp512r1; /**< @brief Holds context for bp512r1 (Brainpool 512-bit). */
  580. nrf_crypto_ecc_curve25519_key_pair_generate_context_t context_curve25519; /**< @brief Holds context for Curve25519. */
  581. nrf_crypto_ecc_ed25519_key_pair_generate_context_t context_ed25519; /**< @brief Holds context for Ed25519. */
  582. } nrf_crypto_ecc_key_pair_generate_context_t;
  583. /** @brief Union holding a context for a public key calculation.
  584. */
  585. typedef union
  586. {
  587. nrf_crypto_ecc_secp160r1_public_key_calculate_context_t context_secp160r1; /**< @brief Holds context for secp160r1 (NIST 160-bit). */
  588. nrf_crypto_ecc_secp160r2_public_key_calculate_context_t context_secp160r2; /**< @brief Holds context for secp160r2 (NIST 160-bit). */
  589. nrf_crypto_ecc_secp192r1_public_key_calculate_context_t context_secp192r1; /**< @brief Holds context for secp192r1 (NIST 192-bit). */
  590. nrf_crypto_ecc_secp224r1_public_key_calculate_context_t context_secp224r1; /**< @brief Holds context for secp224r1 (NIST 224-bit). */
  591. nrf_crypto_ecc_secp256r1_public_key_calculate_context_t context_secp256r1; /**< @brief Holds context for secp256r1 (NIST 256-bit). */
  592. nrf_crypto_ecc_secp384r1_public_key_calculate_context_t context_secp384r1; /**< @brief Holds context for secp384r1 (NIST 384-bit). */
  593. nrf_crypto_ecc_secp521r1_public_key_calculate_context_t context_secp521r1; /**< @brief Holds context for secp521r1 (NIST 521-bit). */
  594. nrf_crypto_ecc_secp160k1_public_key_calculate_context_t context_secp160k1; /**< @brief Holds context for secp160k1 (Koblitz 160-bit). */
  595. nrf_crypto_ecc_secp192k1_public_key_calculate_context_t context_secp192k1; /**< @brief Holds context for secp192k1 (Koblitz 192-bit). */
  596. nrf_crypto_ecc_secp224k1_public_key_calculate_context_t context_secp224k1; /**< @brief Holds context for secp224k1 (Koblitz 224-bit). */
  597. nrf_crypto_ecc_secp256k1_public_key_calculate_context_t context_secp256k1; /**< @brief Holds context for secp256k1 (Koblitz 256-bit). */
  598. nrf_crypto_ecc_bp256r1_public_key_calculate_context_t context_bp256r1; /**< @brief Holds context for bp256r1 (Brainpool 256-bit). */
  599. nrf_crypto_ecc_bp384r1_public_key_calculate_context_t context_bp384r1; /**< @brief Holds context for bp384r1 (Brainpool 384-bit). */
  600. nrf_crypto_ecc_bp512r1_public_key_calculate_context_t context_bp512r1; /**< @brief Holds context for bp512r1 (Brainpool 512-bit). */
  601. nrf_crypto_ecc_curve25519_public_key_calculate_context_t context_curve25519; /**< @brief Holds context for Curve25519. */
  602. nrf_crypto_ecc_ed25519_public_key_calculate_context_t context_ed25519; /**< @brief Holds context for Ed25519. */
  603. } nrf_crypto_ecc_public_key_calculate_context_t;
  604. /** @brief Union holding representation of a private key for any curve type.
  605. */
  606. typedef union
  607. {
  608. nrf_crypto_ecc_secp160r1_private_key_t key_secp160r1; /**< @brief Holds internal representation of a private key for secp160r1 (NIST 160-bit). */
  609. nrf_crypto_ecc_secp160r2_private_key_t key_secp160r2; /**< @brief Holds internal representation of a private key for secp160r2 (NIST 160-bit). */
  610. nrf_crypto_ecc_secp192r1_private_key_t key_secp192r1; /**< @brief Holds internal representation of a private key for secp192r1 (NIST 192-bit). */
  611. nrf_crypto_ecc_secp224r1_private_key_t key_secp224r1; /**< @brief Holds internal representation of a private key for secp224r1 (NIST 224-bit). */
  612. nrf_crypto_ecc_secp256r1_private_key_t key_secp256r1; /**< @brief Holds internal representation of a private key for secp256r1 (NIST 256-bit). */
  613. nrf_crypto_ecc_secp384r1_private_key_t key_secp384r1; /**< @brief Holds internal representation of a private key for secp384r1 (NIST 384-bit). */
  614. nrf_crypto_ecc_secp521r1_private_key_t key_secp521r1; /**< @brief Holds internal representation of a private key for secp521r1 (NIST 521-bit). */
  615. nrf_crypto_ecc_secp160k1_private_key_t key_secp160k1; /**< @brief Holds internal representation of a private key for secp160k1 (Koblitz 160-bit). */
  616. nrf_crypto_ecc_secp192k1_private_key_t key_secp192k1; /**< @brief Holds internal representation of a private key for secp192k1 (Koblitz 192-bit). */
  617. nrf_crypto_ecc_secp224k1_private_key_t key_secp224k1; /**< @brief Holds internal representation of a private key for secp224k1 (Koblitz 224-bit). */
  618. nrf_crypto_ecc_secp256k1_private_key_t key_secp256k1; /**< @brief Holds internal representation of a private key for secp256k1 (Koblitz 256-bit). */
  619. nrf_crypto_ecc_bp256r1_private_key_t key_bp256r1; /**< @brief Holds internal representation of a private key for bp256r1 (Brainpool 256-bit). */
  620. nrf_crypto_ecc_bp384r1_private_key_t key_bp384r1; /**< @brief Holds internal representation of a private key for bp384r1 (Brainpool 384-bit). */
  621. nrf_crypto_ecc_bp512r1_private_key_t key_bp512r1; /**< @brief Holds internal representation of a private key for bp512r1 (Brainpool 512-bit). */
  622. nrf_crypto_ecc_curve25519_private_key_t key_curve25519; /**< @brief Holds internal representation of a private key for Curve25519. */
  623. nrf_crypto_ecc_ed25519_private_key_t key_ed25519; /**< @brief Holds internal representation of a private key for Ed25519. */
  624. } nrf_crypto_ecc_private_key_t;
  625. /** @brief Union holding representation of a public key for any curve type.
  626. */
  627. typedef union
  628. {
  629. nrf_crypto_ecc_secp160r1_public_key_t key_secp160r1; /**< @brief Holds internal representation of a public key for secp160r1 (NIST 160-bit). */
  630. nrf_crypto_ecc_secp160r2_public_key_t key_secp160r2; /**< @brief Holds internal representation of a public key for secp160r2 (NIST 160-bit). */
  631. nrf_crypto_ecc_secp192r1_public_key_t key_secp192r1; /**< @brief Holds internal representation of a public key for secp192r1 (NIST 192-bit). */
  632. nrf_crypto_ecc_secp224r1_public_key_t key_secp224r1; /**< @brief Holds internal representation of a public key for secp224r1 (NIST 224-bit). */
  633. nrf_crypto_ecc_secp256r1_public_key_t key_secp256r1; /**< @brief Holds internal representation of a public key for secp256r1 (NIST 256-bit). */
  634. nrf_crypto_ecc_secp384r1_public_key_t key_secp384r1; /**< @brief Holds internal representation of a public key for secp384r1 (NIST 384-bit). */
  635. nrf_crypto_ecc_secp521r1_public_key_t key_secp521r1; /**< @brief Holds internal representation of a public key for secp521r1 (NIST 521-bit). */
  636. nrf_crypto_ecc_secp160k1_public_key_t key_secp160k1; /**< @brief Holds internal representation of a public key for secp160k1 (Koblitz 160-bit). */
  637. nrf_crypto_ecc_secp192k1_public_key_t key_secp192k1; /**< @brief Holds internal representation of a public key for secp192k1 (Koblitz 192-bit). */
  638. nrf_crypto_ecc_secp224k1_public_key_t key_secp224k1; /**< @brief Holds internal representation of a public key for secp224k1 (Koblitz 224-bit). */
  639. nrf_crypto_ecc_secp256k1_public_key_t key_secp256k1; /**< @brief Holds internal representation of a public key for secp256k1 (Koblitz 256-bit). */
  640. nrf_crypto_ecc_bp256r1_public_key_t key_bp256r1; /**< @brief Holds internal representation of a public key for bp256r1 (Brainpool 256-bit). */
  641. nrf_crypto_ecc_bp384r1_public_key_t key_bp384r1; /**< @brief Holds internal representation of a public key for bp384r1 (Brainpool 384-bit). */
  642. nrf_crypto_ecc_bp512r1_public_key_t key_bp512r1; /**< @brief Holds internal representation of a public key for bp512r1 (Brainpool 512-bit). */
  643. nrf_crypto_ecc_curve25519_public_key_t key_curve25519; /**< @brief Holds internal representation of a public key for Curve25519. */
  644. nrf_crypto_ecc_ed25519_public_key_t key_ed25519; /**< @brief Holds internal representation of a public key for Ed25519. */
  645. } nrf_crypto_ecc_public_key_t;
  646. /** @brief Generate a new pair of a public key and a private key.
  647. *
  648. * Generated keys have to deallocated using @ref nrf_crypto_ecc_private_key_free and
  649. * @ref nrf_crypto_ecc_public_key_free.
  650. * @param[in] p_context Pointer to temporary structure holding context information.
  651. * If it is NULL, necessary data will be allocated with
  652. * @ref NRF_CRYPTO_ALLOC and freed at the end of the function.
  653. * @param[in] p_curve_info Pointer to information on selected curve. Use only global variables
  654. * defined by nrf_crypto, e.g. @ref g_nrf_crypto_ecc_secp256r1_curve_info.
  655. * @param[out] p_private_key Pointer to structure where newly generated private key will be put.
  656. * @param[out] p_public_key Pointer to structure where newly generated public key will be put.
  657. */
  658. ret_code_t nrf_crypto_ecc_key_pair_generate(
  659. nrf_crypto_ecc_key_pair_generate_context_t * p_context,
  660. nrf_crypto_ecc_curve_info_t const * p_curve_info,
  661. nrf_crypto_ecc_private_key_t * p_private_key,
  662. nrf_crypto_ecc_public_key_t * p_public_key);
  663. /** @brief Calculate public key associated with provided private key.
  664. *
  665. * Calculated public key has to be deallocated using @ref nrf_crypto_ecc_public_key_free.
  666. * @param[in] p_context Pointer to temporary structure holding context information.
  667. * If it is NULL, necessary data will be allocated with
  668. * @ref NRF_CRYPTO_ALLOC and freed at the end of the function.
  669. * @param[in] p_private_key Pointer to structure holding a private key that will be used for computation.
  670. * @param[out] p_public_key Pointer to structure where newly generated public key will be put.
  671. */
  672. ret_code_t nrf_crypto_ecc_public_key_calculate(
  673. nrf_crypto_ecc_public_key_calculate_context_t * p_context,
  674. nrf_crypto_ecc_private_key_t const * p_private_key,
  675. nrf_crypto_ecc_public_key_t * p_public_key);
  676. /** @brief Create a private key from a raw data.
  677. *
  678. * Generated private key has to be deallocated using @ref nrf_crypto_ecc_private_key_free.
  679. *
  680. * @note Ed25519 only: Memory is allocated internally using @ref nrf_crypto_mem.
  681. *
  682. * @param[in] p_curve_info Pointer to information on selected curve. Use only global variables
  683. * defined by nrf_crypto, e.g. @ref g_nrf_crypto_ecc_secp256r1_curve_info.
  684. * @param[out] p_private_key Pointer to structure where newly converted private key will be put.
  685. * @param[in] p_raw_data Pointer to buffer containing a big endian raw data.
  686. * @param[in] raw_data_size Number of bytes of a raw data. Correct size for selected curve can be found in
  687. * @p p_curve_info and it is also defined by the preprocessor definitions, e.g.
  688. * @ref NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE.
  689. */
  690. ret_code_t nrf_crypto_ecc_private_key_from_raw(
  691. nrf_crypto_ecc_curve_info_t const * p_curve_info,
  692. nrf_crypto_ecc_private_key_t * p_private_key,
  693. uint8_t const * p_raw_data,
  694. size_t raw_data_size);
  695. /** @brief Convert a private key to a raw data.
  696. *
  697. * @param[in] p_private_key Pointer to structure holding private key that will be convert.
  698. * @param[out] p_raw_data Pointer to buffer containing a big endian raw data.
  699. * @param[in,out] p_raw_data_size Maximum number of bytes that @p p_raw_data buffer can hold on input
  700. * and the actual number of bytes used by the raw data on output.
  701. * Actual size for selected curve can be found in
  702. * @ref nrf_crypto_ecc_curve_info_t and it is also defined by
  703. * the preprocessor definitions, e.g.
  704. * @ref NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE.
  705. */
  706. ret_code_t nrf_crypto_ecc_private_key_to_raw(
  707. nrf_crypto_ecc_private_key_t const * p_private_key,
  708. uint8_t * p_raw_data,
  709. size_t * p_raw_data_size);
  710. /** @brief Create a public key from a raw data.
  711. *
  712. * Generated public key has to be deallocated using @ref nrf_crypto_ecc_public_key_free.
  713. * @param[in] p_curve_info Pointer to information on selected curve. Use only global variables
  714. * defined by nrf_crypto, e.g. @ref g_nrf_crypto_ecc_secp256r1_curve_info.
  715. * @param[out] p_public_key Pointer to structure where newly converted public key will be put.
  716. * @param[in] p_raw_data Pointer to buffer containing a big endian raw data.
  717. * @param[in] raw_data_size Number of bytes of a raw data. Correct size for selected curve can be found in
  718. * @p p_curve_info and it is also defined by the preprocessor definitions, e.g.
  719. * @ref NRF_CRYPTO_ECC_SECP256R1_RAW_PUBLIC_KEY_SIZE.
  720. */
  721. ret_code_t nrf_crypto_ecc_public_key_from_raw(
  722. nrf_crypto_ecc_curve_info_t const * p_curve_info,
  723. nrf_crypto_ecc_public_key_t * p_public_key,
  724. uint8_t const * p_raw_data,
  725. size_t raw_data_size);
  726. /** @brief Convert a public key to a raw data.
  727. *
  728. * @param[in] p_public_key Pointer to structure holding public key that will be convert.
  729. * @param[out] p_raw_data Pointer to buffer containing a big endian raw data.
  730. * @param[in,out] p_raw_data_size Maximum number of bytes that @p p_raw_data buffer can hold on input
  731. * and the actual number of bytes used by the raw data on output.
  732. * Actual size for selected curve can be found in
  733. * @ref nrf_crypto_ecc_curve_info_t and it is also defined by
  734. * the preprocessor definitions, e.g.
  735. * @ref NRF_CRYPTO_ECC_SECP256R1_RAW_PUBLIC_KEY_SIZE.
  736. */
  737. ret_code_t nrf_crypto_ecc_public_key_to_raw(
  738. nrf_crypto_ecc_public_key_t const * p_public_key,
  739. uint8_t * p_raw_data,
  740. size_t * p_raw_data_size);
  741. /** @brief Release resources taken by a private key.
  742. *
  743. * @param[in] p_private_key Pointer to structure holding private key to release.
  744. */
  745. ret_code_t nrf_crypto_ecc_private_key_free(
  746. nrf_crypto_ecc_private_key_t * p_private_key);
  747. /** @brief Release resources taken by a public key.
  748. *
  749. * @param[in] p_public_key Pointer to structure holding public key to release.
  750. */
  751. ret_code_t nrf_crypto_ecc_public_key_free(
  752. nrf_crypto_ecc_public_key_t * p_public_key);
  753. /** @brief Gets curve information structure from provided key (private or public).
  754. *
  755. * @param[in] p_key Pointer to structure holding private or public key.
  756. * @param[out] pp_curve_info Pointer to location where put retrieved pointer to curve information structure.
  757. */
  758. ret_code_t nrf_crypto_ecc_curve_info_get(
  759. void const * p_key,
  760. nrf_crypto_ecc_curve_info_t const ** pp_curve_info);
  761. /** @brief Inverts byte order of a big integers contained in a raw data.
  762. *
  763. * All the ECC API accepts only data with big endian integers, so this function have to be used
  764. * if little endian is required. If input is in little endian byte order it will be converted
  765. * to big endian. If input is in big endian byte order it will be converted to little endian.
  766. * It works for ECC raw private key, raw public key, signature and shared secret. If raw data
  767. * contains two big integers (e.g. R, S, or X, Y) each integer is inverted separately.
  768. * If @p p_curve_info is NULL then all bytes in buffer will be inverted regardless what is the
  769. * content of the buffer.
  770. *
  771. * @param[in] p_curve_info Pointer to information on selected curve. Use only global variables
  772. * defined by nrf_crypto, e.g. @ref g_nrf_crypto_ecc_secp256r1_curve_info.
  773. * @param[in] p_raw_input Pointer to buffer holding source data.
  774. * @param[out] p_raw_output Pointer to buffer that will be filled with inverted byte order.
  775. * This parameter can be the same as @p p_raw_input, otherwise the
  776. * buffers cannot overlap.
  777. * @param[in] raw_data_size Size of input and output buffer.
  778. */
  779. ret_code_t nrf_crypto_ecc_byte_order_invert(
  780. nrf_crypto_ecc_curve_info_t const * p_curve_info,
  781. uint8_t const * p_raw_input,
  782. uint8_t * p_raw_output,
  783. size_t raw_data_size);
  784. #ifdef __cplusplus
  785. }
  786. #endif
  787. /** @}
  788. * @}
  789. */
  790. #endif // NRF_CRYPTO_ECC_H__