mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-22 02:32:23 +00:00
clean up the crypto api
This commit is contained in:
@@ -6,30 +6,13 @@
|
||||
class NRF52CryptoEngine : public CryptoEngine
|
||||
{
|
||||
|
||||
/// How many bytes in our key
|
||||
uint8_t keySize = 0;
|
||||
const uint8_t *keyBytes;
|
||||
|
||||
|
||||
public:
|
||||
NRF52CryptoEngine() {}
|
||||
|
||||
~NRF52CryptoEngine() {}
|
||||
|
||||
/**
|
||||
* 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 16 (AES128), 32 (AES256) or 0 (no crypt)
|
||||
* @param bytes a _static_ buffer that will remain valid for the life of this crypto instance (i.e. this class will cache the
|
||||
* provided pointer)
|
||||
*/
|
||||
virtual void setKey(size_t numBytes, uint8_t *bytes)
|
||||
{
|
||||
keySize = numBytes;
|
||||
keyBytes = bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt a packet
|
||||
*
|
||||
@@ -39,11 +22,11 @@ class NRF52CryptoEngine : public CryptoEngine
|
||||
{
|
||||
// DEBUG_MSG("NRF52 encrypt!\n");
|
||||
|
||||
if (keySize != 0) {
|
||||
if (key.length > 0) {
|
||||
ocrypto_aes_ctr_ctx ctx;
|
||||
|
||||
initNonce(fromNode, packetNum);
|
||||
ocrypto_aes_ctr_init(&ctx, keyBytes, keySize, nonce);
|
||||
ocrypto_aes_ctr_init(&ctx, key.bytes, key.length, nonce);
|
||||
|
||||
ocrypto_aes_ctr_encrypt(&ctx, bytes, bytes, numBytes);
|
||||
}
|
||||
@@ -53,11 +36,11 @@ class NRF52CryptoEngine : public CryptoEngine
|
||||
{
|
||||
// DEBUG_MSG("NRF52 decrypt!\n");
|
||||
|
||||
if (keySize != 0) {
|
||||
if (key.length > 0) {
|
||||
ocrypto_aes_ctr_ctx ctx;
|
||||
|
||||
initNonce(fromNode, packetNum);
|
||||
ocrypto_aes_ctr_init(&ctx, keyBytes, keySize, nonce);
|
||||
ocrypto_aes_ctr_init(&ctx, key.bytes, key.length, nonce);
|
||||
|
||||
ocrypto_aes_ctr_decrypt(&ctx, bytes, bytes, numBytes);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user