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:
committed by
Patrick Fallberg
parent
29fd6d6345
commit
59337b19fe
@@ -19,8 +19,6 @@ const uint32_t sha256K[] PROGMEM = {
|
||||
0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
|
||||
};
|
||||
|
||||
#define BUFFER_SIZE 64
|
||||
|
||||
const uint8_t sha256InitState[] PROGMEM = {
|
||||
0x67,0xe6,0x09,0x6a, // H0
|
||||
0x85,0xae,0x67,0xbb, // H1
|
||||
@@ -110,7 +108,7 @@ void Sha256Class::addUncounted(uint8_t data)
|
||||
{
|
||||
buffer.b[bufferOffset ^ 3] = data;
|
||||
bufferOffset++;
|
||||
if (bufferOffset == BUFFER_SIZE) {
|
||||
if (bufferOffset == BLOCK_LENGTH) {
|
||||
hashBlock();
|
||||
bufferOffset = 0;
|
||||
}
|
||||
@@ -167,10 +165,7 @@ uint8_t* Sha256Class::result(void)
|
||||
#define HMAC_IPAD 0x36
|
||||
#define HMAC_OPAD 0x5c
|
||||
|
||||
uint8_t keyBuffer[BLOCK_LENGTH]; // K0 in FIPS-198a
|
||||
uint8_t innerHash[HASH_LENGTH];
|
||||
|
||||
void Sha256Class::initHmac(const uint8_t* key, int keyLength)
|
||||
void HmacClass::initHmac(const uint8_t* key, int keyLength)
|
||||
{
|
||||
uint8_t i;
|
||||
memset(keyBuffer,0,BLOCK_LENGTH);
|
||||
@@ -192,7 +187,7 @@ void Sha256Class::initHmac(const uint8_t* key, int keyLength)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* Sha256Class::resultHmac(void)
|
||||
uint8_t* HmacClass::resultHmac(void)
|
||||
{
|
||||
uint8_t i;
|
||||
// Complete inner hash
|
||||
|
||||
Reference in New Issue
Block a user