Skip to content

Commit e208401

Browse files
committed
SHA256: allow build if board uses mbedtls
1 parent 7aad6c5 commit e208401

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/tls/utility/SHA256.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,28 @@ constexpr size_t SHA256::HASH_SIZE;
3333

3434
void SHA256::begin()
3535
{
36+
#if defined(HAS_BEARSSL)
3637
br_sha256_init(&_ctx);
38+
#else
39+
mbedtls_sha256_init(&_ctx);
40+
mbedtls_sha256_starts(&_ctx, 0);
41+
#endif
3742
}
3843

3944
void SHA256::update(uint8_t const * data, size_t const len)
4045
{
46+
#if defined(HAS_BEARSSL)
4147
br_sha256_update(&_ctx, data, len);
48+
#else
49+
mbedtls_sha256_update(&_ctx, data, len);
50+
#endif
4251
}
4352

4453
void SHA256::finalize(uint8_t * hash)
4554
{
55+
#if defined(HAS_BEARSSL)
4656
br_sha256_out(&_ctx, hash);
57+
#else
58+
mbedtls_sha256_finish(&_ctx, hash);
59+
#endif
4760
}

src/tls/utility/SHA256.h

+16-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,19 @@
2121
/******************************************************************************
2222
* INCLUDE
2323
******************************************************************************/
24+
#include <AIoTC_Config.h>
2425

25-
#include "../bearssl/bearssl_hash.h"
26+
#if defined(BOARD_HAS_OFFLOADED_ECCX08) || defined(BOARD_HAS_ECCX08)
27+
#define HAS_BEARSSL
28+
#else
29+
#define HAS_MBEDTLS
30+
#endif
31+
32+
#if defined(HAS_BEARSSL)
33+
#include <bearssl/bearssl_hash.h>
34+
#else
35+
#include <mbedtls/sha256.h>
36+
#endif
2637

2738
/******************************************************************************
2839
* CLASS DECLARATION
@@ -41,7 +52,11 @@ class SHA256
4152

4253
private:
4354

55+
#if defined(HAS_BEARSSL)
4456
br_sha256_context _ctx;
57+
#else
58+
mbedtls_sha256_context _ctx;
59+
#endif
4560

4661
};
4762

0 commit comments

Comments
 (0)