Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
gec.h File Reference

Galois embedded crypto implementation. More...

#include "std.h"
#include "mcu_periph/rng.h"
#include "generated/keys_uav.h"
#include "../ext/hacl-c/Hacl_Ed25519.h"
#include "../ext/hacl-c/Hacl_Curve25519.h"
#include "../ext/hacl-c/Hacl_SHA2_512.h"
#include "../ext/hacl-c/Hacl_Chacha20Poly1305.h"
#include "../ext/hacl-c/kremlib.h"
+ Include dependency graph for gec.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  gec_privkey
 
struct  gec_pubkey
 
struct  gec_sym_key
 
struct  gec_sts_ctx
 

Macros

#define PPRZ_MSG_TYPE_PLAINTEXT   0xaa
 
#define PPRZ_MSG_TYPE_ENCRYPTED   0x55
 
#define PPRZ_GEC_IDX   0
 
#define PPRZ_CNTR_IDX   1
 
#define PPRZ_AUTH_IDX   5
 
#define PPRZ_SIGN_LEN   64
 
#define PPRZ_HASH_LEN   64
 
#define PPRZ_KEY_LEN   32
 
#define PPRZ_MAC_LEN   16
 
#define PPRZ_NONCE_LEN   12
 
#define PPRZ_COUNTER_LEN   4
 
#define PPRZ_CRYPTO_OVERHEAD   20
 
#define PPRZ_CURVE_BASEPOINT   9
 

Typedefs

typedef unsigned char ed25519_signature[64]
 

Enumerations

enum  stage_t {
  INIT , WAIT_MSG1 , WAIT_MSG2 , WAIT_MSG3 ,
  CRYPTO_OK
}
 
enum  party_t { INITIATOR , RESPONDER , CLIENT , INVALID_PARTY }
 
enum  gec_sts_msg_type_t { P_AE , P_BE , SIG }
 
enum  sts_error_t {
  ERROR_NONE , MSG1_TIMEOUT_ERROR , MSG1_ENCRYPT_ERROR , MSG3_TIMEOUT_ERROR ,
  MSG3_DECRYPT_ERROR , MSG3_SIGNVERIFY_ERROR , MSG2_TIMEOUT_ERROR , MSG2_DECRYPT_ERROR ,
  MSG2_SIGNVERIFY_ERROR , MSG3_ENCRYPT_ERROR , UNEXPECTED_MSG_TYPE_ERROR , UNEXPECTED_MSG_DATA_ERROR ,
  UNEXPECTED_MSG_ERROR
}
 

Functions

void gec_sts_init (struct gec_sts_ctx *sts)
 
void gec_clear_sts (struct gec_sts_ctx *sts)
 
void gec_generate_ephemeral_keys (struct gec_privkey *sk)
 Generate private and public key pairs for future use. More...
 
void gec_derive_key_material (struct gec_sts_ctx *sts, uint8_t *z)
 Derive key material for both sender and receiver. More...
 
void gec_counter_to_bytes (uint32_t n, uint8_t *bytes)
 Convert counter to bytes in network byte order. More...
 
uint32_t gec_bytes_to_counter (uint8_t *bytes)
 Convert from network byte order (big endian) to the machine byte order. More...
 

Detailed Description

Galois embedded crypto implementation.

Definition in file gec.h.


Data Structure Documentation

◆ gec_privkey

struct gec_privkey

Definition at line 67 of file gec.h.

Data Fields
uint8_t priv[PPRZ_KEY_LEN]
uint8_t pub[PPRZ_KEY_LEN]
bool ready

◆ gec_pubkey

struct gec_pubkey

Definition at line 72 of file gec.h.

Data Fields
uint8_t pub[PPRZ_KEY_LEN]
bool ready

◆ gec_sym_key

struct gec_sym_key

Definition at line 76 of file gec.h.

Data Fields
uint32_t counter
uint8_t key[PPRZ_KEY_LEN]
uint8_t nonce[PPRZ_NONCE_LEN]
bool ready

◆ gec_sts_ctx

struct gec_sts_ctx

Definition at line 115 of file gec.h.

+ Collaboration diagram for gec_sts_ctx:
Data Fields
uint32_t decrypt_err
uint32_t encrypt_err
sts_error_t last_error
struct gec_privkey my_private_ephemeral
struct gec_privkey my_private_key
party_t party
stage_t protocol_stage
uint32_t rx_counter_err
struct gec_sym_key rx_sym_key
struct gec_pubkey their_public_ephemeral
struct gec_pubkey their_public_key
struct gec_sym_key tx_sym_key

Macro Definition Documentation

◆ PPRZ_AUTH_IDX

#define PPRZ_AUTH_IDX   5

Definition at line 46 of file gec.h.

◆ PPRZ_CNTR_IDX

#define PPRZ_CNTR_IDX   1

Definition at line 44 of file gec.h.

◆ PPRZ_COUNTER_LEN

#define PPRZ_COUNTER_LEN   4

Definition at line 59 of file gec.h.

