summaryrefslogtreecommitdiff
path: root/fw/src/noise.h
diff options
context:
space:
mode:
Diffstat (limited to 'fw/src/noise.h')
-rw-r--r--fw/src/noise.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/fw/src/noise.h b/fw/src/noise.h
new file mode 100644
index 0000000..1969945
--- /dev/null
+++ b/fw/src/noise.h
@@ -0,0 +1,56 @@
+#ifndef __NOISE_H__
+#define __NOISE_H__
+
+#include <stdint.h>
+
+#include <noise/protocol.h>
+
+#include "usart_helpers.h"
+#include "rand_stm32.h"
+
+
+#define CURVE25519_KEY_LEN 32
+#define MAX_HOST_PACKET_SIZE 128
+
+
+extern volatile uint8_t host_packet_buf[MAX_HOST_PACKET_SIZE];
+extern volatile int host_packet_length;
+
+enum handshake_state {
+ HANDSHAKE_UNINITIALIZED,
+ HANDSHAKE_PHASE1,
+ HANDSHAKE_PHASE2,
+ HANDSHAKE_DONE_UNKNOWN_HOST,
+ HANDSHAKE_DONE_KNOWN_HOST,
+};
+
+extern volatile enum handshake_state handshake_state;
+
+struct NoiseState {
+ NoiseHandshakeState *handshake;
+ enum handshake_state handshake_state;
+ NoiseCipherState *tx_cipher, *rx_cipher;
+ uint8_t *local_key;
+ uint8_t remote_key[CURVE25519_KEY_LEN];
+ uint8_t *remote_key_reference;
+ uint8_t handshake_hash[BLAKE2S_HASH_SIZE];
+ int failed_handshakes;
+};
+
+
+void uninit_handshake(struct NoiseState *st, enum handshake_state new_state);
+void noise_state_init(struct NoiseState *st, uint8_t *remote_key_reference, uint8_t *local_key);
+void persist_remote_key(struct NoiseState *st);
+int start_protocol_handshake(struct NoiseState *st);
+int reset_protocol_handshake(struct NoiseState *st);
+int generate_identity_key(struct NoiseState *st);
+int try_continue_noise_handshake(struct NoiseState * const st, uint8_t *buf, size_t len);
+int send_encrypted_message(struct NoiseState *st, const uint8_t *msg, size_t len);
+
+/*@ assigns \nothing; */
+void arm_key_scrubber(void);
+
+/*@ assigns \nothing; */
+void disarm_key_scrubber(void);
+
+#endif