Contiki-NG
Loading...
Searching...
No Matches
ecdh.c File Reference

Synchronous wrapper around lib/ecc.h for the EDHOC implementation. More...

#include "contiki.h"
#include "dev/watchdog.h"
#include "ecdh.h"
#include "edhoc-config.h"
#include "lib/ecc.h"
#include "lib/ecc-curve.h"
#include "sys/process-mutex.h"
#include "sys/pt.h"
#include <string.h>
#include "sys/log.h"

Go to the source code of this file.

Functions

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.
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_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 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.

Detailed Description

Synchronous wrapper around lib/ecc.h for the EDHOC implementation.

The Contiki-NG ECC driver exposes long-running operations as protothreads so that other protothreads may make progress while the cryptographic operation is in flight. The current EDHOC protocol implementation is synchronous, so we busy-wait the underlying protothread to completion. This still deduplicates the per-backend wrappers EDHOC used to ship.

Author
Lidia Pocero pocer.nosp@m.o@is.nosp@m.i.gr, Peter A Jonsson, Rikard Höglund, Marco Tiloca, Nicolas Tsiftes

Definition in file ecdh.c.

Function Documentation

◆ ecc_sign_hash()

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.

Parameters
curve_idThe EDHOC curve identifier (e.g. EDHOC_CURVE_P256).
hashThe message hash (ECC_KEY_LEN bytes).
private_keyThe signer's private key (ECC_KEY_LEN bytes).
signatureOutput buffer for the signature (2*ECC_KEY_LEN bytes).
Returns
true on success, false on error.

Definition at line 174 of file ecdh.c.

References ecc_disable(), ecc_get_protothread(), ecc_sign(), PT_INIT, PT_SCHEDULE, and watchdog_periodic().

Referenced by cose_sign1_sign().

◆ ecc_verify_hash()

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.

Parameters
curve_idThe EDHOC curve identifier (e.g. EDHOC_CURVE_P256).
hashThe message hash (ECC_KEY_LEN bytes).
public_keyThe signer's public key (2*ECC_KEY_LEN bytes).
signatureThe signature to verify (2*ECC_KEY_LEN bytes).
Returns
true if the signature is valid, false otherwise.

Definition at line 203 of file ecdh.c.

References ecc_disable(), ecc_get_protothread(), ecc_verify(), PT_INIT, PT_SCHEDULE, and watchdog_periodic().

Referenced by cose_sign1_verify().

◆ ecdh_generate_ikm()

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.

Parameters
curve_idThe EDHOC curve identifier (e.g. EDHOC_CURVE_P256).
peer_xThe peer's public-key x-coordinate (ECC_KEY_LEN bytes). The y-coordinate is recovered from peer_x using point decompression (odd-y branch), so EDHOC's x-only on-wire encoding can be passed in directly.
private_keyOur private key (ECC_KEY_LEN bytes).
ikmOutput buffer for the shared secret (ECC_KEY_LEN bytes).
Returns
true on success, false on error.

Definition at line 123 of file ecdh.c.

References ecc_decompress_public_key(), ecc_disable(), ecc_generate_shared_secret(), ecc_get_protothread(), PT_INIT, PT_SCHEDULE, and watchdog_periodic().

Referenced by edhoc_generate_prk_2e().

◆ ecdh_generate_keypair()

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.

Parameters
curve_idThe EDHOC curve identifier (e.g. EDHOC_CURVE_P256).
pub_xOutput buffer for the x-coordinate (ECC_KEY_LEN bytes).
pub_yOutput buffer for the y-coordinate (ECC_KEY_LEN bytes).
privOutput buffer for the private key (ECC_KEY_LEN bytes).
Returns
true on success, false on error.

Definition at line 91 of file ecdh.c.

References ecc_disable(), ecc_generate_key_pair(), ecc_get_protothread(), PT_INIT, PT_SCHEDULE, and watchdog_periodic().