Paparazzi UAS  v5.15_devel-88-gb3ad7fe
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gec.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Michal Podhradsky <mpodhradsky@galois.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
27 #ifndef SPPRZ_GEC_H
28 #define SPPRZ_GEC_H
29 
30 #include "std.h"
31 #include "mcu_periph/rng.h"
32 #include "generated/keys_uav.h"
33 #include "../ext/hacl-c/Hacl_Ed25519.h"
34 #include "../ext/hacl-c/Hacl_Curve25519.h"
35 #include "../ext/hacl-c/Hacl_SHA2_512.h"
36 #include "../ext/hacl-c/Hacl_Chacha20Poly1305.h"
37 #include "../ext/hacl-c/kremlib.h"
38 
39 #define PPRZ_MSG_TYPE_PLAINTEXT 0xaa
40 #define PPRZ_MSG_TYPE_ENCRYPTED 0x55
41 // index of encrypted/payload byte
42 #define PPRZ_GEC_IDX 0
43 // index of the beginning of the counter
44 #define PPRZ_CNTR_IDX 1
45 // index of the beginning of the authenticated bytes
46 #define PPRZ_AUTH_IDX 5
47 
48 // legth of the message signature
49 #define PPRZ_SIGN_LEN 64
50 // lenght of a hash for key derivation
51 #define PPRZ_HASH_LEN 64
52 // length of the encryption keys
53 #define PPRZ_KEY_LEN 32
54 // length of the message authentication tag
55 #define PPRZ_MAC_LEN 16
56 // length of the message nonce
57 #define PPRZ_NONCE_LEN 12
58 // length of the counter
59 #define PPRZ_COUNTER_LEN 4
60 // length of the crypto overhead (4 bytes of counter + 16 bytes of tag)
61 #define PPRZ_CRYPTO_OVERHEAD 20
62 // basepoint value for the scalar curve multiplication
63 #define PPRZ_CURVE_BASEPOINT 9
64 
65 typedef unsigned char ed25519_signature[64];
66 
67 struct gec_privkey {
70 };
71 
72 struct gec_pubkey {
74 };
75 
76 struct gec_sym_key {
80 };
81 
82 typedef enum {
84 } stage_t;
85 
86 typedef enum {
88 } party_t;
89 
90 typedef enum {
93 
94 typedef enum {
96  // RESPONDER ERRORS
102  // INITIATOR ERRORS
107  // BOTH PARTIES
111 } sts_error_t;
112 
113 // Intermediate data structure containing information relating to the stage of
114 // the STS protocol.
115 struct gec_sts_ctx {
128 };
129 
130 void gec_sts_init(struct gec_sts_ctx *sts);
131 void gec_clear_sts(struct gec_sts_ctx *sts);
133 void gec_derive_key_material(struct gec_sts_ctx *sts, uint8_t *z);
134 
135 void gec_counter_to_bytes(uint32_t n, uint8_t *bytes);
137 
138 #endif /* SPPRZ_GEC_H */
void gec_generate_ephemeral_keys(struct gec_privkey *sk)
Generate private and public key pairs for future use.
Definition: gec.c:73
void gec_counter_to_bytes(uint32_t n, uint8_t *bytes)
Convert counter to bytes in network byte order.
Definition: gec.c:142
uint8_t key[PPRZ_KEY_LEN]
Definition: gec.h:77
Definition: gec.h:83
bool ready
Definition: gec.h:79
bool ready
Definition: gec.h:69
uint8_t pub[PPRZ_KEY_LEN]
Definition: gec.h:73
struct gec_privkey my_private_ephemeral
Definition: gec.h:119
sts_error_t
Definition: gec.h:94
Definition: gec.h:91
Definition: gec.h:87
struct gec_pubkey their_public_key
Definition: gec.h:116
uint32_t encrypt_err
Definition: gec.h:126
stage_t protocol_stage
Definition: gec.h:122
unsigned char ed25519_signature[64]
Definition: gec.h:65
Definition: gec.h:87
stage_t
Definition: gec.h:82
uint32_t decrypt_err
Definition: gec.h:127
struct gec_sym_key rx_sym_key
Definition: gec.h:120
uint8_t pub[PPRZ_KEY_LEN]
Definition: gec.h:69
struct gec_pubkey their_public_ephemeral
Definition: gec.h:118
unsigned long uint32_t
Definition: types.h:18
void gec_clear_sts(struct gec_sts_ctx *sts)
Definition: gec.c:54
Definition: gec.h:83
arch independent Random Number Generator API
bool ready
Definition: gec.h:73
Definition: gec.h:83
#define PPRZ_NONCE_LEN
Definition: gec.h:57
sts_error_t last_error
Definition: gec.h:124
uint32_t gec_bytes_to_counter(uint8_t *bytes)
Convert from network byte order (big endian) to the machine byte order.
Definition: gec.c:117
gec_sts_msg_type_t
Definition: gec.h:90
party_t
Definition: gec.h:86
struct gec_sym_key tx_sym_key
Definition: gec.h:121
Definition: gec.h:87
party_t party
Definition: gec.h:123
unsigned char uint8_t
Definition: types.h:14
uint8_t nonce[PPRZ_NONCE_LEN]
Definition: gec.h:78
Definition: gec.h:91
Definition: gec.h:95
Definition: gec.h:72
Definition: gec.h:83
uint32_t counter
Definition: gec.h:79
uint32_t rx_counter_err
Definition: gec.h:125
uint8_t priv[PPRZ_KEY_LEN]
Definition: gec.h:68
Definition: gec.h:83
void gec_derive_key_material(struct gec_sts_ctx *sts, uint8_t *z)
Derive key material for both sender and receiver.
Definition: gec.c:91
void gec_sts_init(struct gec_sts_ctx *sts)
Definition: gec.c:33
#define PPRZ_KEY_LEN
Definition: gec.h:53
struct gec_privkey my_private_key
Definition: gec.h:117
Definition: gec.h:91