From d6e9d9efb498bb3aae364448a32e7849ff7a6cce Mon Sep 17 00:00:00 2001 From: dybm Date: Thu, 6 Oct 2016 16:39:23 +0200 Subject: [PATCH 1/4] Updated 'sha1InitState' and function 'write' 'sha1InitState' must be declared as a constant in order to be put into read-only section by means of '__attribute__((progmem))'. The virtual function 'write' in the Print class changed from returning void to returning a size_t. --- Sha/sha1.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Sha/sha1.cpp b/Sha/sha1.cpp index 9ff3a1c..b707b44 100644 --- a/Sha/sha1.cpp +++ b/Sha/sha1.cpp @@ -8,7 +8,7 @@ #define SHA1_K40 0x8f1bbcdc #define SHA1_K60 0xca62c1d6 -uint8_t sha1InitState[] PROGMEM = { +const uint8_t sha1InitState[] PROGMEM = { 0x01,0x23,0x45,0x67, // H0 0x89,0xab,0xcd,0xef, // H1 0xfe,0xdc,0xba,0x98, // H2 @@ -72,10 +72,18 @@ void Sha1Class::addUncounted(uint8_t data) { } } -void Sha1Class::write(uint8_t data) { +#if ARDUINO >= 100 +inline size_t Sha1Class::write(uint8_t data) { ++byteCount; addUncounted(data); + return 1; } +#else +inline void Sha1Class::write(uint8_t data) { + ++byteCount; + addUncounted(data); +} +#endif void Sha1Class::pad() { // Implement SHA-1 padding (fips180-2 §5.1.1) From fecfa1716b318a7cda2ae9bfcaa796ff4d12d5a2 Mon Sep 17 00:00:00 2001 From: dybm Date: Thu, 6 Oct 2016 16:40:29 +0200 Subject: [PATCH 2/4] Updated function 'write' The virtual function 'write' in the Print class changed from returning void to returning a size_t. --- Sha/sha1.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sha/sha1.h b/Sha/sha1.h index 9975660..87b1a42 100644 --- a/Sha/sha1.h +++ b/Sha/sha1.h @@ -23,7 +23,11 @@ class Sha1Class : public Print void initHmac(const uint8_t* secret, int secretLength); uint8_t* result(void); uint8_t* resultHmac(void); - virtual void write(uint8_t); + #if ARDUINO >= 100 + virtual size_t write(uint8_t); + #else + virtual void write(uint8_t); + #endif using Print::write; private: void pad(); From 61c9450944e3b4c89fc9ba3aaedf99da0af24632 Mon Sep 17 00:00:00 2001 From: dybm Date: Thu, 6 Oct 2016 16:42:38 +0200 Subject: [PATCH 3/4] Updated PROGMEM vars and function 'write' 'sha256K' and 'sha256InitState' must be declared as a constant in order to be put into read-only section by means of '__attribute__((progmem))'. The virtual function 'write' in the Print class changed from returning void to returning a size_t. --- Sha/sha256.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Sha/sha256.cpp b/Sha/sha256.cpp index e479d86..e8d22b3 100644 --- a/Sha/sha256.cpp +++ b/Sha/sha256.cpp @@ -3,7 +3,7 @@ #include #include "sha256.h" -uint32_t sha256K[] PROGMEM = { +const uint32_t sha256K[] PROGMEM = { 0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5, 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174, 0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da, @@ -16,7 +16,7 @@ uint32_t sha256K[] PROGMEM = { #define BUFFER_SIZE 64 -uint8_t sha256InitState[] PROGMEM = { +const uint8_t sha256InitState[] PROGMEM = { 0x67,0xe6,0x09,0x6a, // H0 0x85,0xae,0x67,0xbb, // H1 0x72,0xf3,0x6e,0x3c, // H2 @@ -87,10 +87,18 @@ void Sha256Class::addUncounted(uint8_t data) { } } -void Sha256Class::write(uint8_t data) { +#if ARDUINO >= 100 +inline size_t Sha256Class::write(uint8_t data) { ++byteCount; addUncounted(data); + return 1; } +#else +inline void Sha256Class::write(uint8_t data) { + ++byteCount; + addUncounted(data); +} +#endif void Sha256Class::pad() { // Implement SHA-256 padding (fips180-2 §5.1.1) From 8490f1bc01372b7c6a28d920d87db50b16da33f2 Mon Sep 17 00:00:00 2001 From: dybm Date: Thu, 6 Oct 2016 16:43:30 +0200 Subject: [PATCH 4/4] Updated function 'write' The virtual function 'write' in the Print class changed from returning void to returning a size_t. --- Sha/sha256.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sha/sha256.h b/Sha/sha256.h index b4b5fd4..27b9636 100644 --- a/Sha/sha256.h +++ b/Sha/sha256.h @@ -23,7 +23,11 @@ class Sha256Class : public Print void initHmac(const uint8_t* secret, int secretLength); uint8_t* result(void); uint8_t* resultHmac(void); - virtual void write(uint8_t); + #if ARDUINO >= 100 + virtual size_t write(uint8_t); + #else + virtual void write(uint8_t); + #endif using Print::write; private: void pad();