Skip to content

Commit 74a80d5

Browse files
manchozpennam
authored andcommitted
Use upstream ArduinoBearSSL
1 parent 4282a2f commit 74a80d5

File tree

7 files changed

+28
-25
lines changed

7 files changed

+28
-25
lines changed

examples/utility/SelfProvisioning/ECCX08Cert.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <ArduinoIoTCloud.h>
2323
#include <ArduinoECCX08.h>
2424
#include "ECCX08Cert.h"
25-
#include "tls/utility/SHA256.h"
25+
#include <SHA256.h>
2626

2727
/******************************************************************************
2828
* DEFINE
@@ -188,13 +188,14 @@ String ECCX08CertClass::endCSR() {
188188
*out++ = 0xa0;
189189
*out++ = 0x00;
190190

191-
SHA256 sha256;
192-
byte csrInfoSha256[64];
191+
SHA256Class sha256;
192+
byte csrInfoSha256[SHA256_DIGEST_SIZE];
193193
byte signature[64];
194194

195-
sha256.begin();
196-
sha256.update(csrInfo, csrInfoHeaderLen + csrInfoLen);
197-
sha256.finalize(csrInfoSha256);
195+
sha256.beginHash();
196+
sha256.write(csrInfo, csrInfoHeaderLen + csrInfoLen);
197+
sha256.endHash();
198+
sha256.readBytes(csrInfoSha256, SHA256_DIGEST_SIZE);
198199

199200
if (!ECCX08.ecSign(_keySlot, csrInfoSha256, signature)) {
200201
return "";

src/ArduinoIoTCloudTCP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ ArduinoIoTCloudTCP::ArduinoIoTCloudTCP()
8181
, _mqtt_data_len{0}
8282
, _mqtt_data_request_retransmit{false}
8383
#ifdef BOARD_HAS_ECCX08
84-
, _sslClient(nullptr, ArduinoIoTCloudTrustAnchor, ArduinoIoTCloudTrustAnchor_NUM, getTime)
84+
, _sslClient(nullptr, ArduinoIoTCloudTrustAnchor, ArduinoIoTCloudTrustAnchor_NUM)
8585
#endif
8686
#ifdef BOARD_HAS_SECRET_KEY
8787
, _password("")
@@ -171,6 +171,7 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
171171
#if defined(BOARD_HAS_OFFLOADED_ECCX08)
172172

173173
#elif defined(BOARD_HAS_ECCX08)
174+
ArduinoBearSSL.onGetTime(getTime);
174175
_sslClient.setClient(_connection->getClient());
175176
#elif defined(ARDUINO_PORTENTA_C33)
176177
_sslClient.setClient(_connection->getClient());

src/ArduinoIoTCloudTCP.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#if defined(BOARD_HAS_OFFLOADED_ECCX08)
3838
#include "WiFiSSLClient.h"
3939
#elif defined(BOARD_HAS_ECCX08)
40-
#include "tls/BearSSLClient.h"
40+
#include <ArduinoBearSSL.h>
4141
#elif defined(ARDUINO_PORTENTA_C33)
4242
#include <SSLClient.h>
4343
#elif defined(ARDUINO_NICLA_VISION)

src/utility/ota/FlashSHA256.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include "FlashSHA256.h"
2626

27-
#include "../../tls/utility/SHA256.h"
27+
#include <SHA256.h>
2828

2929
#include <Arduino_DebugUtils.h>
3030

@@ -38,11 +38,11 @@
3838

3939
String FlashSHA256::calc(uint32_t const start_addr, uint32_t const max_flash_size)
4040
{
41-
SHA256 sha256;
41+
SHA256Class sha256;
4242
uint8_t chunk [FLASH_READ_CHUNK_SIZE],
4343
next_chunk[FLASH_READ_CHUNK_SIZE];
4444

45-
sha256.begin();
45+
sha256.beginHash();
4646

4747
/* Read the first two chunks of flash. */
4848
uint32_t flash_addr = start_addr;
@@ -75,27 +75,28 @@ String FlashSHA256::calc(uint32_t const start_addr, uint32_t const max_flash_siz
7575
break;
7676
}
7777
/* Update with the remaining bytes. */
78-
sha256.update(chunk, valid_bytes_in_chunk);
78+
sha256.write(chunk, valid_bytes_in_chunk);
7979
bytes_read += valid_bytes_in_chunk;
8080
break;
8181
}
8282

