Skip to content

Commit

Permalink
fix enc key initialization after boot
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsss655 committed Jan 31, 2024
1 parent fd03292 commit 229806d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
10 changes: 10 additions & 0 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
#ifdef ENABLE_MESSENGER
#include "app/messenger.h"
#endif
#ifdef ENABLE_ENCRYPTION
#include "helper/crypto.h"
#endif

#ifdef ENABLE_MESSENGER_NOTIFICATION
bool gPlayMSGRing = false;
Expand Down Expand Up @@ -1309,6 +1312,13 @@ void APP_TimeSlice500ms(void)
} else if (hasNewMessage == 2) {
hasNewMessage = 1;
}
}
#endif

#ifdef ENABLE_ENCRYPTION
if(gRecalculateEncKey){
CRYPTO_Generate256BitKey(gEeprom.ENC_KEY, gEncryptionKey, sizeof(gEeprom.ENC_KEY));
gRecalculateEncKey = false;
}
#endif

Expand Down
3 changes: 3 additions & 0 deletions app/messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,9 @@ void MSG_Init() {
prevKey = 0;
prevLetter = 0;
cIndex = 0;
#ifdef ENABLE_ENCRYPTION
gRecalculateEncKey = true;
#endif
}

void MSG_SendAck() {
Expand Down
2 changes: 2 additions & 0 deletions helper/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "driver/bk4819.h"
#include "driver/systick.h"

bool gRecalculateEncKey;

u_int8_t gEncryptionKey[32];

// salt used for hashing encryption key from eeprom used for sending packets
Expand Down
6 changes: 3 additions & 3 deletions helper/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdbool.h>
#include <stdint.h>

extern uint8_t gEncryptionKey[32];
extern bool gRecalculateEncKey;
extern uint8_t gEncryptionKey[32];
static const uint8_t encryptionSalt[4][8];
static const uint8_t displaySalt[32];

Expand Down
3 changes: 1 addition & 2 deletions settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ void SETTINGS_SaveEncryptionKey()
{
EEPROM_WriteBuffer(0x0F30, gEeprom.ENC_KEY, true);
EEPROM_WriteBuffer(0x0F38, gEeprom.ENC_KEY + 8, true);

CRYPTO_Generate256BitKey(gEeprom.ENC_KEY, gEncryptionKey, sizeof(gEeprom.ENC_KEY));
gRecalculateEncKey = true;
}
#endif

Expand Down

0 comments on commit 229806d

Please sign in to comment.