nrf_crypto_ecc.h 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. /**
  2. * Copyright (c) 2018, 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. #if NRF_CRYPTO_ECC_SECP160R1_ENABLED
  255. /** @brief Variable containing information on secp160r1 (NIST 160-bit).
  256. *
  257. * It can be used as a parameter for the functions creating secp160r1 (NIST 160-bit) keys.
  258. */
  259. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp160r1_curve_info;
  260. #endif
  261. /** @} */
  262. /** @addtogroup nrf_crypto_ecc_secp160r2
  263. * @{ */
  264. typedef nrf_crypto_backend_secp160r2_key_pair_generate_context_t
  265. nrf_crypto_ecc_secp160r2_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp160r2 (NIST 160-bit). */
  266. typedef nrf_crypto_backend_secp160r2_public_key_calculate_context_t
  267. nrf_crypto_ecc_secp160r2_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp160r2 (NIST 160-bit). */
  268. typedef nrf_crypto_backend_secp160r2_private_key_t
  269. nrf_crypto_ecc_secp160r2_private_key_t; /**< @brief Structure holding internal representation of a private key for secp160r2 (NIST 160-bit) */
  270. typedef nrf_crypto_backend_secp160r2_public_key_t
  271. nrf_crypto_ecc_secp160r2_public_key_t; /**< @brief Structure holding internal representation of a public key for secp160r2 (NIST 160-bit) */
  272. typedef uint8_t nrf_crypto_ecc_secp160r2_raw_private_key_t
  273. [NRF_CRYPTO_ECC_SECP160R2_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp160r2 (NIST 160-bit) */
  274. typedef uint8_t nrf_crypto_ecc_secp160r2_raw_public_key_t
  275. [NRF_CRYPTO_ECC_SECP160R2_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp160r2 (NIST 160-bit) */
  276. #if NRF_CRYPTO_ECC_SECP160R2_ENABLED
  277. /** @brief Variable containing information on secp160r2 (NIST 160-bit).
  278. *
  279. * It can be used as a parameter for the functions creating secp160r2 (NIST 160-bit) keys.
  280. */
  281. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp160r2_curve_info;
  282. #endif
  283. /** @} */
  284. /** @addtogroup nrf_crypto_ecc_secp192r1
  285. * @{ */
  286. typedef nrf_crypto_backend_secp192r1_key_pair_generate_context_t
  287. nrf_crypto_ecc_secp192r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp192r1 (NIST 192-bit). */
  288. typedef nrf_crypto_backend_secp192r1_public_key_calculate_context_t
  289. nrf_crypto_ecc_secp192r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp192r1 (NIST 192-bit). */
  290. typedef nrf_crypto_backend_secp192r1_private_key_t
  291. nrf_crypto_ecc_secp192r1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp192r1 (NIST 192-bit) */
  292. typedef nrf_crypto_backend_secp192r1_public_key_t
  293. nrf_crypto_ecc_secp192r1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp192r1 (NIST 192-bit) */
  294. typedef uint8_t nrf_crypto_ecc_secp192r1_raw_private_key_t
  295. [NRF_CRYPTO_ECC_SECP192R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp192r1 (NIST 192-bit) */
  296. typedef uint8_t nrf_crypto_ecc_secp192r1_raw_public_key_t
  297. [NRF_CRYPTO_ECC_SECP192R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp192r1 (NIST 192-bit) */
  298. #if NRF_CRYPTO_ECC_SECP192R1_ENABLED
  299. /** @brief Variable containing information on secp192r1 (NIST 192-bit).
  300. *
  301. * It can be used as a parameter for the functions creating secp192r1 (NIST 192-bit) keys.
  302. */
  303. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp192r1_curve_info;
  304. #endif
  305. /** @} */
  306. /** @addtogroup nrf_crypto_ecc_secp224r1
  307. * @{ */
  308. typedef nrf_crypto_backend_secp224r1_key_pair_generate_context_t
  309. nrf_crypto_ecc_secp224r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp224r1 (NIST 224-bit). */
  310. typedef nrf_crypto_backend_secp224r1_public_key_calculate_context_t
  311. nrf_crypto_ecc_secp224r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp224r1 (NIST 224-bit). */
  312. typedef nrf_crypto_backend_secp224r1_private_key_t
  313. nrf_crypto_ecc_secp224r1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp224r1 (NIST 224-bit) */
  314. typedef nrf_crypto_backend_secp224r1_public_key_t
  315. nrf_crypto_ecc_secp224r1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp224r1 (NIST 224-bit) */
  316. typedef uint8_t nrf_crypto_ecc_secp224r1_raw_private_key_t
  317. [NRF_CRYPTO_ECC_SECP224R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp224r1 (NIST 224-bit) */
  318. typedef uint8_t nrf_crypto_ecc_secp224r1_raw_public_key_t
  319. [NRF_CRYPTO_ECC_SECP224R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp224r1 (NIST 224-bit) */
  320. #if NRF_CRYPTO_ECC_SECP224R1_ENABLED
  321. /** @brief Variable containing information on secp224r1 (NIST 224-bit).
  322. *
  323. * It can be used as a parameter for the functions creating secp224r1 (NIST 224-bit) keys.
  324. */
  325. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp224r1_curve_info;
  326. #endif
  327. /** @} */
  328. /** @addtogroup nrf_crypto_ecc_secp256r1
  329. * @{ */
  330. typedef nrf_crypto_backend_secp256r1_key_pair_generate_context_t
  331. nrf_crypto_ecc_secp256r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp256r1 (NIST 256-bit). */
  332. typedef nrf_crypto_backend_secp256r1_public_key_calculate_context_t
  333. nrf_crypto_ecc_secp256r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp256r1 (NIST 256-bit). */
  334. typedef nrf_crypto_backend_secp256r1_private_key_t
  335. nrf_crypto_ecc_secp256r1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp256r1 (NIST 256-bit) */
  336. typedef nrf_crypto_backend_secp256r1_public_key_t
  337. nrf_crypto_ecc_secp256r1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp256r1 (NIST 256-bit) */
  338. typedef uint8_t nrf_crypto_ecc_secp256r1_raw_private_key_t
  339. [NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp256r1 (NIST 256-bit) */
  340. typedef uint8_t nrf_crypto_ecc_secp256r1_raw_public_key_t
  341. [NRF_CRYPTO_ECC_SECP256R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp256r1 (NIST 256-bit) */
  342. #if NRF_CRYPTO_ECC_SECP256R1_ENABLED
  343. /** @brief Variable containing information on secp256r1 (NIST 256-bit).
  344. *
  345. * It can be used as a parameter for the functions creating secp256r1 (NIST 256-bit) keys.
  346. */
  347. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp256r1_curve_info;
  348. #endif
  349. /** @} */
  350. /** @addtogroup nrf_crypto_ecc_secp384r1
  351. * @{ */
  352. typedef nrf_crypto_backend_secp384r1_key_pair_generate_context_t
  353. nrf_crypto_ecc_secp384r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp384r1 (NIST 384-bit). */
  354. typedef nrf_crypto_backend_secp384r1_public_key_calculate_context_t
  355. nrf_crypto_ecc_secp384r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp384r1 (NIST 384-bit). */
  356. typedef nrf_crypto_backend_secp384r1_private_key_t
  357. nrf_crypto_ecc_secp384r1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp384r1 (NIST 384-bit) */
  358. typedef nrf_crypto_backend_secp384r1_public_key_t
  359. nrf_crypto_ecc_secp384r1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp384r1 (NIST 384-bit) */
  360. typedef uint8_t nrf_crypto_ecc_secp384r1_raw_private_key_t
  361. [NRF_CRYPTO_ECC_SECP384R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp384r1 (NIST 384-bit) */
  362. typedef uint8_t nrf_crypto_ecc_secp384r1_raw_public_key_t
  363. [NRF_CRYPTO_ECC_SECP384R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp384r1 (NIST 384-bit) */
  364. #if NRF_CRYPTO_ECC_SECP384R1_ENABLED
  365. /** @brief Variable containing information on secp384r1 (NIST 384-bit).
  366. *
  367. * It can be used as a parameter for the functions creating secp384r1 (NIST 384-bit) keys.
  368. */
  369. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp384r1_curve_info;
  370. #endif
  371. /** @} */
  372. /** @addtogroup nrf_crypto_ecc_secp521r1
  373. * @{ */
  374. typedef nrf_crypto_backend_secp521r1_key_pair_generate_context_t
  375. nrf_crypto_ecc_secp521r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp521r1 (NIST 521-bit). */
  376. typedef nrf_crypto_backend_secp521r1_public_key_calculate_context_t
  377. nrf_crypto_ecc_secp521r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp521r1 (NIST 521-bit). */
  378. typedef nrf_crypto_backend_secp521r1_private_key_t
  379. nrf_crypto_ecc_secp521r1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp521r1 (NIST 521-bit) */
  380. typedef nrf_crypto_backend_secp521r1_public_key_t
  381. nrf_crypto_ecc_secp521r1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp521r1 (NIST 521-bit) */
  382. typedef uint8_t nrf_crypto_ecc_secp521r1_raw_private_key_t
  383. [NRF_CRYPTO_ECC_SECP521R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp521r1 (NIST 521-bit) */
  384. typedef uint8_t nrf_crypto_ecc_secp521r1_raw_public_key_t
  385. [NRF_CRYPTO_ECC_SECP521R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp521r1 (NIST 521-bit) */
  386. #if NRF_CRYPTO_ECC_SECP521R1_ENABLED
  387. /** @brief Variable containing information on secp521r1 (NIST 521-bit).
  388. *
  389. * It can be used as a parameter for the functions creating secp521r1 (NIST 521-bit) keys.
  390. */
  391. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp521r1_curve_info;
  392. #endif
  393. /** @} */
  394. /** @addtogroup nrf_crypto_ecc_secp160k1
  395. * @{ */
  396. typedef nrf_crypto_backend_secp160k1_key_pair_generate_context_t
  397. nrf_crypto_ecc_secp160k1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp160k1 (Koblitz 160-bit). */
  398. typedef nrf_crypto_backend_secp160k1_public_key_calculate_context_t
  399. nrf_crypto_ecc_secp160k1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp160k1 (Koblitz 160-bit). */
  400. typedef nrf_crypto_backend_secp160k1_private_key_t
  401. nrf_crypto_ecc_secp160k1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp160k1 (Koblitz 160-bit) */
  402. typedef nrf_crypto_backend_secp160k1_public_key_t
  403. nrf_crypto_ecc_secp160k1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp160k1 (Koblitz 160-bit) */
  404. typedef uint8_t nrf_crypto_ecc_secp160k1_raw_private_key_t
  405. [NRF_CRYPTO_ECC_SECP160K1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp160k1 (Koblitz 160-bit) */
  406. typedef uint8_t nrf_crypto_ecc_secp160k1_raw_public_key_t
  407. [NRF_CRYPTO_ECC_SECP160K1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp160k1 (Koblitz 160-bit) */
  408. #if NRF_CRYPTO_ECC_SECP160K1_ENABLED
  409. /** @brief Variable containing information on secp160k1 (Koblitz 160-bit).
  410. *
  411. * It can be used as a parameter for the functions creating secp160k1 (Koblitz 160-bit) keys.
  412. */
  413. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp160k1_curve_info;
  414. #endif
  415. /** @} */
  416. /** @addtogroup nrf_crypto_ecc_secp192k1
  417. * @{ */
  418. typedef nrf_crypto_backend_secp192k1_key_pair_generate_context_t
  419. nrf_crypto_ecc_secp192k1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp192k1 (Koblitz 192-bit). */
  420. typedef nrf_crypto_backend_secp192k1_public_key_calculate_context_t
  421. nrf_crypto_ecc_secp192k1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp192k1 (Koblitz 192-bit). */
  422. typedef nrf_crypto_backend_secp192k1_private_key_t
  423. nrf_crypto_ecc_secp192k1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp192k1 (Koblitz 192-bit) */
  424. typedef nrf_crypto_backend_secp192k1_public_key_t
  425. nrf_crypto_ecc_secp192k1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp192k1 (Koblitz 192-bit) */
  426. typedef uint8_t nrf_crypto_ecc_secp192k1_raw_private_key_t
  427. [NRF_CRYPTO_ECC_SECP192K1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp192k1 (Koblitz 192-bit) */
  428. typedef uint8_t nrf_crypto_ecc_secp192k1_raw_public_key_t
  429. [NRF_CRYPTO_ECC_SECP192K1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp192k1 (Koblitz 192-bit) */
  430. #if NRF_CRYPTO_ECC_SECP192K1_ENABLED
  431. /** @brief Variable containing information on secp192k1 (Koblitz 192-bit).
  432. *
  433. * It can be used as a parameter for the functions creating secp192k1 (Koblitz 192-bit) keys.
  434. */
  435. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp192k1_curve_info;
  436. #endif
  437. /** @} */
  438. /** @addtogroup nrf_crypto_ecc_secp224k1
  439. * @{ */
  440. typedef nrf_crypto_backend_secp224k1_key_pair_generate_context_t
  441. nrf_crypto_ecc_secp224k1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp224k1 (Koblitz 224-bit). */
  442. typedef nrf_crypto_backend_secp224k1_public_key_calculate_context_t
  443. nrf_crypto_ecc_secp224k1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp224k1 (Koblitz 224-bit). */
  444. typedef nrf_crypto_backend_secp224k1_private_key_t
  445. nrf_crypto_ecc_secp224k1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp224k1 (Koblitz 224-bit) */
  446. typedef nrf_crypto_backend_secp224k1_public_key_t
  447. nrf_crypto_ecc_secp224k1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp224k1 (Koblitz 224-bit) */
  448. typedef uint8_t nrf_crypto_ecc_secp224k1_raw_private_key_t
  449. [NRF_CRYPTO_ECC_SECP224K1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp224k1 (Koblitz 224-bit) */
  450. typedef uint8_t nrf_crypto_ecc_secp224k1_raw_public_key_t
  451. [NRF_CRYPTO_ECC_SECP224K1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp224k1 (Koblitz 224-bit) */
  452. #if NRF_CRYPTO_ECC_SECP224K1_ENABLED
  453. /** @brief Variable containing information on secp224k1 (Koblitz 224-bit).
  454. *
  455. * It can be used as a parameter for the functions creating secp224k1 (Koblitz 224-bit) keys.
  456. */
  457. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp224k1_curve_info;
  458. #endif
  459. /** @} */
  460. /** @addtogroup nrf_crypto_ecc_secp256k1
  461. * @{ */
  462. typedef nrf_crypto_backend_secp256k1_key_pair_generate_context_t
  463. nrf_crypto_ecc_secp256k1_key_pair_generate_context_t; /**< @brief Context structure for key generation using secp256k1 (Koblitz 256-bit). */
  464. typedef nrf_crypto_backend_secp256k1_public_key_calculate_context_t
  465. nrf_crypto_ecc_secp256k1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using secp256k1 (Koblitz 256-bit). */
  466. typedef nrf_crypto_backend_secp256k1_private_key_t
  467. nrf_crypto_ecc_secp256k1_private_key_t; /**< @brief Structure holding internal representation of a private key for secp256k1 (Koblitz 256-bit) */
  468. typedef nrf_crypto_backend_secp256k1_public_key_t
  469. nrf_crypto_ecc_secp256k1_public_key_t; /**< @brief Structure holding internal representation of a public key for secp256k1 (Koblitz 256-bit) */
  470. typedef uint8_t nrf_crypto_ecc_secp256k1_raw_private_key_t
  471. [NRF_CRYPTO_ECC_SECP256K1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for secp256k1 (Koblitz 256-bit) */
  472. typedef uint8_t nrf_crypto_ecc_secp256k1_raw_public_key_t
  473. [NRF_CRYPTO_ECC_SECP256K1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for secp256k1 (Koblitz 256-bit) */
  474. #if NRF_CRYPTO_ECC_SECP256K1_ENABLED
  475. /** @brief Variable containing information on secp256k1 (Koblitz 256-bit).
  476. *
  477. * It can be used as a parameter for the functions creating secp256k1 (Koblitz 256-bit) keys.
  478. */
  479. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_secp256k1_curve_info;
  480. #endif
  481. /** @} */
  482. /** @addtogroup nrf_crypto_ecc_bp256r1
  483. * @{ */
  484. typedef nrf_crypto_backend_bp256r1_key_pair_generate_context_t
  485. nrf_crypto_ecc_bp256r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using bp256r1 (Brainpool 256-bit). */
  486. typedef nrf_crypto_backend_bp256r1_public_key_calculate_context_t
  487. nrf_crypto_ecc_bp256r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using bp256r1 (Brainpool 256-bit). */
  488. typedef nrf_crypto_backend_bp256r1_private_key_t
  489. nrf_crypto_ecc_bp256r1_private_key_t; /**< @brief Structure holding internal representation of a private key for bp256r1 (Brainpool 256-bit) */
  490. typedef nrf_crypto_backend_bp256r1_public_key_t
  491. nrf_crypto_ecc_bp256r1_public_key_t; /**< @brief Structure holding internal representation of a public key for bp256r1 (Brainpool 256-bit) */
  492. typedef uint8_t nrf_crypto_ecc_bp256r1_raw_private_key_t
  493. [NRF_CRYPTO_ECC_BP256R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for bp256r1 (Brainpool 256-bit) */
  494. typedef uint8_t nrf_crypto_ecc_bp256r1_raw_public_key_t
  495. [NRF_CRYPTO_ECC_BP256R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for bp256r1 (Brainpool 256-bit) */
  496. #if NRF_CRYPTO_ECC_BP256R1_ENABLED
  497. /** @brief Variable containing information on bp256r1 (Brainpool 256-bit).
  498. *
  499. * It can be used as a parameter for the functions creating bp256r1 (Brainpool 256-bit) keys.
  500. */
  501. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_bp256r1_curve_info;
  502. #endif
  503. /** @} */
  504. /** @addtogroup nrf_crypto_ecc_bp384r1
  505. * @{ */
  506. typedef nrf_crypto_backend_bp384r1_key_pair_generate_context_t
  507. nrf_crypto_ecc_bp384r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using bp384r1 (Brainpool 384-bit). */
  508. typedef nrf_crypto_backend_bp384r1_public_key_calculate_context_t
  509. nrf_crypto_ecc_bp384r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using bp384r1 (Brainpool 384-bit). */
  510. typedef nrf_crypto_backend_bp384r1_private_key_t
  511. nrf_crypto_ecc_bp384r1_private_key_t; /**< @brief Structure holding internal representation of a private key for bp384r1 (Brainpool 384-bit) */
  512. typedef nrf_crypto_backend_bp384r1_public_key_t
  513. nrf_crypto_ecc_bp384r1_public_key_t; /**< @brief Structure holding internal representation of a public key for bp384r1 (Brainpool 384-bit) */
  514. typedef uint8_t nrf_crypto_ecc_bp384r1_raw_private_key_t
  515. [NRF_CRYPTO_ECC_BP384R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for bp384r1 (Brainpool 384-bit) */
  516. typedef uint8_t nrf_crypto_ecc_bp384r1_raw_public_key_t
  517. [NRF_CRYPTO_ECC_BP384R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for bp384r1 (Brainpool 384-bit) */
  518. #if NRF_CRYPTO_ECC_BP384R1_ENABLED
  519. /** @brief Variable containing information on bp384r1 (Brainpool 384-bit).
  520. *
  521. * It can be used as a parameter for the functions creating bp384r1 (Brainpool 384-bit) keys.
  522. */
  523. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_bp384r1_curve_info;
  524. #endif
  525. /** @} */
  526. /** @addtogroup nrf_crypto_ecc_bp512r1
  527. * @{ */
  528. typedef nrf_crypto_backend_bp512r1_key_pair_generate_context_t
  529. nrf_crypto_ecc_bp512r1_key_pair_generate_context_t; /**< @brief Context structure for key generation using bp512r1 (Brainpool 512-bit). */
  530. typedef nrf_crypto_backend_bp512r1_public_key_calculate_context_t
  531. nrf_crypto_ecc_bp512r1_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using bp512r1 (Brainpool 512-bit). */
  532. typedef nrf_crypto_backend_bp512r1_private_key_t
  533. nrf_crypto_ecc_bp512r1_private_key_t; /**< @brief Structure holding internal representation of a private key for bp512r1 (Brainpool 512-bit) */
  534. typedef nrf_crypto_backend_bp512r1_public_key_t
  535. nrf_crypto_ecc_bp512r1_public_key_t; /**< @brief Structure holding internal representation of a public key for bp512r1 (Brainpool 512-bit) */
  536. typedef uint8_t nrf_crypto_ecc_bp512r1_raw_private_key_t
  537. [NRF_CRYPTO_ECC_BP512R1_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for bp512r1 (Brainpool 512-bit) */
  538. typedef uint8_t nrf_crypto_ecc_bp512r1_raw_public_key_t
  539. [NRF_CRYPTO_ECC_BP512R1_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for bp512r1 (Brainpool 512-bit) */
  540. #if NRF_CRYPTO_ECC_BP512R1_ENABLED
  541. /** @brief Variable containing information on bp512r1 (Brainpool 512-bit).
  542. *
  543. * It can be used as a parameter for the functions creating bp512r1 (Brainpool 512-bit) keys.
  544. */
  545. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_bp512r1_curve_info;
  546. #endif
  547. /** @} */
  548. /** @addtogroup nrf_crypto_ecc_curve25519
  549. * @{ */
  550. typedef nrf_crypto_backend_curve25519_key_pair_generate_context_t
  551. nrf_crypto_ecc_curve25519_key_pair_generate_context_t; /**< @brief Context structure for key generation using Curve25519. */
  552. typedef nrf_crypto_backend_curve25519_public_key_calculate_context_t
  553. nrf_crypto_ecc_curve25519_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using Curve25519. */
  554. typedef nrf_crypto_backend_curve25519_private_key_t
  555. nrf_crypto_ecc_curve25519_private_key_t; /**< @brief Structure holding internal representation of a private key for Curve25519 */
  556. typedef nrf_crypto_backend_curve25519_public_key_t
  557. nrf_crypto_ecc_curve25519_public_key_t; /**< @brief Structure holding internal representation of a public key for Curve25519 */
  558. typedef uint8_t nrf_crypto_ecc_curve25519_raw_private_key_t
  559. [NRF_CRYPTO_ECC_CURVE25519_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for Curve25519 */
  560. typedef uint8_t nrf_crypto_ecc_curve25519_raw_public_key_t
  561. [NRF_CRYPTO_ECC_CURVE25519_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for Curve25519 */
  562. #if NRF_CRYPTO_ECC_CURVE25519_ENABLED
  563. /** @brief Variable containing information on Curve25519.
  564. *
  565. * It can be used as a parameter for the functions creating Curve25519 keys.
  566. */
  567. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_curve25519_curve_info;
  568. #endif
  569. /** @} */
  570. /** @addtogroup nrf_crypto_ecc_ed25519
  571. * @{ */
  572. typedef nrf_crypto_backend_ed25519_key_pair_generate_context_t
  573. nrf_crypto_ecc_ed25519_key_pair_generate_context_t; /**< @brief Context structure for key generation using Ed25519. */
  574. typedef nrf_crypto_backend_ed25519_public_key_calculate_context_t
  575. nrf_crypto_ecc_ed25519_public_key_calculate_context_t; /**< @brief Context structure for public key calculation using Ed25519. */
  576. typedef nrf_crypto_backend_ed25519_private_key_t
  577. nrf_crypto_ecc_ed25519_private_key_t; /**< @brief Structure holding internal representation of a private key for Ed25519 */
  578. typedef nrf_crypto_backend_ed25519_public_key_t
  579. nrf_crypto_ecc_ed25519_public_key_t; /**< @brief Structure holding internal representation of a public key for Ed25519 */
  580. typedef uint8_t nrf_crypto_ecc_ed25519_raw_private_key_t
  581. [NRF_CRYPTO_ECC_ED25519_RAW_PRIVATE_KEY_SIZE]; /**< @brief Array holding raw private key for Ed25519 */
  582. typedef uint8_t nrf_crypto_ecc_ed25519_raw_public_key_t
  583. [NRF_CRYPTO_ECC_ED25519_RAW_PUBLIC_KEY_SIZE]; /**< @brief Array holding raw public key for Ed25519 */
  584. #if NRF_CRYPTO_ECC_ED25519_ENABLED
  585. /** @brief Variable containing information on Ed25519.
  586. *
  587. * It can be used as a parameter for the functions creating Ed25519 keys.
  588. */
  589. extern const nrf_crypto_ecc_curve_info_t g_nrf_crypto_ecc_ed25519_curve_info;
  590. #endif
  591. /** @} */
  592. 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. */
  593. 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. */
  594. /** @brief Union holding a context for a key pair generation.
  595. */
  596. typedef union
  597. {
  598. nrf_crypto_ecc_secp160r1_key_pair_generate_context_t context_secp160r1; /**< @brief Holds context for secp160r1 (NIST 160-bit). */
  599. nrf_crypto_ecc_secp160r2_key_pair_generate_context_t context_secp160r2; /**< @brief Holds context for secp160r2 (NIST 160-bit). */
  600. nrf_crypto_ecc_secp192r1_key_pair_generate_context_t context_secp192r1; /**< @brief Holds context for secp192r1 (NIST 192-bit). */
  601. nrf_crypto_ecc_secp224r1_key_pair_generate_context_t context_secp224r1; /**< @brief Holds context for secp224r1 (NIST 224-bit). */
  602. nrf_crypto_ecc_secp256r1_key_pair_generate_context_t context_secp256r1; /**< @brief Holds context for secp256r1 (NIST 256-bit). */
  603. nrf_crypto_ecc_secp384r1_key_pair_generate_context_t context_secp384r1; /**< @brief Holds context for secp384r1 (NIST 384-bit). */
  604. nrf_crypto_ecc_secp521r1_key_pair_generate_context_t context_secp521r1; /**< @brief Holds context for secp521r1 (NIST 521-bit). */
  605. nrf_crypto_ecc_secp160k1_key_pair_generate_context_t context_secp160k1; /**< @brief Holds context for secp160k1 (Koblitz 160-bit). */
  606. nrf_crypto_ecc_secp192k1_key_pair_generate_context_t context_secp192k1; /**< @brief Holds context for secp192k1 (Koblitz 192-bit). */
  607. nrf_crypto_ecc_secp224k1_key_pair_generate_context_t context_secp224k1; /**< @brief Holds context for secp224k1 (Koblitz 224-bit). */
  608. nrf_crypto_ecc_secp256k1_key_pair_generate_context_t context_secp256k1; /**< @brief Holds context for secp256k1 (Koblitz 256-bit). */
  609. nrf_crypto_ecc_bp256r1_key_pair_generate_context_t context_bp256r1; /**< @brief Holds context for bp256r1 (Brainpool 256-bit). */
  610. nrf_crypto_ecc_bp384r1_key_pair_generate_context_t context_bp384r1; /**< @brief Holds context for bp384r1 (Brainpool 384-bit). */
  611. nrf_crypto_ecc_bp512r1_key_pair_generate_context_t context_bp512r1; /**< @brief Holds context for bp512r1 (Brainpool 512-bit). */
  612. nrf_crypto_ecc_curve25519_key_pair_generate_context_t context_curve25519; /**< @brief Holds context for Curve25519. */
  613. nrf_crypto_ecc_ed25519_key_pair_generate_context_t context_ed25519; /**< @brief Holds context for Ed25519. */
  614. } nrf_crypto_ecc_key_pair_generate_context_t;
  615. /** @brief Union holding a context for a public key calculation.
  616. */
  617. typedef union
  618. {
  619. nrf_crypto_ecc_secp160r1_public_key_calculate_context_t context_secp160r1; /**< @brief Holds context for secp160r1 (NIST 160-bit). */
  620. nrf_crypto_ecc_secp160r2_public_key_calculate_context_t context_secp160r2; /**< @brief Holds context for secp160r2 (NIST 160-bit). */
  621. nrf_crypto_ecc_secp192r1_public_key_calculate_context_t context_secp192r1; /**< @brief Holds context for secp192r1 (NIST 192-bit). */
  622. nrf_crypto_ecc_secp224r1_public_key_calculate_context_t context_secp224r1; /**< @brief Holds context for secp224r1 (NIST 224-bit). */
  623. nrf_crypto_ecc_secp256r1_public_key_calculate_context_t context_secp256r1; /**< @brief Holds context for secp256r1 (NIST 256-bit). */
  624. nrf_crypto_ecc_secp384r1_public_key_calculate_context_t context_secp384r1; /**< @brief Holds context for secp384r1 (NIST 384-bit). */
  625. nrf_crypto_ecc_secp521r1_public_key_calculate_context_t context_secp521r1; /**< @brief Holds context for secp521r1 (NIST 521-bit). */
  626. nrf_crypto_ecc_secp160k1_public_key_calculate_context_t context_secp160k1; /**< @brief Holds context for secp160k1 (Koblitz 160-bit). */
  627. nrf_crypto_ecc_secp192k1_public_key_calculate_context_t context_secp192k1; /**< @brief Holds context for secp192k1 (Koblitz 192-bit). */
  628. nrf_crypto_ecc_secp224k1_public_key_calculate_context_t context_secp224k1; /**< @brief Holds context for secp224k1 (Koblitz 224-bit). */
  629. nrf_crypto_ecc_secp256k1_public_key_calculate_context_t context_secp256k1; /**< @brief Holds context for secp256k1 (Koblitz 256-bit). */
  630. nrf_crypto_ecc_bp256r1_public_key_calculate_context_t context_bp256r1; /**< @brief Holds context for bp256r1 (Brainpool 256-bit). */
  631. nrf_crypto_ecc_bp384r1_public_key_calculate_context_t context_bp384r1; /**< @brief Holds context for bp384r1 (Brainpool 384-bit). */
  632. nrf_crypto_ecc_bp512r1_public_key_calculate_context_t context_bp512r1; /**< @brief Holds context for bp512r1 (Brainpool 512-bit). */
  633. nrf_crypto_ecc_curve25519_public_key_calculate_context_t context_curve25519; /**< @brief Holds context for Curve25519. */
  634. nrf_crypto_ecc_ed25519_public_key_calculate_context_t context_ed25519; /**< @brief Holds context for Ed25519. */
  635. } nrf_crypto_ecc_public_key_calculate_context_t;
  636. /** @brief Union holding representation of a private key for any curve type.
  637. */
  638. typedef union
  639. {
  640. nrf_crypto_ecc_secp160r1_private_key_t key_secp160r1; /**< @brief Holds internal representation of a private key for secp160r1 (NIST 160-bit). */
  641. nrf_crypto_ecc_secp160r2_private_key_t key_secp160r2; /**< @brief Holds internal representation of a private key for secp160r2 (NIST 160-bit). */
  642. nrf_crypto_ecc_secp192r1_private_key_t key_secp192r1; /**< @brief Holds internal representation of a private key for secp192r1 (NIST 192-bit). */
  643. nrf_crypto_ecc_secp224r1_private_key_t key_secp224r1; /**< @brief Holds internal representation of a private key for secp224r1 (NIST 224-bit). */
  644. nrf_crypto_ecc_secp256r1_private_key_t key_secp256r1; /**< @brief Holds internal representation of a private key for secp256r1 (NIST 256-bit). */
  645. nrf_crypto_ecc_secp384r1_private_key_t key_secp384r1; /**< @brief Holds internal representation of a private key for secp384r1 (NIST 384-bit). */
  646. nrf_crypto_ecc_secp521r1_private_key_t key_secp521r1; /**< @brief Holds internal representation of a private key for secp521r1 (NIST 521-bit). */
  647. nrf_crypto_ecc_secp160k1_private_key_t key_secp160k1; /**< @brief Holds internal representation of a private key for secp160k1 (Koblitz 160-bit). */
  648. nrf_crypto_ecc_secp192k1_private_key_t key_secp192k1; /**< @brief Holds internal representation of a private key for secp192k1 (Koblitz 192-bit). */
  649. nrf_crypto_ecc_secp224k1_private_key_t key_secp224k1; /**< @brief Holds internal representation of a private key for secp224k1 (Koblitz 224-bit). */
  650. nrf_crypto_ecc_secp256k1_private_key_t key_secp256k1; /**< @brief Holds internal representation of a private key for secp256k1 (Koblitz 256-bit). */
  651. nrf_crypto_ecc_bp256r1_private_key_t key_bp256r1; /**< @brief Holds internal representation of a private key for bp256r1 (Brainpool 256-bit). */
  652. nrf_crypto_ecc_bp384r1_private_key_t key_bp384r1; /**< @brief Holds internal representation of a private key for bp384r1 (Brainpool 384-bit). */
  653. nrf_crypto_ecc_bp512r1_private_key_t key_bp512r1; /**< @brief Holds internal representation of a private key for bp512r1 (Brainpool 512-bit). */
  654. nrf_crypto_ecc_curve25519_private_key_t key_curve25519; /**< @brief Holds internal representation of a private key for Curve25519. */
  655. nrf_crypto_ecc_ed25519_private_key_t key_ed25519; /**< @brief Holds internal representation of a private key for Ed25519. */
  656. } nrf_crypto_ecc_private_key_t;
  657. /** @brief Union holding representation of a public key for any curve type.
  658. */
  659. typedef union
  660. {
  661. nrf_crypto_ecc_secp160r1_public_key_t key_secp160r1; /**< @brief Holds internal representation of a public key for secp160r1 (NIST 160-bit). */
  662. nrf_crypto_ecc_secp160r2_public_key_t key_secp160r2; /**< @brief Holds internal representation of a public key for secp160r2 (NIST 160-bit). */
  663. nrf_crypto_ecc_secp192r1_public_key_t key_secp192r1; /**< @brief Holds internal representation of a public key for secp192r1 (NIST 192-bit). */
  664. nrf_crypto_ecc_secp224r1_public_key_t key_secp224r1; /**< @brief Holds internal representation of a public key for secp224r1 (NIST 224-bit). */
  665. nrf_crypto_ecc_secp256r1_public_key_t key_secp256r1; /**< @brief Holds internal representation of a public key for secp256r1 (NIST 256-bit). */
  666. nrf_crypto_ecc_secp384r1_public_key_t key_secp384r1; /**< @brief Holds internal representation of a public key for secp384r1 (NIST 384-bit). */
  667. nrf_crypto_ecc_secp521r1_public_key_t key_secp521r1; /**< @brief Holds internal representation of a public key for secp521r1 (NIST 521-bit). */
  668. nrf_crypto_ecc_secp160k1_public_key_t key_secp160k1; /**< @brief Holds internal representation of a public key for secp160k1 (Koblitz 160-bit). */
  669. nrf_crypto_ecc_secp192k1_public_key_t key_secp192k1; /**< @brief Holds internal representation of a public key for secp192k1 (Koblitz 192-bit). */
  670. nrf_crypto_ecc_secp224k1_public_key_t key_secp224k1; /**< @brief Holds internal representation of a public key for secp224k1 (Koblitz 224-bit). */
  671. nrf_crypto_ecc_secp256k1_public_key_t key_secp256k1; /**< @brief Holds internal representation of a public key for secp256k1 (Koblitz 256-bit). */
  672. nrf_crypto_ecc_bp256r1_public_key_t key_bp256r1; /**< @brief Holds internal representation of a public key for bp256r1 (Brainpool 256-bit). */
  673. nrf_crypto_ecc_bp384r1_public_key_t key_bp384r1; /**< @brief Holds internal representation of a public key for bp384r1 (Brainpool 384-bit). */
  674. nrf_crypto_ecc_bp512r1_public_key_t key_bp512r1; /**< @brief Holds internal representation of a public key for bp512r1 (Brainpool 512-bit). */
  675. nrf_crypto_ecc_curve25519_public_key_t key_curve25519; /**< @brief Holds internal representation of a public key for Curve25519. */
  676. nrf_crypto_ecc_ed25519_public_key_t key_ed25519; /**< @brief Holds internal representation of a public key for Ed25519. */
  677. } nrf_crypto_ecc_public_key_t;
  678. /** @brief Generate a new pair of a public key and a private key.
  679. *
  680. * Generated keys have to deallocated using @ref nrf_crypto_ecc_private_key_free and
  681. * @ref nrf_crypto_ecc_public_key_free.
  682. * @param[in] p_context Pointer to temporary structure holding context information.
  683. * If it is NULL, necessary data will be allocated with
  684. * @ref NRF_CRYPTO_ALLOC and freed at the end of the function.
  685. * @param[in] p_curve_info Pointer to information on selected curve. Use only global variables
  686. * defined by nrf_crypto, e.g. @ref g_nrf_crypto_ecc_secp256r1_curve_info.
  687. * @param[out] p_private_key Pointer to structure where newly generated private key will be put.
  688. * @param[out] p_public_key Pointer to structure where newly generated public key will be put.
  689. */
  690. ret_code_t nrf_crypto_ecc_key_pair_generate(
  691. nrf_crypto_ecc_key_pair_generate_context_t * p_context,
  692. nrf_crypto_ecc_curve_info_t const * p_curve_info,
  693. nrf_crypto_ecc_private_key_t * p_private_key,
  694. nrf_crypto_ecc_public_key_t * p_public_key);
  695. /** @brief Calculate public key associated with provided private key.
  696. *
  697. * Calculated public key has to be deallocated using @ref nrf_crypto_ecc_public_key_free.
  698. * @param[in] p_context Pointer to temporary structure holding context information.
  699. * If it is NULL, necessary data will be allocated with
  700. * @ref NRF_CRYPTO_ALLOC and freed at the end of the function.
  701. * @param[in] p_private_key Pointer to structure holding a private key that will be used for computation.
  702. * @param[out] p_public_key Pointer to structure where newly generated public key will be put.
  703. */
  704. ret_code_t nrf_crypto_ecc_public_key_calculate(
  705. nrf_crypto_ecc_public_key_calculate_context_t * p_context,
  706. nrf_crypto_ecc_private_key_t const * p_private_key,
  707. nrf_crypto_ecc_public_key_t * p_public_key);
  708. /** @brief Create a private key from a raw data.
  709. *
  710. * Generated private key has to be deallocated using @ref nrf_crypto_ecc_private_key_free.
  711. *
  712. * @note Ed25519 only: Memory is allocated internally using @ref nrf_crypto_mem.
  713. *
  714. * @param[in] p_curve_info Pointer to information on selected curve. Use only global variables
  715. * defined by nrf_crypto, e.g. @ref g_nrf_crypto_ecc_secp256r1_curve_info.
  716. * @param[out] p_private_key Pointer to structure where newly converted private key will be put.
  717. * @param[in] p_raw_data Pointer to buffer containing a big endian raw data.
  718. * @param[in] raw_data_size Number of bytes of a raw data. Correct size for selected curve can be found in
  719. * @p p_curve_info and it is also defined by the preprocessor definitions, e.g.
  720. * @ref NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE.
  721. */
  722. ret_code_t nrf_crypto_ecc_private_key_from_raw(
  723. nrf_crypto_ecc_curve_info_t const * p_curve_info,
  724. nrf_crypto_ecc_private_key_t * p_private_key,
  725. uint8_t const * p_raw_data,
  726. size_t raw_data_size);
  727. /** @brief Convert a private key to a raw data.
  728. *
  729. * @param[in] p_private_key Pointer to structure holding private key that will be convert.
  730. * @param[out] p_raw_data Pointer to buffer containing a big endian raw data.
  731. * @param[in,out] p_raw_data_size Maximum number of bytes that @p p_raw_data buffer can hold on input
  732. * and the actual number of bytes used by the raw data on output.
  733. * Actual size for selected curve can be found in
  734. * @ref nrf_crypto_ecc_curve_info_t and it is also defined by
  735. * the preprocessor definitions, e.g.
  736. * @ref NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE.
  737. */
  738. ret_code_t nrf_crypto_ecc_private_key_to_raw(
  739. nrf_crypto_ecc_private_key_t const * p_private_key,
  740. uint8_t * p_raw_data,
  741. size_t * p_raw_data_size);
  742. /** @brief Create a public key from a raw data.
  743. *
  744. * Generated public key has to be deallocated using @ref nrf_crypto_ecc_public_key_free.
  745. * @param[in] p_curve_info Pointer to information on selected curve. Use only global variables
  746. * defined by nrf_crypto, e.g. @ref g_nrf_crypto_ecc_secp256r1_curve_info.
  747. * @param[out] p_public_key Pointer to structure where newly converted public key will be put.
  748. * @param[in] p_raw_data Pointer to buffer containing a big endian raw data.
  749. * @param[in] raw_data_size Number of bytes of a raw data. Correct size for selected curve can be found in
  750. * @p p_curve_info and it is also defined by the preprocessor definitions, e.g.
  751. * @ref NRF_CRYPTO_ECC_SECP256R1_RAW_PUBLIC_KEY_SIZE.
  752. */
  753. ret_code_t nrf_crypto_ecc_public_key_from_raw(
  754. nrf_crypto_ecc_curve_info_t const * p_curve_info,
  755. nrf_crypto_ecc_public_key_t * p_public_key,
  756. uint8_t const * p_raw_data,
  757. size_t raw_data_size);
  758. /** @brief Convert a public key to a raw data.
  759. *
  760. * @param[in] p_public_key Pointer to structure holding public key that will be convert.
  761. * @param[out] p_raw_data Pointer to buffer containing a big endian raw data.
  762. * @param[in,out] p_raw_data_size Maximum number of bytes that @p p_raw_data buffer can hold on input
  763. * and the actual number of bytes used by the raw data on output.
  764. * Actual size for selected curve can be found in
  765. * @ref nrf_crypto_ecc_curve_info_t and it is also defined by
  766. * the preprocessor definitions, e.g.
  767. * @ref NRF_CRYPTO_ECC_SECP256R1_RAW_PUBLIC_KEY_SIZE.
  768. */
  769. ret_code_t nrf_crypto_ecc_public_key_to_raw(
  770. nrf_crypto_ecc_public_key_t const * p_public_key,
  771. uint8_t * p_raw_data,
  772. size_t * p_raw_data_size);
  773. /** @brief Release resources taken by a private key.
  774. *
  775. * @param[in] p_private_key Pointer to structure holding private key to release.
  776. */
  777. ret_code_t nrf_crypto_ecc_private_key_free(
  778. nrf_crypto_ecc_private_key_t * p_private_key);
  779. /** @brief Release resources taken by a public key.
  780. *
  781. * @param[in] p_public_key Pointer to structure holding public key to release.
  782. */
  783. ret_code_t nrf_crypto_ecc_public_key_free(
  784. nrf_crypto_ecc_public_key_t * p_public_key);
  785. /** @brief Gets curve information structure from provided key (private or public).
  786. *
  787. * @param[in] p_key Pointer to structure holding private or public key.
  788. * @param[out] pp_curve_info Pointer to location where put retrieved pointer to curve information structure.
  789. */
  790. ret_code_t nrf_crypto_ecc_curve_info_get(
  791. void const * p_key,
  792. nrf_crypto_ecc_curve_info_t const ** pp_curve_info);
  793. /** @brief Inverts byte order of a big integers contained in a raw data.
  794. *
  795. * All the ECC API accepts only data with big endian integers, so this function have to be used
  796. * if little endian is required. If input is in little endian byte order it will be converted
  797. * to big endian. If input is in big endian byte order it will be converted to little endian.
  798. * It works for ECC raw private key, raw public key, signature and shared secret. If raw data
  799. * contains two big integers (e.g. R, S, or X, Y) each integer is inverted separately.
  800. * If @p p_curve_info is NULL then all bytes in buffer will be inverted regardless what is the
  801. * content of the buffer.
  802. *
  803. * @param[in] p_curve_info Pointer to information on selected curve. Use only global variables
  804. * defined by nrf_crypto, e.g. @ref g_nrf_crypto_ecc_secp256r1_curve_info.
  805. * @param[in] p_raw_input Pointer to buffer holding source data.
  806. * @param[out] p_raw_output Pointer to buffer that will be filled with inverted byte order.
  807. * This parameter can be the same as @p p_raw_input, otherwise the
  808. * buffers cannot overlap.
  809. * @param[in] raw_data_size Size of input and output buffer.
  810. */
  811. ret_code_t nrf_crypto_ecc_byte_order_invert(
  812. nrf_crypto_ecc_curve_info_t const * p_curve_info,
  813. uint8_t const * p_raw_input,
  814. uint8_t * p_raw_output,
  815. size_t raw_data_size);
  816. #ifdef __cplusplus
  817. }
  818. #endif
  819. /** @}
  820. * @}
  821. */
  822. #endif // NRF_CRYPTO_ECC_H__