Skip to content

Commit

Permalink
Added EEPROM storage
Browse files Browse the repository at this point in the history
  • Loading branch information
phippstech committed Feb 17, 2024
1 parent 95dbc32 commit 8791d59
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
8 changes: 4 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ monitor_speed = 74880
; use faster upload speed
upload_speed = 921600

[env:huzzah_config]
;[env:huzzah_config]
; everything except crypto example (= this is the config exmaple)
build_src_filter = +<*> -<AES_crypto_example.cpp>
;build_src_filter = +<*> -<AES_crypto_example.cpp>

;[env:huzzah_aes]
[env:huzzah_aes]
; everything except main.cpp (= this is the AES exmaple)
;build_src_filter = +<*> -<main.cpp>
build_src_filter = +<*> -<main.cpp>
23 changes: 14 additions & 9 deletions src/AES_crypto_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern "C"
#include "cryptoauthlib.h"
}
#include "aes_cbc.h"

#include <EEPROM.h>
// Key Slot number
uint8_t KEY_SLOT = (uint8_t)9;

Expand All @@ -14,11 +14,10 @@ ATCA_STATUS status;
void setup()
{
Serial.begin(74880);

// Init the constuctor for the library
cfg.iface_type = ATCA_I2C_IFACE; // Type of communication -> I2C mode
cfg.devtype = ATECC608A; // Type of chip
cfg.atcai2c.slave_address = 0X60; // I2C address of the Adafruit Breakout Board
cfg.atcai2c.slave_address = 0X30; // I2C address of the Adafruit Breakout Board
cfg.atcai2c.bus = 1;
cfg.atcai2c.baud = 100000;
cfg.wake_delay = 1500; // Delay of wake up (1500 ms)
Expand All @@ -34,18 +33,23 @@ void loop()
Serial.println(F("atcab_init() failed : Code -> 0x"));
Serial.println(status, HEX);
}

uint8_t plaintext[16] = "AAAAAAAAAAAAAAA";

uint addr = 0; //Address for EEPROM
uint8_t plaintext[32] = "EB4655C2-372F-4133-82B9-AC3DECA";
uint8_t iv[IV_LENGTH_CBC];
uint8_t cypherdata[sizeof(plaintext)];
uint8_t decryptdata[sizeof(plaintext)];

Serial.println("Beginning of the encryption !");
status = aes_cbc_encrypt(&cfg, plaintext, sizeof(plaintext), iv, cypherdata, KEY_SLOT);
if (status == ATCA_SUCCESS)
{
status = aes_cbc_decrypt(&cfg, cypherdata, sizeof(cypherdata), iv, decryptdata, KEY_SLOT);
Serial.println("encrypted");
EEPROM.begin(512);// commit 512 bytes of ESP8266 flash (for "EEPROM" emulation)
EEPROM.put(addr,cypherdata);
EEPROM.commit();
Serial.println("Beginning of the decryption !");
uint8_t FP_cypherdata[sizeof(plaintext)];//Calling it something else to make sure we are in fact pulling it from EEPROM
EEPROM.get(addr,FP_cypherdata);
status = aes_cbc_decrypt(&cfg, FP_cypherdata, sizeof(FP_cypherdata), iv, decryptdata, KEY_SLOT);
if (status == ATCA_SUCCESS)
{
Serial.print("Decrypted text is : ");
Expand All @@ -57,7 +61,7 @@ void loop()
}
else
{
// See file atca_status.h for the code Error
// See file atca_status.h for the code Error
Serial.print(F("Impossible do the decryption | Code Error 0x"));
Serial.println(status, HEX);
return;
Expand All @@ -70,4 +74,5 @@ void loop()
Serial.println(status, HEX);
return;
}
delay(1000);
}

0 comments on commit 8791d59

Please sign in to comment.