ecc.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2016 Nordic Semiconductor. All Rights Reserved.
  3. *
  4. * The information contained herein is confidential property of Nordic Semiconductor. The use,
  5. * copying, transfer or disclosure of such information is prohibited except by express written
  6. * agreement with Nordic Semiconductor.
  7. *
  8. */
  9. /**
  10. * @brief Elliptic Curve Cryptography Interface
  11. *
  12. */
  13. #include <stdint.h>
  14. #include "nordic_common.h"
  15. #include "nrf_error.h"
  16. #define ECC_P256_SK_LEN 32
  17. #define ECC_P256_PK_LEN 64
  18. /**@brief Initialize the ECC module. */
  19. void ecc_init(void);
  20. /**@brief Create a public/private key pair.
  21. *
  22. * @param[out] p_le_sk Private key. Pointer must be aligned to a 4-byte boundary.
  23. * @param[out] p_le_pk Public key. Pointer must be aligned to a 4-byte boundary.
  24. *
  25. * @retval NRF_SUCCESS Key pair successfuly created.
  26. * @retval NRF_ERROR_NULL NULL pointer provided.
  27. * @retval NRF_ERROR_INVALID_ADDR Unaligned pointer provided.
  28. * @retval NRF_ERROR_INTERNAL Internal error during key generation.
  29. */
  30. ret_code_t ecc_p256_keypair_gen(uint8_t *p_le_sk, uint8_t* p_le_pk);
  31. /**@brief Create a public key from a provided private key.
  32. *
  33. * @param[in] p_le_sk Private key. Pointer must be aligned to a 4-byte boundary.
  34. * @param[out] p_le_pk Public key. Pointer must be aligned to a 4-byte boundary.
  35. *
  36. * @retval NRF_SUCCESS Public key successfuly created.
  37. * @retval NRF_ERROR_NULL NULL pointer provided.
  38. * @retval NRF_ERROR_INVALID_ADDR Unaligned pointer provided.
  39. * @retval NRF_ERROR_INTERNAL Internal error during key generation.
  40. */
  41. ret_code_t ecc_p256_public_key_compute(uint8_t const *p_le_sk, uint8_t* p_le_pk);
  42. /**@brief Create a shared secret from a provided public/private key pair.
  43. *
  44. * @param[in] p_le_sk Private key. Pointer must be aligned to a 4-byte boundary.
  45. * @param[in] p_le_pk Public key. Pointer must be aligned to a 4-byte boundary.
  46. * @param[out] p_le_ss Shared secret. Pointer must be aligned to a 4-byte boundary.
  47. *
  48. * @retval NRF_SUCCESS Shared secret successfuly created.
  49. * @retval NRF_ERROR_NULL NULL pointer provided.
  50. * @retval NRF_ERROR_INVALID_ADDR Unaligned pointer provided.
  51. * @retval NRF_ERROR_INTERNAL Internal error during key generation.
  52. */
  53. ret_code_t ecc_p256_shared_secret_compute(uint8_t const *p_le_sk, uint8_t const * p_le_pk, uint8_t *p_le_ss);