Skip to content

Commit 4bbd533

Browse files
Fix sha build issues with mbedtls 3.x (#2447)
The mbedtls methods have dropped the "_ret" from the function names in mbedtls 3.x. Use the new function names but support the old names if mbedtls 2.x is used.
1 parent 0de8847 commit 4bbd533

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/rp2_common/pico_mbedtls/pico_mbedtls.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
#include "pico.h"
99
#include "pico/rand.h"
1010
#include "mbedtls/sha256.h"
11+
#include "mbedtls/version.h"
12+
13+
#if MBEDTLS_VERSION_MAJOR < 3
14+
#define mbedtls_sha256_starts mbedtls_sha256_starts_ret
15+
#define mbedtls_sha256_update mbedtls_sha256_update_ret
16+
#define mbedtls_sha256_finish mbedtls_sha256_finish_ret
17+
#endif
1118

1219
/* Function to feed mbedtls entropy. */
1320
int mbedtls_hardware_poll(void *data __unused, unsigned char *output, size_t len, size_t *olen) {
@@ -38,17 +45,17 @@ void mbedtls_sha256_free(__unused mbedtls_sha256_context *ctx) {
3845
pico_sha256_cleanup(ctx);
3946
}
4047

41-
int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224) {
48+
int mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224) {
4249
hard_assert(!is224); // that's annoying
4350
return pico_sha256_start_blocking(ctx, SHA256_BIG_ENDIAN, PICO_MBEDTLS_SHA256_ALT_USE_DMA);
4451
}
4552

46-
int mbedtls_sha256_update_ret(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen) {
53+
int mbedtls_sha256_update(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen) {
4754
pico_sha256_update_blocking(ctx, input, ilen);
4855
return 0;
4956
}
5057

51-
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32]) {
58+
int mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32]) {
5259
sha256_result_t result;
5360
pico_sha256_finish(ctx, &result);
5461
memcpy(output, result.bytes, 32);

0 commit comments

Comments
 (0)