Memory optimizations in signing (#874)

* Sha256 driver cosmetics

cosmetic cleanups:
- use actual define that was used to allocate the array
- remove unused file globals

* Save memory by eliminating sha256_hash array

eliminated sha256_hash array to save memory. Instead pass the
Sha256Class result pointer.

There seems to be no use for the extra sha256_hash array as it was
zeroed exactly at the same time, the Sha256Class result was invalidated
(by calling signerSha256Init)

If the result needs to stay around while another sha is calculated,
it's better to have the user taking care of this.

* Moved hmac methods and buffers to separate class

This allows saving the buffer memory if no hmac is needed ... eg. with
the public Signing API.
This commit is contained in:
Rainer Clasen
2017-06-07 08:25:56 +02:00
committed by Patrick Fallberg
parent 29fd6d6345
commit 59337b19fe
4 changed files with 13 additions and 15 deletions
+1 -4
View File
@@ -284,12 +284,10 @@ bool signerVerifyMsg(MyMessage &msg)
return verificationResult;
}
static uint8_t sha256_hash[32];
Sha256Class _soft_sha256;
void signerSha256Init(void)
{
memset(sha256_hash, 0, 32);
_soft_sha256.init();
}
@@ -302,8 +300,7 @@ void signerSha256Update(const uint8_t* data, size_t sz)
uint8_t* signerSha256Final(void)
{
memcpy(sha256_hash, _soft_sha256.result(), 32);
return sha256_hash;
return _soft_sha256.result();
}
int signerMemcmp(const void* a, const void* b, size_t sz)