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
@@ -21,9 +21,7 @@ class Sha256Class
|
||||
public:
|
||||
Sha256Class(); // Constructor
|
||||
void init(void);
|
||||
void initHmac(const uint8_t* secret, int secretLength);
|
||||
uint8_t* result(void);
|
||||
uint8_t* resultHmac(void);
|
||||
void write(uint8_t);
|
||||
private:
|
||||
void pad();
|
||||
@@ -34,6 +32,14 @@ private:
|
||||
uint8_t bufferOffset;
|
||||
_state state;
|
||||
uint32_t byteCount;
|
||||
};
|
||||
|
||||
class HmacClass : public Sha256Class
|
||||
{
|
||||
public:
|
||||
void initHmac(const uint8_t* secret, int secretLength);
|
||||
uint8_t* resultHmac(void);
|
||||
private:
|
||||
uint8_t keyBuffer[BLOCK_LENGTH];
|
||||
uint8_t innerHash[HASH_LENGTH];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user