◆ PPRZ_CRYPTO_OVERHEAD

#define PPRZ_CRYPTO_OVERHEAD   20

Definition at line 61 of file gec.h.

◆ PPRZ_CURVE_BASEPOINT

#define PPRZ_CURVE_BASEPOINT   9

Definition at line 63 of file gec.h.

◆ PPRZ_GEC_IDX

#define PPRZ_GEC_IDX   0

Definition at line 42 of file gec.h.

◆ PPRZ_HASH_LEN

#define PPRZ_HASH_LEN   64

Definition at line 51 of file gec.h.

◆ PPRZ_KEY_LEN

#define PPRZ_KEY_LEN   32

Definition at line 53 of file gec.h.

◆ PPRZ_MAC_LEN

#define PPRZ_MAC_LEN   16

Definition at line 55 of file gec.h.

◆ PPRZ_MSG_TYPE_ENCRYPTED

#define PPRZ_MSG_TYPE_ENCRYPTED   0x55

Definition at line 40 of file gec.h.

◆ PPRZ_MSG_TYPE_PLAINTEXT

#define PPRZ_MSG_TYPE_PLAINTEXT   0xaa

Definition at line 39 of file gec.h.

◆ PPRZ_NONCE_LEN

#define PPRZ_NONCE_LEN   12

Definition at line 57 of file gec.h.

◆ PPRZ_SIGN_LEN

#define PPRZ_SIGN_LEN   64

Definition at line 49 of file gec.h.

Typedef Documentation

◆ ed25519_signature

typedef unsigned char ed25519_signature[64]

Definition at line 65 of file gec.h.

Enumeration Type Documentation

◆ gec_sts_msg_type_t

Enumerator
P_AE 
P_BE 
SIG 

Definition at line 90 of file gec.h.

◆ party_t

enum party_t
Enumerator
INITIATOR 
RESPONDER 
CLIENT 
INVALID_PARTY 

Definition at line 86 of file gec.h.

◆ stage_t

enum stage_t
Enumerator
INIT 
WAIT_MSG1 
WAIT_MSG2 
WAIT_MSG3 
CRYPTO_OK 

Definition at line 82 of file gec.h.

◆ sts_error_t

Enumerator
ERROR_NONE 
MSG1_TIMEOUT_ERROR 
MSG1_ENCRYPT_ERROR 
MSG3_TIMEOUT_ERROR 
MSG3_DECRYPT_ERROR 
MSG3_SIGNVERIFY_ERROR 
MSG2_TIMEOUT_ERROR 
MSG2_DECRYPT_ERROR 
MSG2_SIGNVERIFY_ERROR 
MSG3_ENCRYPT_ERROR 
UNEXPECTED_MSG_TYPE_ERROR 
UNEXPECTED_MSG_DATA_ERROR 
UNEXPECTED_MSG_ERROR 

Definition at line 94 of file gec.h.

Function Documentation

◆ gec_bytes_to_counter()

uint32_t gec_bytes_to_counter ( uint8_t bytes)

Convert from network byte order (big endian) to the machine byte order.

Definition at line 117 of file gec.c.

Referenced by gec_decrypt_message().

+ Here is the caller graph for this function:

◆ gec_clear_sts()

void gec_clear_sts ( struct gec_sts_ctx sts)

Definition at line 54 of file gec.c.

References ERROR_NONE, RESPONDER, sts, and WAIT_MSG1.

Referenced by gec_sts_init().

+ Here is the caller graph for this function:

◆ gec_counter_to_bytes()

void gec_counter_to_bytes ( uint32_t  n,
uint8_t bytes 
)

Convert counter to bytes in network byte order.

Definition at line 142 of file gec.c.

Referenced by gec_encrypt_message().

+ Here is the caller graph for this function:

◆ gec_derive_key_material()

void gec_derive_key_material ( struct gec_sts_ctx sts,
uint8_t z 
)

Derive key material for both sender and receiver.

Definition at line 91 of file gec.c.

References gec_sym_key::counter, gec_sym_key::key, gec_sym_key::nonce, PPRZ_KEY_LEN, PPRZ_NONCE_LEN, gec_sym_key::ready, gec_sts_ctx::rx_sym_key, and gec_sts_ctx::tx_sym_key.

Referenced by gec_process_msg1().

+ Here is the caller graph for this function:

◆ gec_generate_ephemeral_keys()

void gec_generate_ephemeral_keys ( struct gec_privkey sk)

Generate private and public key pairs for future use.

Definition at line 73 of file gec.c.

References PPRZ_KEY_LEN, gec_privkey::priv, gec_privkey::pub, gec_privkey::ready, and rng_wait_and_get().

Referenced by gec_process_msg1(), and gec_sts_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gec_sts_init()

void gec_sts_init ( struct gec_sts_ctx sts)

Definition at line 33 of file gec.c.

References gec_clear_sts(), gec_generate_ephemeral_keys(), PPRZ_KEY_LEN, and sts.

Referenced by gec_dl_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: