From 0b3785b64454499b2bd56afb7c3a214a2f8bad93 Mon Sep 17 00:00:00 2001 From: Nunu Date: Wed, 24 Jan 2024 10:39:23 +0100 Subject: [PATCH] nonce working --- app/messenger.c | 22 +++++++++++++++------- app/messenger.h | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/messenger.c b/app/messenger.c index 73ded61..ad5fc49 100644 --- a/app/messenger.c +++ b/app/messenger.c @@ -63,11 +63,6 @@ unsigned char key[32] = { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f }; -unsigned char nonce[12] = { - 0x07, 0x00, 0x00, 0x00, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 -}; - // ----------------------------------------------------- void MSG_FSKSendData() { @@ -565,7 +560,20 @@ void MSG_SendPacket(union DataPacket packet) { dataPacket = packet; if(packet.unencrypted.header == ENCRYPTED_MESSAGE_PACKET){ - CRYPTO_Crypt(packet.encrypted.ciphertext, PAYLOAD_LENGTH, dataPacket.encrypted.ciphertext, nonce, key, 256); + char nonce[NONCE_LENGTH]; + CRYPTO_Random(nonce, NONCE_LENGTH-1); + // this is wat happens when we have global state + memcpy(packet.encrypted.nonce, nonce, NONCE_LENGTH); + + CRYPTO_Crypt( + packet.encrypted.ciphertext, + PAYLOAD_LENGTH, + dataPacket.encrypted.ciphertext, + &packet.encrypted.nonce, + key, + 256 + ); + memcpy(dataPacket.encrypted.nonce, nonce, sizeof(dataPacket.encrypted.nonce)); } @@ -682,7 +690,7 @@ void MSG_StorePacket(const uint16_t interrupt_bits) { CRYPTO_Crypt(dataPacket.encrypted.ciphertext, PAYLOAD_LENGTH, dencryptedTxMessage, - dataPacket.encrypted.nonce, + &dataPacket.encrypted.nonce, key, 256); diff --git a/app/messenger.h b/app/messenger.h index 59c27d3..f2ceb24 100644 --- a/app/messenger.h +++ b/app/messenger.h @@ -46,7 +46,7 @@ union DataPacket struct{ uint8_t header; uint8_t ciphertext[PAYLOAD_LENGTH]; - uint8_t nonce[NONCE_LENGTH]; + unsigned char nonce[NONCE_LENGTH]; // uint8_t signature[SIGNATURE_LENGTH]; } encrypted;