nrf_crypto_ecdsa.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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_ECDSA_H__
  41. #define NRF_CRYPTO_ECDSA_H__
  42. /** @addtogroup nrf_crypto
  43. * @{
  44. * @addtogroup nrf_crypto_ecdsa Elliptic Curve Digital Signature (ECDSA)
  45. * @{
  46. * @brief Provides elliptic curve cryptography functions for digital signature.
  47. *
  48. * @addtogroup nrf_crypto_ecdsa_secp160r1 Definitions specific to secp160r1 (NIST 160-bit)
  49. * @addtogroup nrf_crypto_ecdsa_secp160r2 Definitions specific to secp160r2 (NIST 160-bit)
  50. * @addtogroup nrf_crypto_ecdsa_secp192r1 Definitions specific to secp192r1 (NIST 192-bit)
  51. * @addtogroup nrf_crypto_ecdsa_secp224r1 Definitions specific to secp224r1 (NIST 224-bit)
  52. * @addtogroup nrf_crypto_ecdsa_secp256r1 Definitions specific to secp256r1 (NIST 256-bit)
  53. * @addtogroup nrf_crypto_ecdsa_secp384r1 Definitions specific to secp384r1 (NIST 384-bit)
  54. * @addtogroup nrf_crypto_ecdsa_secp521r1 Definitions specific to secp521r1 (NIST 521-bit)
  55. * @addtogroup nrf_crypto_ecdsa_secp160k1 Definitions specific to secp160k1 (Koblitz 160-bit)
  56. * @addtogroup nrf_crypto_ecdsa_secp192k1 Definitions specific to secp192k1 (Koblitz 192-bit)
  57. * @addtogroup nrf_crypto_ecdsa_secp224k1 Definitions specific to secp224k1 (Koblitz 224-bit)
  58. * @addtogroup nrf_crypto_ecdsa_secp256k1 Definitions specific to secp256k1 (Koblitz 256-bit)
  59. * @addtogroup nrf_crypto_ecdsa_bp256r1 Definitions specific to bp256r1 (Brainpool 256-bit)
  60. * @addtogroup nrf_crypto_ecdsa_bp384r1 Definitions specific to bp384r1 (Brainpool 384-bit)
  61. * @addtogroup nrf_crypto_ecdsa_bp512r1 Definitions specific to bp512r1 (Brainpool 512-bit)
  62. * @addtogroup nrf_crypto_ecdsa_curve25519 Definitions specific to Curve25519
  63. */
  64. #include <stdint.h>
  65. #include <stddef.h>
  66. #include "nrf_crypto_error.h"
  67. #include "nrf_crypto_ecc.h"
  68. #include "nrf_crypto_ecdsa_shared.h"
  69. #include "nrf_crypto_ecdsa_backend.h"
  70. #ifdef __cplusplus
  71. extern "C" {
  72. #endif
  73. #define NRF_CRYPTO_ECDSA_SECP160R1_SIGNATURE_SIZE (2 * 160 / 8) /**< @brief Size of a signature for secp160r1 (NIST 160-bit) curve. @ingroup nrf_crypto_ecdsa_secp160r1 */
  74. #define NRF_CRYPTO_ECDSA_SECP160R2_SIGNATURE_SIZE (2 * 160 / 8) /**< @brief Size of a signature for secp160r2 (NIST 160-bit) curve. @ingroup nrf_crypto_ecdsa_secp160r2 */
  75. #define NRF_CRYPTO_ECDSA_SECP192R1_SIGNATURE_SIZE (2 * 192 / 8) /**< @brief Size of a signature for secp192r1 (NIST 192-bit) curve. @ingroup nrf_crypto_ecdsa_secp192r1 */
  76. #define NRF_CRYPTO_ECDSA_SECP224R1_SIGNATURE_SIZE (2 * 224 / 8) /**< @brief Size of a signature for secp224r1 (NIST 224-bit) curve. @ingroup nrf_crypto_ecdsa_secp224r1 */
  77. #define NRF_CRYPTO_ECDSA_SECP256R1_SIGNATURE_SIZE (2 * 256 / 8) /**< @brief Size of a signature for secp256r1 (NIST 256-bit) curve. @ingroup nrf_crypto_ecdsa_secp256r1 */
  78. #define NRF_CRYPTO_ECDSA_SECP384R1_SIGNATURE_SIZE (2 * 384 / 8) /**< @brief Size of a signature for secp384r1 (NIST 384-bit) curve. @ingroup nrf_crypto_ecdsa_secp384r1 */
  79. #define NRF_CRYPTO_ECDSA_SECP521R1_SIGNATURE_SIZE (2 * 528 / 8) /**< @brief Size of a signature for secp521r1 (NIST 521-bit) curve. @ingroup nrf_crypto_ecdsa_secp521r1 */
  80. #define NRF_CRYPTO_ECDSA_SECP160K1_SIGNATURE_SIZE (2 * 160 / 8) /**< @brief Size of a signature for secp160k1 (Koblitz 160-bit) curve. @ingroup nrf_crypto_ecdsa_secp160k1 */
  81. #define NRF_CRYPTO_ECDSA_SECP192K1_SIGNATURE_SIZE (2 * 192 / 8) /**< @brief Size of a signature for secp192k1 (Koblitz 192-bit) curve. @ingroup nrf_crypto_ecdsa_secp192k1 */
  82. #define NRF_CRYPTO_ECDSA_SECP224K1_SIGNATURE_SIZE (2 * 224 / 8) /**< @brief Size of a signature for secp224k1 (Koblitz 224-bit) curve. @ingroup nrf_crypto_ecdsa_secp224k1 */
  83. #define NRF_CRYPTO_ECDSA_SECP256K1_SIGNATURE_SIZE (2 * 256 / 8) /**< @brief Size of a signature for secp256k1 (Koblitz 256-bit) curve. @ingroup nrf_crypto_ecdsa_secp256k1 */
  84. #define NRF_CRYPTO_ECDSA_BP256R1_SIGNATURE_SIZE (2 * 256 / 8) /**< @brief Size of a signature for bp256r1 (Brainpool 256-bit) curve. @ingroup nrf_crypto_ecdsa_bp256r1 */
  85. #define NRF_CRYPTO_ECDSA_BP384R1_SIGNATURE_SIZE (2 * 384 / 8) /**< @brief Size of a signature for bp384r1 (Brainpool 384-bit) curve. @ingroup nrf_crypto_ecdsa_bp384r1 */
  86. #define NRF_CRYPTO_ECDSA_BP512R1_SIGNATURE_SIZE (2 * 512 / 8) /**< @brief Size of a signature for bp512r1 (Brainpool 512-bit) curve. @ingroup nrf_crypto_ecdsa_bp512r1 */
  87. #define NRF_CRYPTO_ECDSA_CURVE25519_SIGNATURE_SIZE (2 * 256 / 8) /**< @brief Size of a signature for Curve25519 curve. @ingroup nrf_crypto_ecdsa_curve25519 */
  88. #define NRF_CRYPTO_ECDSA_SIGNATURE_MAX_SIZE (2 * NRF_CRYPTO_ECC_RAW_PRIVATE_KEY_MAX_SIZE) /**< @brief Maximum size of a signature for all enabled curves. */
  89. typedef uint8_t nrf_crypto_ecdsa_secp160r1_signature_t [NRF_CRYPTO_ECDSA_SECP160R1_SIGNATURE_SIZE]; /**< @brief Type to hold signature output for secp160r1 (NIST 160-bit) curve. @ingroup nrf_crypto_ecdsa_secp160r1 */
  90. typedef uint8_t nrf_crypto_ecdsa_secp160r2_signature_t [NRF_CRYPTO_ECDSA_SECP160R2_SIGNATURE_SIZE]; /**< @brief Type to hold signature output for secp160r2 (NIST 160-bit) curve. @ingroup nrf_crypto_ecdsa_secp160r2 */
  91. typedef uint8_t nrf_crypto_ecdsa_secp192r1_signature_t [NRF_CRYPTO_ECDSA_SECP192R1_SIGNATURE_SIZE]; /**< @brief Type to hold signature output for secp192r1 (NIST 192-bit) curve. @ingroup nrf_crypto_ecdsa_secp192r1 */
  92. typedef uint8_t nrf_crypto_ecdsa_secp224r1_signature_t [NRF_CRYPTO_ECDSA_SECP224R1_SIGNATURE_SIZE]; /**< @brief Type to hold signature output for secp224r1 (NIST 224-bit) curve. @ingroup nrf_crypto_ecdsa_secp224r1 */
  93. typedef uint8_t nrf_crypto_ecdsa_secp256r1_signature_t [NRF_CRYPTO_ECDSA_SECP256R1_SIGNATURE_SIZE]; /**< @brief Type to hold signature output for secp256r1 (NIST 256-bit) curve. @ingroup nrf_crypto_ecdsa_secp256r1 */
  94. typedef uint8_t nrf_crypto_ecdsa_secp384r1_signature_t [NRF_CRYPTO_ECDSA_SECP384R1_SIGNATURE_SIZE]; /**< @brief Type to hold signature output for secp384r1 (NIST 384-bit) curve. @ingroup nrf_crypto_ecdsa_secp384r1 */
  95. typedef uint8_t nrf_crypto_ecdsa_secp521r1_signature_t [NRF_CRYPTO_ECDSA_SECP521R1_SIGNATURE_SIZE]; /**< @brief Type to hold signature output for secp521r1 (NIST 521-bit) curve. @ingroup nrf_crypto_ecdsa_secp521r1 */
  96. typedef uint8_t nrf_crypto_ecdsa_secp160k1_signature_t [NRF_CRYPTO_ECDSA_SECP160K1_SIGNATURE_SIZE]; /**< @brief Type to hold signature output for secp160k1 (Koblitz 160-bit) curve. @ingroup nrf_crypto_ecdsa_secp160k1 */
  97. typedef uint8_t nrf_crypto_ecdsa_secp192k1_signature_t [NRF_CRYPTO_ECDSA_SECP192K1_SIGNATURE_SIZE]; /**< @brief Type to hold signature output for secp192k1 (Koblitz 192-bit) curve. @ingroup nrf_crypto_ecdsa_secp192k1 */
  98. typedef uint8_t nrf_crypto_ecdsa_secp224k1_signature_t [NRF_CRYPTO_ECDSA_SECP224K1_SIGNATURE_SIZE]; /**< @brief Type to hold signature output for secp224k1 (Koblitz 224-bit) curve. @ingroup nrf_crypto_ecdsa_secp224k1 */
  99. typedef uint8_t nrf_crypto_ecdsa_secp256k1_signature_t [NRF_CRYPTO_ECDSA_SECP256K1_SIGNATURE_SIZE]; /**< @brief Type to hold signature output for secp256k1 (Koblitz 256-bit) curve. @ingroup nrf_crypto_ecdsa_secp256k1 */
  100. typedef uint8_t nrf_crypto_ecdsa_bp256r1_signature_t [NRF_CRYPTO_ECDSA_BP256R1_SIGNATURE_SIZE]; /**< @brief Type to hold signature output for bp256r1 (Brainpool 256-bit) curve. @ingroup nrf_crypto_ecdsa_bp256r1 */
  101. typedef uint8_t nrf_crypto_ecdsa_bp384r1_signature_t [NRF_CRYPTO_ECDSA_BP384R1_SIGNATURE_SIZE]; /**< @brief Type to hold signature output for bp384r1 (Brainpool 384-bit) curve. @ingroup nrf_crypto_ecdsa_bp384r1 */
  102. typedef uint8_t nrf_crypto_ecdsa_bp512r1_signature_t [NRF_CRYPTO_ECDSA_BP512R1_SIGNATURE_SIZE]; /**< @brief Type to hold signature output for bp512r1 (Brainpool 512-bit) curve. @ingroup nrf_crypto_ecdsa_bp512r1 */
  103. typedef uint8_t nrf_crypto_ecdsa_curve25519_signature_t [NRF_CRYPTO_ECDSA_CURVE25519_SIGNATURE_SIZE]; /**< @brief Type to hold signature output for Curve25519 curve. @ingroup nrf_crypto_ecdsa_curve25519 */
  104. typedef uint8_t nrf_crypto_ecdsa_signature_t [NRF_CRYPTO_ECDSA_SIGNATURE_MAX_SIZE]; /**< @brief Type big enough to hold signature output for any curve type. */
  105. typedef nrf_crypto_backend_secp160r1_sign_context_t nrf_crypto_ecdsa_secp160r1_sign_context_t; /**< @brief Context used to store temporary data during signing with curve secp160r1 (NIST 160-bit). @ingroup nrf_crypto_ecdsa_secp160r1 */
  106. typedef nrf_crypto_backend_secp160r2_sign_context_t nrf_crypto_ecdsa_secp160r2_sign_context_t; /**< @brief Context used to store temporary data during signing with curve secp160r2 (NIST 160-bit). @ingroup nrf_crypto_ecdsa_secp160r2 */
  107. typedef nrf_crypto_backend_secp192r1_sign_context_t nrf_crypto_ecdsa_secp192r1_sign_context_t; /**< @brief Context used to store temporary data during signing with curve secp192r1 (NIST 192-bit). @ingroup nrf_crypto_ecdsa_secp192r1 */
  108. typedef nrf_crypto_backend_secp224r1_sign_context_t nrf_crypto_ecdsa_secp224r1_sign_context_t; /**< @brief Context used to store temporary data during signing with curve secp224r1 (NIST 224-bit). @ingroup nrf_crypto_ecdsa_secp224r1 */
  109. typedef nrf_crypto_backend_secp256r1_sign_context_t nrf_crypto_ecdsa_secp256r1_sign_context_t; /**< @brief Context used to store temporary data during signing with curve secp256r1 (NIST 256-bit). @ingroup nrf_crypto_ecdsa_secp256r1 */
  110. typedef nrf_crypto_backend_secp384r1_sign_context_t nrf_crypto_ecdsa_secp384r1_sign_context_t; /**< @brief Context used to store temporary data during signing with curve secp384r1 (NIST 384-bit). @ingroup nrf_crypto_ecdsa_secp384r1 */
  111. typedef nrf_crypto_backend_secp521r1_sign_context_t nrf_crypto_ecdsa_secp521r1_sign_context_t; /**< @brief Context used to store temporary data during signing with curve secp521r1 (NIST 521-bit). @ingroup nrf_crypto_ecdsa_secp521r1 */
  112. typedef nrf_crypto_backend_secp160k1_sign_context_t nrf_crypto_ecdsa_secp160k1_sign_context_t; /**< @brief Context used to store temporary data during signing with curve secp160k1 (Koblitz 160-bit). @ingroup nrf_crypto_ecdsa_secp160k1 */
  113. typedef nrf_crypto_backend_secp192k1_sign_context_t nrf_crypto_ecdsa_secp192k1_sign_context_t; /**< @brief Context used to store temporary data during signing with curve secp192k1 (Koblitz 192-bit). @ingroup nrf_crypto_ecdsa_secp192k1 */
  114. typedef nrf_crypto_backend_secp224k1_sign_context_t nrf_crypto_ecdsa_secp224k1_sign_context_t; /**< @brief Context used to store temporary data during signing with curve secp224k1 (Koblitz 224-bit). @ingroup nrf_crypto_ecdsa_secp224k1 */
  115. typedef nrf_crypto_backend_secp256k1_sign_context_t nrf_crypto_ecdsa_secp256k1_sign_context_t; /**< @brief Context used to store temporary data during signing with curve secp256k1 (Koblitz 256-bit). @ingroup nrf_crypto_ecdsa_secp256k1 */
  116. typedef nrf_crypto_backend_bp256r1_sign_context_t nrf_crypto_ecdsa_bp256r1_sign_context_t; /**< @brief Context used to store temporary data during signing with curve bp256r1 (Brainpool 256-bit). @ingroup nrf_crypto_ecdsa_bp256r1 */
  117. typedef nrf_crypto_backend_bp384r1_sign_context_t nrf_crypto_ecdsa_bp384r1_sign_context_t; /**< @brief Context used to store temporary data during signing with curve bp384r1 (Brainpool 384-bit). @ingroup nrf_crypto_ecdsa_bp384r1 */
  118. typedef nrf_crypto_backend_bp512r1_sign_context_t nrf_crypto_ecdsa_bp512r1_sign_context_t; /**< @brief Context used to store temporary data during signing with curve bp512r1 (Brainpool 512-bit). @ingroup nrf_crypto_ecdsa_bp512r1 */
  119. typedef nrf_crypto_backend_curve25519_sign_context_t nrf_crypto_ecdsa_curve25519_sign_context_t; /**< @brief Context used to store temporary data during signing with curve Curve25519. @ingroup nrf_crypto_ecdsa_curve25519 */
  120. typedef nrf_crypto_backend_secp160r1_verify_context_t nrf_crypto_ecdsa_secp160r1_verify_context_t; /**< @brief Context used to store temporary data during verifying with curve secp160r1 (NIST 160-bit). @ingroup nrf_crypto_ecdsa_secp160r1 */
  121. typedef nrf_crypto_backend_secp160r2_verify_context_t nrf_crypto_ecdsa_secp160r2_verify_context_t; /**< @brief Context used to store temporary data during verifying with curve secp160r2 (NIST 160-bit). @ingroup nrf_crypto_ecdsa_secp160r2 */
  122. typedef nrf_crypto_backend_secp192r1_verify_context_t nrf_crypto_ecdsa_secp192r1_verify_context_t; /**< @brief Context used to store temporary data during verifying with curve secp192r1 (NIST 192-bit). @ingroup nrf_crypto_ecdsa_secp192r1 */
  123. typedef nrf_crypto_backend_secp224r1_verify_context_t nrf_crypto_ecdsa_secp224r1_verify_context_t; /**< @brief Context used to store temporary data during verifying with curve secp224r1 (NIST 224-bit). @ingroup nrf_crypto_ecdsa_secp224r1 */
  124. typedef nrf_crypto_backend_secp256r1_verify_context_t nrf_crypto_ecdsa_secp256r1_verify_context_t; /**< @brief Context used to store temporary data during verifying with curve secp256r1 (NIST 256-bit). @ingroup nrf_crypto_ecdsa_secp256r1 */
  125. typedef nrf_crypto_backend_secp384r1_verify_context_t nrf_crypto_ecdsa_secp384r1_verify_context_t; /**< @brief Context used to store temporary data during verifying with curve secp384r1 (NIST 384-bit). @ingroup nrf_crypto_ecdsa_secp384r1 */
  126. typedef nrf_crypto_backend_secp521r1_verify_context_t nrf_crypto_ecdsa_secp521r1_verify_context_t; /**< @brief Context used to store temporary data during verifying with curve secp521r1 (NIST 521-bit). @ingroup nrf_crypto_ecdsa_secp521r1 */
  127. typedef nrf_crypto_backend_secp160k1_verify_context_t nrf_crypto_ecdsa_secp160k1_verify_context_t; /**< @brief Context used to store temporary data during verifying with curve secp160k1 (Koblitz 160-bit). @ingroup nrf_crypto_ecdsa_secp160k1 */
  128. typedef nrf_crypto_backend_secp192k1_verify_context_t nrf_crypto_ecdsa_secp192k1_verify_context_t; /**< @brief Context used to store temporary data during verifying with curve secp192k1 (Koblitz 192-bit). @ingroup nrf_crypto_ecdsa_secp192k1 */
  129. typedef nrf_crypto_backend_secp224k1_verify_context_t nrf_crypto_ecdsa_secp224k1_verify_context_t; /**< @brief Context used to store temporary data during verifying with curve secp224k1 (Koblitz 224-bit). @ingroup nrf_crypto_ecdsa_secp224k1 */
  130. typedef nrf_crypto_backend_secp256k1_verify_context_t nrf_crypto_ecdsa_secp256k1_verify_context_t; /**< @brief Context used to store temporary data during verifying with curve secp256k1 (Koblitz 256-bit). @ingroup nrf_crypto_ecdsa_secp256k1 */
  131. typedef nrf_crypto_backend_bp256r1_verify_context_t nrf_crypto_ecdsa_bp256r1_verify_context_t; /**< @brief Context used to store temporary data during verifying with curve bp256r1 (Brainpool 256-bit). @ingroup nrf_crypto_ecdsa_bp256r1 */
  132. typedef nrf_crypto_backend_bp384r1_verify_context_t nrf_crypto_ecdsa_bp384r1_verify_context_t; /**< @brief Context used to store temporary data during verifying with curve bp384r1 (Brainpool 384-bit). @ingroup nrf_crypto_ecdsa_bp384r1 */
  133. typedef nrf_crypto_backend_bp512r1_verify_context_t nrf_crypto_ecdsa_bp512r1_verify_context_t; /**< @brief Context used to store temporary data during verifying with curve bp512r1 (Brainpool 512-bit). @ingroup nrf_crypto_ecdsa_bp512r1 */
  134. typedef nrf_crypto_backend_curve25519_verify_context_t nrf_crypto_ecdsa_curve25519_verify_context_t; /**< @brief Context used to store temporary data during verifying with curve Curve25519. @ingroup nrf_crypto_ecdsa_curve25519 */
  135. /** @brief Union holding a context for ECDSA hash sign.
  136. */
  137. typedef union
  138. {
  139. nrf_crypto_ecdsa_secp160r1_sign_context_t context_secp160r1; /**< @brief Occupies space for secp160r1 (NIST 160-bit). */
  140. nrf_crypto_ecdsa_secp160r2_sign_context_t context_secp160r2; /**< @brief Occupies space for secp160r2 (NIST 160-bit). */
  141. nrf_crypto_ecdsa_secp192r1_sign_context_t context_secp192r1; /**< @brief Occupies space for secp192r1 (NIST 192-bit). */
  142. nrf_crypto_ecdsa_secp224r1_sign_context_t context_secp224r1; /**< @brief Occupies space for secp224r1 (NIST 224-bit). */
  143. nrf_crypto_ecdsa_secp256r1_sign_context_t context_secp256r1; /**< @brief Occupies space for secp256r1 (NIST 256-bit). */
  144. nrf_crypto_ecdsa_secp384r1_sign_context_t context_secp384r1; /**< @brief Occupies space for secp384r1 (NIST 384-bit). */
  145. nrf_crypto_ecdsa_secp521r1_sign_context_t context_secp521r1; /**< @brief Occupies space for secp521r1 (NIST 521-bit). */
  146. nrf_crypto_ecdsa_secp160k1_sign_context_t context_secp160k1; /**< @brief Occupies space for secp160k1 (Koblitz 160-bit). */
  147. nrf_crypto_ecdsa_secp192k1_sign_context_t context_secp192k1; /**< @brief Occupies space for secp192k1 (Koblitz 192-bit). */
  148. nrf_crypto_ecdsa_secp224k1_sign_context_t context_secp224k1; /**< @brief Occupies space for secp224k1 (Koblitz 224-bit). */
  149. nrf_crypto_ecdsa_secp256k1_sign_context_t context_secp256k1; /**< @brief Occupies space for secp256k1 (Koblitz 256-bit). */
  150. nrf_crypto_ecdsa_bp256r1_sign_context_t context_bp256r1; /**< @brief Occupies space for bp256r1 (Brainpool 256-bit). */
  151. nrf_crypto_ecdsa_bp384r1_sign_context_t context_bp384r1; /**< @brief Occupies space for bp384r1 (Brainpool 384-bit). */
  152. nrf_crypto_ecdsa_bp512r1_sign_context_t context_bp512r1; /**< @brief Occupies space for bp512r1 (Brainpool 512-bit). */
  153. nrf_crypto_ecdsa_curve25519_sign_context_t context_curve25519; /**< @brief Occupies space for Curve25519. */
  154. } nrf_crypto_ecdsa_sign_context_t;
  155. /** @brief Union holding a context for ECDSA hash verify.
  156. */
  157. typedef union
  158. {
  159. nrf_crypto_ecdsa_secp160r1_verify_context_t context_secp160r1; /**< @brief Occupies spece for secp160r1 (NIST 160-bit). */
  160. nrf_crypto_ecdsa_secp160r2_verify_context_t context_secp160r2; /**< @brief Occupies spece for secp160r2 (NIST 160-bit). */
  161. nrf_crypto_ecdsa_secp192r1_verify_context_t context_secp192r1; /**< @brief Occupies spece for secp192r1 (NIST 192-bit). */
  162. nrf_crypto_ecdsa_secp224r1_verify_context_t context_secp224r1; /**< @brief Occupies spece for secp224r1 (NIST 224-bit). */
  163. nrf_crypto_ecdsa_secp256r1_verify_context_t context_secp256r1; /**< @brief Occupies spece for secp256r1 (NIST 256-bit). */
  164. nrf_crypto_ecdsa_secp384r1_verify_context_t context_secp384r1; /**< @brief Occupies spece for secp384r1 (NIST 384-bit). */
  165. nrf_crypto_ecdsa_secp521r1_verify_context_t context_secp521r1; /**< @brief Occupies spece for secp521r1 (NIST 521-bit). */
  166. nrf_crypto_ecdsa_secp160k1_verify_context_t context_secp160k1; /**< @brief Occupies spece for secp160k1 (Koblitz 160-bit). */
  167. nrf_crypto_ecdsa_secp192k1_verify_context_t context_secp192k1; /**< @brief Occupies spece for secp192k1 (Koblitz 192-bit). */
  168. nrf_crypto_ecdsa_secp224k1_verify_context_t context_secp224k1; /**< @brief Occupies spece for secp224k1 (Koblitz 224-bit). */
  169. nrf_crypto_ecdsa_secp256k1_verify_context_t context_secp256k1; /**< @brief Occupies spece for secp256k1 (Koblitz 256-bit). */
  170. nrf_crypto_ecdsa_bp256r1_verify_context_t context_bp256r1; /**< @brief Occupies spece for bp256r1 (Brainpool 256-bit). */
  171. nrf_crypto_ecdsa_bp384r1_verify_context_t context_bp384r1; /**< @brief Occupies spece for bp384r1 (Brainpool 384-bit). */
  172. nrf_crypto_ecdsa_bp512r1_verify_context_t context_bp512r1; /**< @brief Occupies spece for bp512r1 (Brainpool 512-bit). */
  173. nrf_crypto_ecdsa_curve25519_verify_context_t context_curve25519; /**< @brief Occupies spece for Curve25519. */
  174. } nrf_crypto_ecdsa_verify_context_t;
  175. /** @brief Sign a hash of a message.
  176. *
  177. * @param[in] p_context Pointer to temporary structure holding context information.
  178. * If it is NULL, necessary data will be allocated with
  179. * @ref NRF_CRYPTO_ALLOC and freed at the end of the function.
  180. * @param[in] p_private_key Pointer to structure holding a private key.
  181. * @param[in] p_hash Pointer to hash to sign.
  182. * @param[in] hash_size Number of bytes in p_hash.
  183. * @param[out] p_signature Pointer to buffer where digital signature will be put.
  184. * @param[in,out] p_signature_size Maximum number of bytes that @p p_signature buffer can hold on input
  185. * and the actual number of bytes used by the data on output.
  186. * Actual size for selected curve is defined by
  187. * the preprocessor definitions, e.g.
  188. * @ref NRF_CRYPTO_ECDSA_SECP256R1_SIGNATURE_SIZE.
  189. */
  190. ret_code_t nrf_crypto_ecdsa_sign(
  191. nrf_crypto_ecdsa_sign_context_t * p_context,
  192. nrf_crypto_ecc_private_key_t const * p_private_key,
  193. uint8_t const * p_hash,
  194. size_t hash_size,
  195. uint8_t * p_signature,
  196. size_t * p_signature_size);
  197. /** @brief Verify a signature using a hash of a message.
  198. *
  199. * @param[in] p_context Pointer to temporary structure holding context information.
  200. * If it is NULL, necessary data will be allocated with
  201. * @ref NRF_CRYPTO_ALLOC and freed at the end of the function.
  202. * @param[in] p_public_key Pointer to structure holding a public key.
  203. * @param[in] p_hash Pointer to hash to verify.
  204. * @param[in] hash_size Number of bytes in p_hash.
  205. * @param[in] p_signature Pointer to buffer containing digital signature.
  206. * @param[in,out] signature_size Number of bytes in p_signature.
  207. */
  208. ret_code_t nrf_crypto_ecdsa_verify(
  209. nrf_crypto_ecdsa_verify_context_t * p_context,
  210. nrf_crypto_ecc_public_key_t const * p_public_key,
  211. uint8_t const * p_hash,
  212. size_t hash_size,
  213. uint8_t const * p_signature,
  214. size_t signature_size);
  215. #ifdef __cplusplus
  216. }
  217. #endif
  218. /** @}
  219. * @}
  220. */
  221. #endif // NRF_CRYPTO_ECDSA_H__