mbedtls_backend_ecdh.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 MBEDTLS_BACKEND_ECDH_H__
  41. #define MBEDTLS_BACKEND_ECDH_H__
  42. #include "sdk_config.h"
  43. #include "nordic_common.h"
  44. #if NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS)
  45. #include "nrf_crypto_ecc.h"
  46. #include "nrf_crypto_ecdh_shared.h"
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. /** @internal See @ref nrf_crypto_backend_ecdh_compute_fn_t.
  51. */
  52. ret_code_t nrf_crypto_backend_mbedtls_ecdh_compute(
  53. void * p_context,
  54. void const * p_private_key,
  55. void const * p_public_key,
  56. uint8_t * p_shared_secret);
  57. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP192R1)
  58. // Aliases for one common MBEDTLS implementation
  59. #define nrf_crypto_backend_secp192r1_ecdh_compute nrf_crypto_backend_mbedtls_ecdh_compute
  60. typedef uint32_t nrf_crypto_backend_secp192r1_ecdh_context_t;
  61. #define NRF_CRYPTO_BACKEND_SECP192R1_ECDH_CONTEXT_SIZE 0
  62. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP192R1)
  63. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP224R1)
  64. // Aliases for one common MBEDTLS implementation
  65. #define nrf_crypto_backend_secp224r1_ecdh_compute nrf_crypto_backend_mbedtls_ecdh_compute
  66. typedef uint32_t nrf_crypto_backend_secp224r1_ecdh_context_t;
  67. #define NRF_CRYPTO_BACKEND_SECP224R1_ECDH_CONTEXT_SIZE 0
  68. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP224R1)
  69. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP256R1)
  70. // Aliases for one common MBEDTLS implementation
  71. #define nrf_crypto_backend_secp256r1_ecdh_compute nrf_crypto_backend_mbedtls_ecdh_compute
  72. typedef uint32_t nrf_crypto_backend_secp256r1_ecdh_context_t;
  73. #define NRF_CRYPTO_BACKEND_SECP256R1_ECDH_CONTEXT_SIZE 0
  74. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP256R1)
  75. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP384R1)
  76. // Aliases for one common MBEDTLS implementation
  77. #define nrf_crypto_backend_secp384r1_ecdh_compute nrf_crypto_backend_mbedtls_ecdh_compute
  78. typedef uint32_t nrf_crypto_backend_secp384r1_ecdh_context_t;
  79. #define NRF_CRYPTO_BACKEND_SECP384R1_ECDH_CONTEXT_SIZE 0
  80. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP384R1)
  81. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP521R1)
  82. // Aliases for one common MBEDTLS implementation
  83. #define nrf_crypto_backend_secp521r1_ecdh_compute nrf_crypto_backend_mbedtls_ecdh_compute
  84. typedef uint32_t nrf_crypto_backend_secp521r1_ecdh_context_t;
  85. #define NRF_CRYPTO_BACKEND_SECP521R1_ECDH_CONTEXT_SIZE 0
  86. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP521R1)
  87. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP192K1)
  88. // Aliases for one common MBEDTLS implementation
  89. #define nrf_crypto_backend_secp192k1_ecdh_compute nrf_crypto_backend_mbedtls_ecdh_compute
  90. typedef uint32_t nrf_crypto_backend_secp192k1_ecdh_context_t;
  91. #define NRF_CRYPTO_BACKEND_SECP192K1_ECDH_CONTEXT_SIZE 0
  92. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP192K1)
  93. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP224K1)
  94. // Aliases for one common MBEDTLS implementation
  95. #define nrf_crypto_backend_secp224k1_ecdh_compute nrf_crypto_backend_mbedtls_ecdh_compute
  96. typedef uint32_t nrf_crypto_backend_secp224k1_ecdh_context_t;
  97. #define NRF_CRYPTO_BACKEND_SECP224K1_ECDH_CONTEXT_SIZE 0
  98. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP224K1)
  99. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP256K1)
  100. // Aliases for one common MBEDTLS implementation
  101. #define nrf_crypto_backend_secp256k1_ecdh_compute nrf_crypto_backend_mbedtls_ecdh_compute
  102. typedef uint32_t nrf_crypto_backend_secp256k1_ecdh_context_t;
  103. #define NRF_CRYPTO_BACKEND_SECP256K1_ECDH_CONTEXT_SIZE 0
  104. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_SECP256K1)
  105. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_BP256R1)
  106. // Aliases for one common MBEDTLS implementation
  107. #define nrf_crypto_backend_bp256r1_ecdh_compute nrf_crypto_backend_mbedtls_ecdh_compute
  108. typedef uint32_t nrf_crypto_backend_bp256r1_ecdh_context_t;
  109. #define NRF_CRYPTO_BACKEND_BP256R1_ECDH_CONTEXT_SIZE 0
  110. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_BP256R1)
  111. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_BP384R1)
  112. // Aliases for one common MBEDTLS implementation
  113. #define nrf_crypto_backend_bp384r1_ecdh_compute nrf_crypto_backend_mbedtls_ecdh_compute
  114. typedef uint32_t nrf_crypto_backend_bp384r1_ecdh_context_t;
  115. #define NRF_CRYPTO_BACKEND_BP384R1_ECDH_CONTEXT_SIZE 0
  116. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_BP384R1)
  117. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_BP512R1)
  118. // Aliases for one common MBEDTLS implementation
  119. #define nrf_crypto_backend_bp512r1_ecdh_compute nrf_crypto_backend_mbedtls_ecdh_compute
  120. typedef uint32_t nrf_crypto_backend_bp512r1_ecdh_context_t;
  121. #define NRF_CRYPTO_BACKEND_BP512R1_ECDH_CONTEXT_SIZE 0
  122. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_BP512R1)
  123. #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_CURVE25519)
  124. // Aliases for one common MBEDTLS implementation
  125. #define nrf_crypto_backend_curve25519_ecdh_compute nrf_crypto_backend_mbedtls_ecdh_compute
  126. typedef uint32_t nrf_crypto_backend_curve25519_ecdh_context_t;
  127. #define NRF_CRYPTO_BACKEND_CURVE25519_ECDH_CONTEXT_SIZE 0
  128. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS_ECC_CURVE25519)
  129. #ifdef __cplusplus
  130. }
  131. #endif
  132. #endif // NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS)
  133. #endif // MBEDTLS_BACKEND_ECDH_H__