Contiki-NG
Loading...
Searching...
No Matches
Cryptographic primitives

Topics

 Cryptographically-secure PRNG
 In contrast to a normal PRNG, a CSPRNG generates a stream of pseudo-random numbers that is indistinguishable from the uniform distribution to a computationally-bounded adversary who does not know the seed.
 

Files

file  aes-128.c
 Wrapped AES-128 implementation from Texas Instruments.
 
file  aes-128.h
 AES-128.
 
file  ccm-star.c
 AES_128-based CCM* implementation.
 
file  ccm-star.h
 CCM* header file.
 
file  ecc-curve.c
 NIST curves for various key sizes.
 
file  ecc-curve.h
 NIST curves for various key sizes.
 
file  ecc.h
 Header file of ECC.
 
file  sha-256.c
 Software implementation of SHA-256.
 
file  sha-256.h
 Platform-independent SHA-256 API.
 
file  ecc.c
 Adapter for uECC.
 
file  module-macros.h
 Applies settings that are mandatory for uECC.
 

Data Structures

struct  aes_128_driver
 Structure of AES drivers. More...
 
struct  ccm_star_driver
 Structure of CCM* drivers. More...
 
struct  ecc_curve_t
 Parameters of an ECC curve in little-endian word order. More...
 
struct  sha_256_driver
 Structure of SHA-256 drivers. More...
 

Functions

void ecc_init (void)
 Initializes ECC.
 
process_mutex_tecc_get_mutex (void)
 Provides a mutex to be locked before proceeding with ecc_enable().
 
int ecc_enable (const ecc_curve_t *curve)
 Sets up the ECC driver.
 
struct pt * ecc_get_protothread (void)
 Provides the protothread that runs long-running ECC operations.
 
char ecc_validate_public_key (const uint8_t *public_key, int *result)
 Validates a public key.
 
void ecc_compress_public_key (const uint8_t *uncompressed_public_key, uint8_t *compressed_public_key)
 Compresses a public key as per SECG SEC 1.
 
char ecc_decompress_public_key (const uint8_t *compressed_public_key, uint8_t *uncompressed_public_key, int *result)
 Decompresses a public key.
 
char ecc_sign (const uint8_t *message_hash, const uint8_t *private_key, uint8_t *signature, int *result)
 Generates an ECDSA signature for a message.
 
char ecc_verify (const uint8_t *signature, const uint8_t *message_hash, const uint8_t *public_key, int *result)
 Verifies an ECDSA signature of a message.
 
char ecc_generate_key_pair (uint8_t *public_key, uint8_t *private_key, int *result)
 Generates a public/private key pair.
 
char ecc_generate_shared_secret (const uint8_t *public_key, const uint8_t *private_key, uint8_t *shared_secret, int *result)
 Generates a shared secret as per ECDH.
 
void ecc_disable (void)
 Shuts down the ECC driver and unlocks the mutex.
 
void sha_256_hmac_init (const uint8_t *key, size_t key_len)
 Initiates a stepwise HMAC-SHA-256 computation.
 
void sha_256_hmac_update (const uint8_t *data, size_t data_len)
 Proceeds with the computation of an HMAC-SHA-256.
 
void sha_256_hkdf_expand (const uint8_t *prk, size_t prk_len, const uint8_t *info, size_t info_len, uint8_t *okm, uint_fast16_t okm_len)
 Expands a key as per RFC 5869.
 
void sha_256_hkdf (const uint8_t *salt, size_t salt_len, const uint8_t *ikm, size_t ikm_len, const uint8_t *info, size_t info_len, uint8_t *okm, uint_fast16_t okm_len)
 Performs both extraction and expansion as per RFC 5869.
 
void sha_256_hash (const uint8_t *data, size_t len, uint8_t digest[static 32])
 Generic implementation of sha_256_driver::hash.
 
void sha_256_hmac_finish (uint8_t hmac[static 32])
 Finishes the computation of an HMAC-SHA-256.
 
