v2.0.0
sha256.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _PICO_SHA256_H
8#define _PICO_SHA256_H
9
10#include "pico/time.h"
11#include "hardware/dma.h"
12#include "hardware/sha256.h"
13
41#ifdef __cplusplus
42extern "C" {
43#endif
44
48 typedef struct pico_sha256_state {
49 enum sha256_endianness endianness;
50 int8_t channel;
51 bool locked;
52 uint8_t cache_used;
53 union {
54 uint32_t word;
55 uint8_t bytes[4];
56 } cache;
57 dma_channel_config config;
58 size_t total_data_size;
59} pico_sha256_state_t;
60
72int pico_sha256_try_start(pico_sha256_state_t *state, enum sha256_endianness endianness, bool use_dma);
73
86int pico_sha256_start_blocking_until(pico_sha256_state_t *state, enum sha256_endianness endianness, bool use_dma, absolute_time_t until);
87
99 static inline int pico_sha256_start_blocking(pico_sha256_state_t *state, enum sha256_endianness endianness, bool use_dma) {
100 return pico_sha256_start_blocking_until(state, endianness, use_dma, at_the_end_of_time);
101}
102
118void pico_sha256_update(pico_sha256_state_t *state, const uint8_t *data, size_t data_size_bytes);
119
133void pico_sha256_update_blocking(pico_sha256_state_t *state, const uint8_t *data, size_t data_size_bytes);
134
144void pico_sha256_finish(pico_sha256_state_t *state, sha256_result_t *out);
145
146#ifdef __cplusplus
147}
148#endif
149
150#endif
time.h
sha256_endianness
sha256_endianness
SHA-256 endianness definition used in the API.
Definition: sha256.h:49
pico_sha256_update
void pico_sha256_update(pico_sha256_state_t *state, const uint8_t *data, size_t data_size_bytes)
Add byte data to be SHA-256 calculation.
Definition: sha256.c:137
pico_sha256_finish
void pico_sha256_finish(pico_sha256_state_t *state, sha256_result_t *out)
Finish the SHA-256 calculation and return the result.
Definition: sha256.c:167
pico_sha256_try_start
int pico_sha256_try_start(pico_sha256_state_t *state, enum sha256_endianness endianness, bool use_dma)
Start a SHA-256 calculation returning immediately with an error if the SHA-256 hardware is not availa...
Definition: sha256.c:33
pico_sha256_start_blocking_until
int pico_sha256_start_blocking_until(pico_sha256_state_t *state, enum sha256_endianness endianness, bool use_dma, absolute_time_t until)
Start a SHA-256 calculation waiting for a defined period for the SHA-256 hardware to be available.
Definition: sha256.c:59
pico_sha256_update_blocking
void pico_sha256_update_blocking(pico_sha256_state_t *state, const uint8_t *data, size_t data_size_bytes)
Add byte data to be SHA-256 calculation.
Definition: sha256.c:141
pico_sha256_state_t
struct pico_sha256_state pico_sha256_state_t
SHA-256 state used by the API.
pico_sha256_start_blocking
static int pico_sha256_start_blocking(pico_sha256_state_t *state, enum sha256_endianness endianness, bool use_dma)
Start a SHA-256 calculation, blocking forever waiting until the SHA-256 hardware is available.
Definition: sha256.h:99
absolute_time_t
uint64_t absolute_time_t
An opaque 64 bit timestamp in microseconds.
Definition: types.h:43
at_the_end_of_time
const absolute_time_t at_the_end_of_time
The timestamp representing the end of time; this is actually not the maximum possible timestamp,...
dma.h
sha256.h
dma_channel_config
Definition: dma.h:149
pico_sha256_state
SHA-256 state used by the API.
Definition: sha256.h:48
sha256_result_t
SHA-256 result generated by the API.
Definition: sha256.h:57