diff --git a/RegFPwithHash/src/src.cpp b/RegFPwithHash/src/main.cpp similarity index 94% rename from RegFPwithHash/src/src.cpp rename to RegFPwithHash/src/main.cpp index 1547c0acbd903498c5787bf5db6888dff80545fd..143dac82704e40cd751b39b8666328296600be05 100644 --- a/RegFPwithHash/src/src.cpp +++ b/RegFPwithHash/src/main.cpp @@ -1,7 +1,7 @@ #include <Arduino.h> -#include <Crypto.h> #include <DFRobot_ID809.h> #include <EEPROM.h> +#include <sha256.h> // use serial3 as interface with fingerprint // sensor. @@ -14,8 +14,8 @@ // Collect the fingerprint 3 times -#define COLLECT_NUMBER 3 - +#define COLLECT_NUMBER 3 +#define SHA256_SIZE 32 // EEPROM OFFSET to store /*------Global variables--------------*/ @@ -30,9 +30,10 @@ const uint16_t EEPROM_FP_HASH = 1696; void compute_hash() { - SHA256 hasher; - hasher.doUpdate(temp, sizeof(temp)); - hasher.doFinal(hash); + SHA256_CTX ctx; + sha256_init(&ctx); + sha256_update(&ctx, temp, sizeof(temp)); + sha256_final(&ctx, hash); for (uint8_t i = 0; i < SHA256_SIZE; i++) { @@ -64,6 +65,12 @@ void saveHash() { memoryAddress = EEPROM_FP_HASH + ((ID - 1) * 32); + if(memoryAddress > 2016){ + Serial.println("Error: not enough space in" + " EEPROM"); + return; + } + for (uint8_t i = 0; i < SHA256_SIZE; i++) { EEPROM.write(memoryAddress, hash[i]); @@ -86,7 +93,7 @@ void setup() { Serial.println("Communication with the device failed"); delay(1000); } - // Disable self-learn feature + // Disable self-learn feature fingerprint.setSelfLearn(0); } diff --git a/matchFPandHash/src/src.cpp b/matchFPandHash/src/main.cpp similarity index 96% rename from matchFPandHash/src/src.cpp rename to matchFPandHash/src/main.cpp index 7afea72d61f1ffee178a1a317b33bd94c3616d46..51928ba4ec7f6b7a6a5df73e100670f9e462bac5 100644 --- a/matchFPandHash/src/src.cpp +++ b/matchFPandHash/src/main.cpp @@ -1,7 +1,7 @@ #include <Arduino.h> -#include <Crypto.h> #include <DFRobot_ID809.h> #include <EEPROM.h> +#include <sha256.h> // use serial3 as interface with fingerprint // sensor. @@ -11,7 +11,7 @@ // define buillt_in led #define BUILTIN_LED 13 - +#define SHA256_SIZE 32 // Collect the fingerprint 3 times #define COLLECT_NUMBER 3 @@ -30,9 +30,10 @@ const uint16_t EEPROM_FP_HASH = 1696; void compute_hash() { - SHA256 hasher; - hasher.doUpdate(temp, sizeof(temp)); - hasher.doFinal(hash); + SHA256_CTX ctx; + sha256_init(&ctx); + sha256_update(&ctx, temp, sizeof(temp)); + sha256_final(&ctx, hash); Serial.println("-----------------------"); for (uint8_t i = 0; i < SHA256_SIZE; i++) {