Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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

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
struct gec_pubkey

Definition at line 72 of file gec.h.

Data Fields
uint8_t pub[PPRZ_KEY_LEN]
bool ready
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
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

#define PPRZ_AUTH_IDX   5

Definition at line 46 of file gec.h.

Referenced by gec_decrypt_message(), and gec_encrypt_message().

#define PPRZ_CNTR_IDX   1

Definition at line 44 of file gec.h.

Referenced by gec_decrypt_message(), and gec_encrypt_message().

#define PPRZ_COUNTER_LEN   4

Definition at line 59 of file gec.h.

#define PPRZ_CRYPTO_OVERHEAD   20

Definition at line 61 of file gec.h.

Referenced by gec_decrypt_message(), and gec_encrypt_message().

#define PPRZ_CURVE_BASEPOINT   9

Definition at line 63 of file gec.h.

#define PPRZ_GEC_IDX   0

Definition at line 42 of file gec.h.

Referenced by gec_decrypt_message(), gec_encrypt_message(), and gec_process_msg1().

#define PPRZ_HASH_LEN   64

Definition at line 51 of file gec.h.

#define PPRZ_KEY_LEN   32
#define PPRZ_MAC_LEN   16

Definition at line 55 of file gec.h.

Referenced by gec_decrypt_message(), gec_encrypt_message(), gec_process_msg1(), and gec_process_msg3().

#define PPRZ_MSG_TYPE_ENCRYPTED   0x55

Definition at line 40 of file gec.h.

Referenced by gec_decrypt_message(), and gec_encrypt_message().

#define PPRZ_MSG_TYPE_PLAINTEXT   0xaa

Definition at line 39 of file gec.h.

Referenced by gec_decrypt_message(), and gec_process_msg1().

#define PPRZ_NONCE_LEN   12

Definition at line 57 of file gec.h.

Referenced by gec_derive_key_material().

#define PPRZ_SIGN_LEN   64

Definition at line 49 of file gec.h.

Referenced by gec_process_msg1(), and gec_process_msg3().

Typedef Documentation

typedef unsigned char ed25519_signature[64]

Definition at line 65 of file gec.h.

Enumeration Type Documentation

Enumerator
P_AE 
P_BE 
SIG 

Definition at line 90 of file gec.h.

enum party_t
Enumerator
INITIATOR 
RESPONDER 
CLIENT 
INVALID_PARTY 

Definition at line 86 of file gec.h.

enum stage_t
Enumerator
INIT 
WAIT_MSG1 
WAIT_MSG2 
WAIT_MSG3 
CRYPTO_OK 

Definition at line 82 of file gec.h.

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

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:

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:

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:

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:

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(), gec_sts_ctx::my_private_ephemeral, gec_sts_ctx::my_private_key, PPRZ_KEY_LEN, gec_privkey::priv, gec_privkey::pub, gec_privkey::ready, gec_pubkey::ready, and gec_sts_ctx::their_public_key.

Referenced by gec_dl_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function: