ocrypto_ecjpake_p256.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**
  2. * Copyright (c) 2019 - 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. /**@file
  41. * @defgroup nrf_oberon_ecjpake EC-JPAKE
  42. * @ingroup nrf_oberon
  43. * @{
  44. * @brief Type declaration and APIs for EC-JPAKE.
  45. *
  46. */
  47. #ifndef OCRYPTO_ECJPAKE_P256_H
  48. #define OCRYPTO_ECJPAKE_P256_H
  49. #include <stddef.h>
  50. #include <stdint.h>
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54. /**
  55. * EC-JPAKE-P256 public key and zero knowledge proof generation.
  56. *
  57. * @param[out] X Public key.
  58. * @param[out] V ZKP ephemeral public key.
  59. * @param[out] r ZKP signature.
  60. * @param G Generator. May be NULL to use the default generator.
  61. * @param x Secret key. 0 < x < group order.
  62. * @param v ZKP ephemeral secret key. 0 < v < group order.
  63. * @param id Identity of originator.
  64. * @param id_len Identity length.
  65. *
  66. * @retval 0 If inputs are valid.
  67. * @retval -1 Otherwise.
  68. */
  69. int ocrypto_ecjpake_get_key(
  70. uint8_t X[64],
  71. uint8_t V[64],
  72. uint8_t r[32],
  73. const uint8_t G[64],
  74. const uint8_t x[32],
  75. const uint8_t v[32],
  76. const char *id, size_t id_len);
  77. /**
  78. * EC-JPAKE-P256 zero knowledge proof verification.
  79. *
  80. * @param G Generator. May be NULL to use the default generator.
  81. * @param X Public key.
  82. * @param V ZKP ephemeral public key.
  83. * @param r ZKP signature.
  84. * @param id Identity of originator.
  85. * @param id_len Identity length.
  86. *
  87. * @retval 0 If proof is valid.
  88. * @retval -1 Otherwise.
  89. */
  90. int ocrypto_ecjpake_verify_key(
  91. const uint8_t G[64],
  92. const uint8_t X[64],
  93. const uint8_t V[64],
  94. const uint8_t r[32],
  95. const char *id, size_t id_len);
  96. /**
  97. * EC-JPAKE-P256 generator derivation.
  98. *
  99. * @param[out] G Generator.
  100. * @param X1 Public key 1.
  101. * @param X2 Public key 2.
  102. * @param X3 Public key 3.
  103. *
  104. * @retval 0 If the generator is valid.
  105. * @retval -1 Otherwise.
  106. */
  107. int ocrypto_ecjpake_get_generator(
  108. uint8_t G[64],
  109. const uint8_t X1[64],
  110. const uint8_t X2[64],
  111. const uint8_t X3[64]);
  112. /**
  113. * EC-JPAKE-P256 read shared secret.
  114. *
  115. * @param[out] rs Reduced shared secret.
  116. * @param secret Shared secret.
  117. * @param secret_len Secret length.
  118. */
  119. void ocrypto_ecjpake_read_shared_secret(
  120. uint8_t rs[32],
  121. const uint8_t *secret, size_t secret_len);
  122. /**
  123. * EC-JPAKE-P256 shared secret handling.
  124. *
  125. * @param[out] xs Client/server secret key.
  126. * @param x2 Secret key 2.
  127. * @param rs Reduced shared secret.
  128. *
  129. * @retval 0 If the derived secret key is valid.
  130. * @retval -1 Otherwise.
  131. */
  132. int ocrypto_ecjpake_process_shared_secret(
  133. uint8_t xs[32],
  134. const uint8_t x2[32],
  135. const uint8_t rs[32]);
  136. /**
  137. * EC-JPAKE-P256 secret key generation.
  138. *
  139. * @param[out] secret Resulting premaster secret.
  140. * @param Xr Remote client/server public key.
  141. * @param X2 Remote public key 2.
  142. * @param xs Client/server secret key.
  143. * @param x2 Secret key 2.
  144. *
  145. * @retval 0 If the key is valid.
  146. * @retval -1 Otherwise.
  147. */
  148. int ocrypto_ecjpake_get_secret_key(
  149. uint8_t secret[32],
  150. const uint8_t Xr[64],
  151. const uint8_t X2[64],
  152. const uint8_t xs[32],
  153. const uint8_t x2[32]);
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif /* #ifndef OCRYPTO_ECJPAKE_P256_H */
  158. /** @} */