8383
/* We've read a normal segment with the next segment not containing
8484
* any erased elements, just update the SHA256 hash calculation.
8585
*/
86-
sha256.update(chunk, FLASH_READ_CHUNK_SIZE);
86+
sha256.write(chunk, FLASH_READ_CHUNK_SIZE);
8787
bytes_read += FLASH_READ_CHUNK_SIZE;
8888

8989
/* Copy next_chunk to chunk. */
9090
memcpy(chunk, next_chunk, FLASH_READ_CHUNK_SIZE);
9191
}
9292

9393
/* Retrieve the final hash string. */
94-
uint8_t sha256_hash[SHA256::HASH_SIZE] = {0};
95-
sha256.finalize(sha256_hash);
94+
uint8_t sha256_hash[SHA256_DIGEST_SIZE] = {0};
95+
sha256.endHash();
96+
sha256.readBytes(sha256_hash, SHA256_DIGEST_SIZE);
9697
String sha256_str;
9798
std::for_each(sha256_hash,
98-
sha256_hash + SHA256::HASH_SIZE,
99+
sha256_hash + SHA256_DIGEST_SIZE,
99100
[&sha256_str](uint8_t const elem)
100101
{
101102
char buf[4];

src/utility/ota/OTA-esp32.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "OTA.h"
2727
#include <Arduino_DebugUtils.h>
2828
#include <Arduino_ESP32_OTA.h>
29-
#include "tls/utility/SHA256.h"
29+
#include <SHA256.h>
3030

3131
#include <esp_ota_ops.h>
3232

@@ -105,11 +105,11 @@ String esp32_getOTAImageSHA256()
105105
free(b);
106106

107107
/* Retrieve the final hash string. */
108-
uint8_t sha256_hash[SHA256::HASH_SIZE] = {0};
108+
uint8_t sha256_hash[SHA256_DIGEST_SIZE] = {0};
109109
sha256.finalize(sha256_hash);
110110
String sha256_str;
111111
std::for_each(sha256_hash,
112-
sha256_hash + SHA256::HASH_SIZE,
112+
sha256_hash + SHA256_DIGEST_SIZE,
113113
[&sha256_str](uint8_t const elem)
114114
{
115115
char buf[4];

src/utility/ota/OTA-portenta-h7.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#include <stm32h7xx_hal_rtc_ex.h>
3333

34-
#include "tls/utility/SHA256.h"
34+
#include <SHA256.h>
3535

3636
#include "../watchdog/Watchdog.h"
3737

@@ -117,11 +117,11 @@ String portenta_h7_getOTAImageSHA256()
117117
sha256.update(reinterpret_cast<uint8_t *>(&b), sizeof(b));
118118
}
119119
/* Retrieve the final hash string. */
120-
uint8_t sha256_hash[SHA256::HASH_SIZE] = {0};
120+
uint8_t sha256_hash[SHA256_DIGEST_SIZE] = {0};
121121
sha256.finalize(sha256_hash);
122122
String sha256_str;
123123
std::for_each(sha256_hash,
124-
sha256_hash + SHA256::HASH_SIZE,
124+
sha256_hash + SHA256_DIGEST_SIZE,
125125
[&sha256_str](uint8_t const elem)
126126
{
127127
char buf[4];

src/utility/ota/OTA-unor4.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#include "OTAUpdate.h"
2727
#include <Arduino_DebugUtils.h>
28-
#include "tls/utility/SHA256.h"
28+
#include <SHA256.h>
2929
#include "fsp_common_api.h"
3030
#include "r_flash_lp.h"
3131
#include "WiFiS3.h"
@@ -159,11 +159,11 @@ String unor4_getOTAImageSHA256()
159159
unor4_codeFlashClose(&ctrl);
160160

161161
/* Retrieve the final hash string. */
162-
uint8_t sha256_hash[SHA256::HASH_SIZE] = {0};
162+
uint8_t sha256_hash[SHA256_DIGEST_SIZE] = {0};
163163
sha256.finalize(sha256_hash);
164164
String sha256_str;
165165
std::for_each(sha256_hash,
166-
sha256_hash + SHA256::HASH_SIZE,
166+
sha256_hash + SHA256_DIGEST_SIZE,
167167
[&sha256_str](uint8_t const elem)
168168
{
169169
char buf[4];

0 commit comments

Comments
 (0)