49#include "dev/watchdog.h"
59#define LOG_MODULE "ECDH"
60#define LOG_LEVEL LOG_LEVEL_EDHOC
64get_curve(uint8_t curve_id)
67 case EDHOC_CURVE_P256:
68 return &ecc_curve_p_256;
70 LOG_ERR(
"Unsupported ECDH curve id %u\n", curve_id);
82 if(ecc_enable(curve) != 0) {
84 LOG_ERR(
"ecc_enable() failed\n");
92 uint8_t *pub_x, uint8_t *pub_y, uint8_t *priv)
98 if(!acquire_ecc(curve)) {
102 uint8_t public_key[2 * ECC_KEY_LEN];
113 LOG_ERR(
"ecc_generate_key_pair() failed (%d)\n", result);
117 memcpy(pub_x, public_key, ECC_KEY_LEN);
118 memcpy(pub_y, public_key + ECC_KEY_LEN, ECC_KEY_LEN);
124 const uint8_t *peer_x,
125 const uint8_t *private_key, uint8_t *ikm)
131 if(!acquire_ecc(curve)) {
141 uint8_t compressed[1 + ECC_KEY_LEN];
142 uint8_t public_key[2 * ECC_KEY_LEN];
143 compressed[0] = 0x03;
144 memcpy(compressed + 1, peer_x, ECC_KEY_LEN);
153 LOG_ERR(
"ecc_decompress_public_key() failed (%d)\n", result);
167 LOG_ERR(
"ecc_generate_shared_secret() failed (%d)\n", result);
176 const uint8_t *private_key,
183 if(!acquire_ecc(curve)) {
196 LOG_ERR(
"ecc_sign() failed (%d)\n", result);
205 const uint8_t *public_key,
206 const uint8_t *signature)
212 if(!acquire_ecc(curve)) {
225 LOG_ERR(
"ecc_verify() failed (%d)\n", result);
NIST curves for various key sizes.
bool ecc_sign_hash(uint8_t curve_id, const uint8_t *hash, const uint8_t *private_key, uint8_t *signature)
Generates an ECDSA signature for a message hash.
bool ecdh_generate_ikm(uint8_t curve_id, const uint8_t *peer_x, const uint8_t *private_key, uint8_t *ikm)
Computes an ECDH shared secret.
bool ecc_verify_hash(uint8_t curve_id, const uint8_t *hash, const uint8_t *public_key, const uint8_t *signature)
Verifies an ECDSA signature of a message hash.
bool ecdh_generate_keypair(uint8_t curve_id, uint8_t *pub_x, uint8_t *pub_y, uint8_t *priv)
Generates a fresh ECDH key pair.
ECDH interface for the EDHOC implementation.
EDHOC configuration file.
char ecc_verify(const uint8_t *signature, const uint8_t *message_hash, const uint8_t *public_key, int *const result)
char ecc_decompress_public_key(const uint8_t *compressed_public_key, uint8_t *uncompressed_public_key, int *const result)
char ecc_generate_key_pair(uint8_t *public_key, uint8_t *private_key, int *const result)
char ecc_sign(const uint8_t *message_hash, const uint8_t *private_key, uint8_t *signature, int *const result)
char ecc_generate_shared_secret(const uint8_t *public_key, const uint8_t *private_key, uint8_t *shared_secret, int *const result)
void watchdog_periodic(void)
Writes the WDT clear sequence.
void ecc_disable(void)
Shuts down the ECC driver and unlocks the mutex.
process_mutex_t * ecc_get_mutex(void)
Provides a mutex to be locked before proceeding with ecc_enable().
struct pt * ecc_get_protothread(void)
Provides the protothread that runs long-running ECC operations.
bool process_mutex_try_lock(process_mutex_t *mutex)
Tries to acquire a process mutex.
#define PT_INIT(pt)
Initialize a protothread.
#define PT_SCHEDULE(f)
Schedule a protothread.
Header file for the logging system.
Header file for Process mutexes.
Protothreads implementation.
Parameters of an ECC curve in little-endian word order.
Structure of a process mutex.