Skip to content

Commit 13fbaf5

Browse files
committed
Restore SHA256 via bearSSL
Loses 2KB of flash compared with 46aa5f6 but it's surely faster
1 parent 0273c3a commit 13fbaf5

File tree

5 files changed

+10
-15
lines changed

5 files changed

+10
-15
lines changed

src/tls/bearssl/dec32be.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
#include <AIoTC_Config.h>
26-
#ifdef BOARD_HAS_ECCX08
26+
#if defined(BOARD_HAS_ECCX08) || defined(BOARD_HAS_OFFLOADED_ECCX08)
2727

2828
#include "inner.h"
2929

src/tls/bearssl/enc32be.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
#include <AIoTC_Config.h>
26-
#ifdef BOARD_HAS_ECCX08
26+
#if defined(BOARD_HAS_ECCX08) || defined(BOARD_HAS_OFFLOADED_ECCX08)
2727

2828
#include "inner.h"
2929

src/tls/bearssl/sha2small.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
#include <AIoTC_Config.h>
26-
#ifdef BOARD_HAS_ECCX08
26+
#if defined(BOARD_HAS_ECCX08) || defined(BOARD_HAS_OFFLOADED_ECCX08)
2727

2828
#include "inner.h"
2929

src/tls/utility/SHA256.cpp

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

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

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

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

src/tls/utility/SHA256.h

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

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

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

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

4748
#endif /* ARDUINO_TLS_UTILITY_SHA256_H_ */

0 commit comments

Comments
 (0)