void sha_256_hmac (const uint8_t *key, size_t key_len, const uint8_t *data, size_t data_len, uint8_t hmac[static 32])
 Computes HMAC-SHA-256 as per RFC 2104.
 
void sha_256_hkdf_extract (const uint8_t *salt, size_t salt_len, const uint8_t *ikm, size_t ikm_len, uint8_t prk[static 32])
 Extracts a key as per RFC 5869.
 

Detailed Description

Function Documentation

◆ ecc_compress_public_key()

void ecc_compress_public_key ( const uint8_t * uncompressed_public_key,
uint8_t * compressed_public_key )

Compresses a public key as per SECG SEC 1.

Parameters
uncompressed_public_keyThe uncompressed 2|CURVE|-byte public key.
compressed_public_keyThe compressed (1+|CURVE|)-byte public key.

Definition at line 103 of file ecc.c.

◆ ecc_decompress_public_key()

char ecc_decompress_public_key ( const uint8_t * compressed_public_key,
uint8_t * uncompressed_public_key,
int * result )

Decompresses a public key.

Parameters
compressed_public_keyThe compressed (1+|CURVE|)-byte public key.
uncompressed_public_keyThe uncompressed 2|CURVE|-byte public key.
result0 on success and else a driver-specific error code.

Definition at line 111 of file ecc.c.

References PT_BEGIN, and PT_END.

◆ ecc_enable()

int ecc_enable ( const ecc_curve_t * curve)

Sets up the ECC driver.

Parameters
curveThe curve to use in subsequent calls.
Returns
0 on success and else a driver-specific error code. On error, the mutex is unlocked automatically and there is no need to call ecc_disable() either.

Definition at line 72 of file ecc.c.

References process_mutex_unlock().

◆ ecc_generate_key_pair()

char ecc_generate_key_pair ( uint8_t * public_key,
uint8_t * private_key,
int * result )

Generates a public/private key pair.

Parameters
public_keyThe 2|CURVE|-byte public key.
private_keyThe |CURVE|-byte private key.
result0 on success and else a driver-specific error code.

Definition at line 157 of file ecc.c.

References PT_BEGIN, and PT_END.

◆ ecc_generate_shared_secret()

char ecc_generate_shared_secret ( const uint8_t * public_key,
const uint8_t * private_key,
uint8_t * shared_secret,
int * result )

Generates a shared secret as per ECDH.

NOTE: Callers should derive symmetric keys from the shared secret via a key derivation function.

Parameters
public_keyThe peer's 2|CURVE|-byte public key.
private_keyOur |CURVE|-byte private key.
shared_secretThe resultant |CURVE|-byte shared secret.
result0 on success and else a driver-specific error code.

Definition at line 171 of file ecc.c.

References PT_BEGIN, and PT_END.

◆ ecc_get_mutex()

process_mutex_t * ecc_get_mutex ( void )

Provides a mutex to be locked before proceeding with ecc_enable().

Returns
The mutex.

Definition at line 66 of file ecc.c.

◆ ecc_get_protothread()

struct pt * ecc_get_protothread ( void )

Provides the protothread that runs long-running ECC operations.

Returns
The protothread that runs long-running ECC operations.

Definition at line 87 of file ecc.c.

◆ ecc_sign()

char ecc_sign ( const uint8_t * message_hash,
const uint8_t * private_key,
uint8_t * signature,
int * result )

Generates an ECDSA signature for a message.

Parameters
message_hashThe |CURVE|-byte hash over the message.
private_keyThe |CURVE|-byte private key.
signatureThe 2|CURVE|-byte signature.
result0 on success and else a driver-specific error code.

Definition at line 126 of file ecc.c.

References ecc_curve_t::bytes, PT_BEGIN, and PT_END.

◆ ecc_validate_public_key()

char ecc_validate_public_key ( const uint8_t * public_key,
int * result )

Validates a public key.

