From 6d4736c6989065d1598496d1cacb2f35731d6203 Mon Sep 17 00:00:00 2001 From: dorababu <dorababu@subcom.tech> Date: Wed, 3 Aug 2022 17:48:33 +0530 Subject: [PATCH] chnaged name src to main --- RegFPwithHash/src/{src.cpp => main.cpp} | 21 ++++++++++++++------- matchFPandHash/src/{src.cpp => main.cpp} | 11 ++++++----- 2 files changed, 20 insertions(+), 12 deletions(-) rename RegFPwithHash/src/{src.cpp => main.cpp} (94%) rename matchFPandHash/src/{src.cpp => main.cpp} (96%) 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 1547c0a..143dac8 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 7afea72..51928ba 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++) { -- GitLab