1
6
7
13
14
24
25
26
27
28
29
30
31
32
33
34
35
37
38
40
41
45
46
50
51
57
/* ... */
#include <string.h>
#include "pico.h"
#include "pico/rand.h"
#include "mbedtls/sha256.h"
#include "common.h"
5 includes
int mbedtls_hardware_poll(void *data __unused, unsigned char *output, size_t len, size_t *olen) {
*olen = 0;
while(*olen < len) {
uint64_t rand_data = get_rand_64();
size_t to_copy = MIN(len, sizeof(rand_data));
memcpy(output + *olen, &rand_data, to_copy);
*olen += to_copy;
}while (*olen < len) { ... }
return 0;
}{ ... }
#ifdef MBEDTLS_SHA256_ALT
#if !LIB_PICO_SHA256
#error SHA256 hardware acceleration not supported
#endif
#ifndef PICO_MBEDTLS_SHA256_ALT_USE_DMA
#define PICO_MBEDTLS_SHA256_ALT_USE_DMA 1
#endif
void mbedtls_sha256_init(__unused mbedtls_sha256_context *ctx) {
}mbedtls_sha256_init (__unused mbedtls_sha256_context *ctx) { ... }
void mbedtls_sha256_free(__unused mbedtls_sha256_context *ctx) {
}mbedtls_sha256_free (__unused mbedtls_sha256_context *ctx) { ... }
int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224) {
hard_assert(!is224);
return pico_sha256_start_blocking(ctx, SHA256_BIG_ENDIAN, PICO_MBEDTLS_SHA256_ALT_USE_DMA);
}mbedtls_sha256_starts_ret (mbedtls_sha256_context *ctx, int is224) { ... }
int mbedtls_sha256_update_ret(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen) {
pico_sha256_update_blocking(ctx, input, ilen);
return 0;
}mbedtls_sha256_update_ret (mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen) { ... }
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32]) {
sha256_result_t result;
pico_sha256_finish(ctx, &result);
memcpy(output, result.bytes, 32);
return 0;
}mbedtls_sha256_finish_ret (mbedtls_sha256_context *ctx, unsigned char output[32]) { ... }
/* ... */#endif