Parameters
public_keyThe 2|CURVE|-byte public key.
result0 on success and else a driver-specific error code.

Definition at line 93 of file ecc.c.

References PT_BEGIN, and PT_END.

◆ ecc_verify()

char ecc_verify ( const uint8_t * signature,
const uint8_t * message_hash,
const uint8_t * public_key,
int * result )

Verifies an ECDSA signature of a message.

Parameters
signatureThe 2|CURVE|-byte signature.
message_hashThe |CURVE|-byte hash over the message.
public_keyThe 2|CURVE|-byte public key.
result0 on success and else a driver-specific error code.

Definition at line 142 of file ecc.c.

References ecc_curve_t::bytes, PT_BEGIN, and PT_END.

◆ sha_256_hkdf()

void sha_256_hkdf ( const uint8_t * salt,
size_t salt_len,
const uint8_t * ikm,
size_t ikm_len,
const uint8_t * info,
size_t info_len,
uint8_t * okm,
uint_fast16_t okm_len )

Performs both extraction and expansion as per RFC 5869.

Parameters
saltoptional salt value
salt_lenlength of salt in bytes
ikminput keying material
ikm_lenlength of ikm in bytes
infooptional context and application specific information
info_lenlength of info in bytes
okmoutput keying material
okm_lenlength of okm in bytes (<= 255 * SHA_256_DIGEST_LENGTH)

Definition at line 443 of file sha-256.c.

References sha_256_hkdf_expand().

◆ sha_256_hkdf_expand()

void sha_256_hkdf_expand ( const uint8_t * prk,
size_t prk_len,
const uint8_t * info,
size_t info_len,
uint8_t * okm,
uint_fast16_t okm_len )

Expands a key as per RFC 5869.

Parameters
prka pseudorandom key of at least SHA_256_DIGEST_LENGTH bytes
prk_lenlength of prk in bytes
infooptional context and application specific information
info_lenlength of info in bytes
okmoutput keying material
okm_lenlength of okm in bytes (<= 255 * SHA_256_DIGEST_LENGTH)

Definition at line 415 of file sha-256.c.

References sha_256_hmac_init(), and sha_256_hmac_update().

Referenced by sha_256_hkdf().

◆ sha_256_hkdf_extract()

void sha_256_hkdf_extract ( const uint8_t * salt,
size_t salt_len,
const uint8_t * ikm,
size_t ikm_len,
uint8_t prk[static 32] )

Extracts a key as per RFC 5869.

Parameters
saltoptional salt value
salt_lenlength of salt in bytes
ikminput keying material
ikm_lenlength of ikm in bytes
prkpointer to where the extracted key shall be stored

◆ sha_256_hmac()

void sha_256_hmac ( const uint8_t * key,
size_t key_len,
const uint8_t * data,
size_t data_len,
uint8_t hmac[static 32] )

Computes HMAC-SHA-256 as per RFC 2104.

Parameters
keythe key to authenticate with
key_lenlength of key in bytes
datathe data to authenticate
data_lenlength of data in bytes
hmacpointer to where the resulting HMAC shall be stored

◆ sha_256_hmac_finish()

void sha_256_hmac_finish ( uint8_t hmac[static 32])

Finishes the computation of an HMAC-SHA-256.

Parameters
hmacpointer to where the resulting HMAC shall be stored

◆ sha_256_hmac_init()

void sha_256_hmac_init ( const uint8_t * key,
size_t key_len )

Initiates a stepwise HMAC-SHA-256 computation.

Parameters
keythe key to authenticate with
key_lenlength of key in bytes

Definition at line 355 of file sha-256.c.

Referenced by sha_256_hkdf_expand().

◆ sha_256_hmac_update()

void sha_256_hmac_update ( const uint8_t * data,
size_t data_len )

Proceeds with the computation of an HMAC-SHA-256.

Parameters
datafurther data to authenticate
data_lenlength of data in bytes

Definition at line 380 of file sha-256.c.

Referenced by sha_256_hkdf_expand().