123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- #ifndef NRF_CRYPTO_ECDH_H__
- #define NRF_CRYPTO_ECDH_H__
- #include <stdint.h>
- #include <stddef.h>
- #include "nrf_crypto_error.h"
- #include "nrf_crypto_ecc.h"
- #include "nrf_crypto_ecdh_shared.h"
- #include "nrf_crypto_ecdh_backend.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define NRF_CRYPTO_ECDH_SECP160R1_SHARED_SECRET_SIZE (160 / 8)
- #define NRF_CRYPTO_ECDH_SECP160R2_SHARED_SECRET_SIZE (160 / 8)
- #define NRF_CRYPTO_ECDH_SECP192R1_SHARED_SECRET_SIZE (192 / 8)
- #define NRF_CRYPTO_ECDH_SECP224R1_SHARED_SECRET_SIZE (224 / 8)
- #define NRF_CRYPTO_ECDH_SECP256R1_SHARED_SECRET_SIZE (256 / 8)
- #define NRF_CRYPTO_ECDH_SECP384R1_SHARED_SECRET_SIZE (384 / 8)
- #define NRF_CRYPTO_ECDH_SECP521R1_SHARED_SECRET_SIZE (528 / 8)
- #define NRF_CRYPTO_ECDH_SECP160K1_SHARED_SECRET_SIZE (160 / 8)
- #define NRF_CRYPTO_ECDH_SECP192K1_SHARED_SECRET_SIZE (192 / 8)
- #define NRF_CRYPTO_ECDH_SECP224K1_SHARED_SECRET_SIZE (224 / 8)
- #define NRF_CRYPTO_ECDH_SECP256K1_SHARED_SECRET_SIZE (256 / 8)
- #define NRF_CRYPTO_ECDH_BP256R1_SHARED_SECRET_SIZE (256 / 8)
- #define NRF_CRYPTO_ECDH_BP384R1_SHARED_SECRET_SIZE (384 / 8)
- #define NRF_CRYPTO_ECDH_BP512R1_SHARED_SECRET_SIZE (512 / 8)
- #define NRF_CRYPTO_ECDH_CURVE25519_SHARED_SECRET_SIZE (256 / 8)
- #define NRF_CRYPTO_ECDH_SHARED_SECRET_MAX_SIZE NRF_CRYPTO_ECC_RAW_PRIVATE_KEY_MAX_SIZE
- typedef nrf_crypto_backend_secp160r1_ecdh_context_t nrf_crypto_ecdh_secp160r1_context_t;
- typedef nrf_crypto_backend_secp160r2_ecdh_context_t nrf_crypto_ecdh_secp160r2_context_t;
- typedef nrf_crypto_backend_secp192r1_ecdh_context_t nrf_crypto_ecdh_secp192r1_context_t;
- typedef nrf_crypto_backend_secp224r1_ecdh_context_t nrf_crypto_ecdh_secp224r1_context_t;
- typedef nrf_crypto_backend_secp256r1_ecdh_context_t nrf_crypto_ecdh_secp256r1_context_t;
- typedef nrf_crypto_backend_secp384r1_ecdh_context_t nrf_crypto_ecdh_secp384r1_context_t;
- typedef nrf_crypto_backend_secp521r1_ecdh_context_t nrf_crypto_ecdh_secp521r1_context_t;
- typedef nrf_crypto_backend_secp160k1_ecdh_context_t nrf_crypto_ecdh_secp160k1_context_t;
- typedef nrf_crypto_backend_secp192k1_ecdh_context_t nrf_crypto_ecdh_secp192k1_context_t;
- typedef nrf_crypto_backend_secp224k1_ecdh_context_t nrf_crypto_ecdh_secp224k1_context_t;
- typedef nrf_crypto_backend_secp256k1_ecdh_context_t nrf_crypto_ecdh_secp256k1_context_t;
- typedef nrf_crypto_backend_bp256r1_ecdh_context_t nrf_crypto_ecdh_bp256r1_context_t;
- typedef nrf_crypto_backend_bp384r1_ecdh_context_t nrf_crypto_ecdh_bp384r1_context_t;
- typedef nrf_crypto_backend_bp512r1_ecdh_context_t nrf_crypto_ecdh_bp512r1_context_t;
- typedef nrf_crypto_backend_curve25519_ecdh_context_t nrf_crypto_ecdh_curve25519_context_t;
- typedef uint8_t nrf_crypto_ecdh_secp160r1_shared_secret_t
- [NRF_CRYPTO_ECDH_SECP160R1_SHARED_SECRET_SIZE];
- typedef uint8_t nrf_crypto_ecdh_secp160r2_shared_secret_t
- [NRF_CRYPTO_ECDH_SECP160R2_SHARED_SECRET_SIZE];
- typedef uint8_t nrf_crypto_ecdh_secp192r1_shared_secret_t
- [NRF_CRYPTO_ECDH_SECP192R1_SHARED_SECRET_SIZE];
- typedef uint8_t nrf_crypto_ecdh_secp224r1_shared_secret_t
- [NRF_CRYPTO_ECDH_SECP224R1_SHARED_SECRET_SIZE];
- typedef uint8_t nrf_crypto_ecdh_secp256r1_shared_secret_t
- [NRF_CRYPTO_ECDH_SECP256R1_SHARED_SECRET_SIZE];
- typedef uint8_t nrf_crypto_ecdh_secp384r1_shared_secret_t
- [NRF_CRYPTO_ECDH_SECP384R1_SHARED_SECRET_SIZE];
- typedef uint8_t nrf_crypto_ecdh_secp521r1_shared_secret_t
- [NRF_CRYPTO_ECDH_SECP521R1_SHARED_SECRET_SIZE];
- typedef uint8_t nrf_crypto_ecdh_secp160k1_shared_secret_t
- [NRF_CRYPTO_ECDH_SECP160K1_SHARED_SECRET_SIZE];
- typedef uint8_t nrf_crypto_ecdh_secp192k1_shared_secret_t
- [NRF_CRYPTO_ECDH_SECP192K1_SHARED_SECRET_SIZE];
- typedef uint8_t nrf_crypto_ecdh_secp224k1_shared_secret_t
- [NRF_CRYPTO_ECDH_SECP224K1_SHARED_SECRET_SIZE];
- typedef uint8_t nrf_crypto_ecdh_secp256k1_shared_secret_t
- [NRF_CRYPTO_ECDH_SECP256K1_SHARED_SECRET_SIZE];
- typedef uint8_t nrf_crypto_ecdh_bp256r1_shared_secret_t
- [NRF_CRYPTO_ECDH_BP256R1_SHARED_SECRET_SIZE];
- typedef uint8_t nrf_crypto_ecdh_bp384r1_shared_secret_t
- [NRF_CRYPTO_ECDH_BP384R1_SHARED_SECRET_SIZE];
- typedef uint8_t nrf_crypto_ecdh_bp512r1_shared_secret_t
- [NRF_CRYPTO_ECDH_BP512R1_SHARED_SECRET_SIZE];
- typedef uint8_t nrf_crypto_ecdh_curve25519_shared_secret_t
- [NRF_CRYPTO_ECDH_CURVE25519_SHARED_SECRET_SIZE];
- typedef uint8_t nrf_crypto_ecdh_shared_secret_t
- [NRF_CRYPTO_ECDH_SHARED_SECRET_MAX_SIZE];
- typedef union
- {
- nrf_crypto_ecdh_secp160r1_context_t context_secp160r1;
- nrf_crypto_ecdh_secp160r2_context_t context_secp160r2;
- nrf_crypto_ecdh_secp192r1_context_t context_secp192r1;
- nrf_crypto_ecdh_secp224r1_context_t context_secp224r1;
- nrf_crypto_ecdh_secp256r1_context_t context_secp256r1;
- nrf_crypto_ecdh_secp384r1_context_t context_secp384r1;
- nrf_crypto_ecdh_secp521r1_context_t context_secp521r1;
- nrf_crypto_ecdh_secp160k1_context_t context_secp160k1;
- nrf_crypto_ecdh_secp192k1_context_t context_secp192k1;
- nrf_crypto_ecdh_secp224k1_context_t context_secp224k1;
- nrf_crypto_ecdh_secp256k1_context_t context_secp256k1;
- nrf_crypto_ecdh_bp256r1_context_t context_bp256r1;
- nrf_crypto_ecdh_bp384r1_context_t context_bp384r1;
- nrf_crypto_ecdh_bp512r1_context_t context_bp512r1;
- nrf_crypto_ecdh_curve25519_context_t context_curve25519;
- } nrf_crypto_ecdh_context_t;
- ret_code_t nrf_crypto_ecdh_compute(
- nrf_crypto_ecdh_context_t * p_context,
- nrf_crypto_ecc_private_key_t const * p_private_key,
- nrf_crypto_ecc_public_key_t const * p_public_key,
- uint8_t * p_shared_secret,
- size_t * p_shared_secret_size);
- #ifdef __cplusplus
- }
- #endif
- #endif
|