aggregator recieved messages decryption

aggregator-decription
033zhek 1 year ago
parent ca8d66c521
commit 2efc7889a5

1
.gitignore vendored

@ -1 +1,2 @@
cybergarden-sensor/.vscode
cybergarden-aggregator/.vscode

@ -8,7 +8,33 @@
#define ECC_LENGTH 4
#define TOTAL_LENGTH (MSG_LENGTH + ECC_LENGTH)
bool TransmissionModule::receive(uint8_t &sensor_id, MeasureData &data) {
void TransmissionModule::decrypt(uint8_t *data, size_t data_size, uint8_t *output_data)
{
size_t posn, len, inc = 5;
cipher->clear();
cipher->setKey(encryptionKey, key_size);
cipher->setIV(iv, iv_size);
memset(buffer, 0xBA, sizeof(buffer));
for (posn = 0; posn < auth_size; posn += inc) {
len = auth_size - posn;
if (len > inc)
len = inc;
cipher->addAuthData(authdata + posn, len);
}
for (posn = 0; posn < data_size; posn += inc) {
len = data_size - posn;
if (len > inc)
len = inc;
cipher->decrypt(buffer + posn, data + posn, len);
}
memcpy(output_data, buffer, data_size);
}
bool TransmissionModule::receive(uint8_t &sensor_id, MeasureData &data)
{
uint8_t buf[TOTAL_LENGTH];
if (!transmitterModule->receive(buf, TOTAL_LENGTH)) {
return false;

@ -1,17 +1,39 @@
#ifndef KEMPT_KINKAJOU_TRANSMISSIONMODULE_H
#define KEMPT_KINKAJOU_TRANSMISSIONMODULE_H
#include <Arduino.h>
#include <Crypto.h>
#include <ChaChaPoly.h>
#include "MeasureData.h"
#include "TransmitterModule.h"
#include "ReedSolomonModule.h"
#ifndef KEMPT_KINKAJOU_TRANSMISSIONMODULE_H
#define KEMPT_KINKAJOU_TRANSMISSIONMODULE_H
#define MAX_PLAINTEXT_LEN 265
class TransmissionModule {
private:
TransmitterModule * transmitterModule;
ReedSolomonModule * reedSolomonModule;
ChaChaPoly* cipher;
uint8_t encryptionKey[16] = {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f};
uint8_t authdata[16] = {0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3,
0xc4, 0xc5, 0xc6, 0xc7};
uint8_t iv[16] = {0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43,
0x44, 0x45, 0x46, 0x47};
uint8_t buffer[MAX_PLAINTEXT_LEN];
size_t key_size = 16;
size_t auth_size = 12;
// size_t data_size = 4;
size_t iv_size = 12;
public:
TransmissionModule(TransmitterModule &transmitterModule, ReedSolomonModule &reedSolomonModule) : transmitterModule(&transmitterModule), reedSolomonModule(&reedSolomonModule) {}
TransmissionModule(TransmitterModule &transmitterModule, ReedSolomonModule &reedSolomonModule) :
transmitterModule(&transmitterModule),
reedSolomonModule(&reedSolomonModule) {
cipher = new ChaChaPoly();
}
void decrypt(uint8_t * data, size_t data_size, uint8_t* output_data);
bool receive(uint8_t &sendor_id, MeasureData &data);
};

@ -1,12 +1,13 @@
//
// Created by o.likhogub on 10/7/2023.
//
#ifndef KEMPT_KINKAJOU_TRANSMITTERMODULE_H
#define KEMPT_KINKAJOU_TRANSMITTERMODULE_H
#include "Arduino.h"
#include <RH_ASK.h>
#include <SPI.h>
#ifndef KEMPT_KINKAJOU_TRANSMITTERMODULE_H
#define KEMPT_KINKAJOU_TRANSMITTERMODULE_H
class TransmitterModule {
private:

@ -8,7 +8,7 @@
// https://en.wikipedia.org/wiki/Universally_unique_identifier
#include "UUID.h"
#include "Uuid.h"
UUID::UUID()

@ -16,3 +16,4 @@ monitor_speed = 115200
lib_deps =
mikem/RadioHead@^1.120
bblanchon/ArduinoJson@^6.21.3
rweather/Crypto@^0.4.0

Loading…
Cancel
Save