begin work on crypto

This commit is contained in:
geeksville
2020-05-09 16:15:01 -07:00
parent 8bfe9fa8fc
commit 28d21ecdcc
5 changed files with 86 additions and 2 deletions

16
src/mesh/CryptoEngine.cpp Normal file
View File

@@ -0,0 +1,16 @@
#include "CryptoEngine.h"
#include "configuration.h"
void CryptoEngine::setKey(size_t numBytes, const uint8_t *bytes)
{
DEBUG_MSG("WARNING: Using stub crypto - all crypto is sent in plaintext!\n");
}
/**
* Encrypt a packet
*
* @param bytes is updated in place
*/
void CryptoEngine::encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) {}
void CryptoEngine::decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) {}

31
src/mesh/CryptoEngine.h Normal file
View File

@@ -0,0 +1,31 @@
#pragma once
#include <Arduino.h>
/**
* see docs/software/crypto.md for details.
*
* The NONCE is constructed by concatenating:
* a 32 bit sending node number + a 64 bit packet number + a 32 bit block counter (starts at zero)
*/
class CryptoEngine
{
public:
/**
* Set the key used for encrypt, decrypt.
*
* As a special case: If all bytes are zero, we assume _no encryption_ and send all data in cleartext.
*
* @param numBytes must be 32 for now (AES256)
*/
void setKey(size_t numBytes, const uint8_t *bytes);
/**
* Encrypt a packet
*
* @param bytes is updated in place
*/
void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes);
void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes);
};