Skip to content

Commit 46aa5f6

Browse files
committed
RFC: calculate SHA256 using ECCx08
1 parent de6e5e8 commit 46aa5f6

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/tls/utility/SHA256.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,21 @@ constexpr size_t SHA256::HASH_SIZE;
3333

3434
void SHA256::begin()
3535
{
36-
br_sha256_init(&_ctx);
36+
spare_len = 0;
37+
ECCX08.beginSHA256();
3738
}
3839

3940
void SHA256::update(uint8_t const * data, size_t const len)
4041
{
41-
br_sha256_update(&_ctx, data, len);
42+
if (len == 64) {
43+
ECCX08.updateSHA256(data);
44+
} else {
45+
memcpy(spare_buf, data, len);
46+
spare_len = len;
47+
}
4248
}
4349

4450
void SHA256::finalize(uint8_t * hash)
4551
{
46-
br_sha256_out(&_ctx, hash);
52+
ECCX08.endSHA256(spare_buf, spare_len, hash);
4753
}

src/tls/utility/SHA256.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* INCLUDE
2323
******************************************************************************/
2424

25-
#include "../bearssl/bearssl_hash.h"
25+
#include "ArduinoECCX08.h"
2626

2727
/******************************************************************************
2828
* CLASS DECLARATION
@@ -40,9 +40,8 @@ class SHA256
4040
void finalize(uint8_t * hash);
4141

4242
private:
43-
44-
br_sha256_context _ctx;
45-
43+
uint8_t spare_buf[64];
44+
size_t spare_len = 0;
4645
};
4746

4847
#endif /* ARDUINO_TLS_UTILITY_SHA256_H_ */

0 commit comments

Comments
 (0)