fixed spi-flash-reboot on esp32, encryption kinda works

pull/1/head
033zhek 1 year ago
parent 8cb54166b9
commit 2146173559

1
.gitignore vendored

@ -0,0 +1 @@
cybergarden-sensor/.vscode

@ -30,24 +30,28 @@ void TransmissionModule::encrypt(uint8_t * input_data, size_t data_size, uint8_t
cipher->encrypt(buffer + posn, input_data + posn, len);
}
byte buffer2[MAX_PLAINTEXT_LEN];
memset(buffer2, 0xBA, sizeof(buffer));
//*************************
//Encryption Testing
//*************************
cipher->setKey(encryptionKey, 16);
cipher->setIV(iv, iv_size);
// byte buffer2[MAX_PLAINTEXT_LEN];
// memset(buffer2, 0xBA, sizeof(buffer));
for (posn = 0; posn < data_size; posn += inc) {
len = data_size - posn;
if (len > inc)
len = inc;
cipher->decrypt(buffer2 + posn, buffer + posn, len);
}
// cipher->setKey(encryptionKey, 16);
// cipher->setIV(iv, iv_size);
if (memcmp(buffer2, input_data, data_size) != 0) {
// Serial.println("doesn't work");
} else{
// Serial.println("works");
}
// for (posn = 0; posn < data_size; posn += inc) {
// len = data_size - posn;
// if (len > inc)
// len = inc;
// cipher->decrypt(buffer2 + posn, buffer + posn, len);
// }
// if (memcmp(buffer2, input_data, data_size) != 0) {
// Serial.println("doesn't work");
// } else{
// Serial.println("works");
// }
memcpy(output_data, buffer, data_size);
}
@ -57,8 +61,6 @@ void TransmissionModule::transmit(MeasureData &data)
uint8_t msg[MSG_LENGTH];
msg[0] = data.sensor_id;
memcpy(msg + 1, (void *) &data, 4);
uint8_t encoded[MSG_LENGTH + ECC_LENGTH];
reedSolomonModule->encode(msg, encoded);
transmitterModule->send(encoded, MSG_LENGTH + ECC_LENGTH);

@ -8,15 +8,15 @@
#ifndef KEMPT_KINKAJOU_TRANSMITTERMODULE_H
#define KEMPT_KINKAJOU_TRANSMITTERMODULE_H
#define RH_TRANSMIT_PIN 12
#define RH_RECEIVE_PIN 11
#define RH_TRANSMIT_PIN 5
#define RH_RECEIVE_PIN 4
class TransmitterModule {
private:
RH_ASK *rhAsk;
public:
TransmitterModule() {
rhAsk = new RH_ASK();
rhAsk = new RH_ASK(2000, RH_RECEIVE_PIN, RH_TRANSMIT_PIN);
}
bool init() {
return rhAsk->init();

@ -10,7 +10,6 @@ TransmissionModule transmissionModule(transmitterModule, reedSolomonModule);
void setup() {
Serial.begin(115200);
transmitterModule.init();
// pinMode(LED_BUILTIN, OUTPUT);
}
uint16_t getMockSensorData() {
@ -22,11 +21,7 @@ void loop() {
measureData.sensor_id = 0xA5;
measureData.sensor_type = 0x01;
measureData.payload = getMockSensorData();
// transmissionModule.encrypt((uint8_t*)&measureData+1, 4, (uint8_t*)&measureData+1);
transmissionModule.encrypt((uint8_t*)&measureData+1, 4, (uint8_t*)&measureData+1);
transmissionModule.transmit(measureData);
// analogWrite(LED_BUILTIN, 255);
// delay(200);
// analogWrite(LED_BUILTIN, 0);
// delay(10000);
delay(1000);
}
Loading…
Cancel
Save