Loading...
Searching...
No Matches
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
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
48typedef struct pico_sha256_state {
50 int8_t channel;
51 bool locked;
52 uint8_t cache_used;
53 union {
54 uint32_t word;
55 uint8_t bytes[4];
57 dma_channel_config config;
60
70
82int pico_sha256_try_start(pico_sha256_state_t *state, enum sha256_endianness endianness, bool use_dma);
83
96int pico_sha256_start_blocking_until(pico_sha256_state_t *state, enum sha256_endianness endianness, bool use_dma, absolute_time_t until);
97
109static inline int pico_sha256_start_blocking(pico_sha256_state_t *state, enum sha256_endianness endianness, bool use_dma) {
110 return pico_sha256_start_blocking_until(state, endianness, use_dma, at_the_end_of_time);
111}
112
128void pico_sha256_update(pico_sha256_state_t *state, const uint8_t *data, size_t data_size_bytes);
129
143void pico_sha256_update_blocking(pico_sha256_state_t *state, const uint8_t *data, size_t data_size_bytes);
144
155
156#ifdef __cplusplus
157}
158#endif
159
160#endif
sha256_endianness
SHA-256 endianness definition used in the API.
Definition sha256.h:49
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:147
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:177
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:39
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:65
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:151
struct pico_sha256_state pico_sha256_state_t
SHA-256 state used by the API.
void pico_sha256_cleanup(pico_sha256_state_t *state)
Release the internal lock on the SHA-256 hardware.
Definition sha256.c:33
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:109
const absolute_time_t at_the_end_of_time
The timestamp representing the end of time; this is actually not the maximum possible timestamp,...
uint64_t absolute_time_t
An opaque 64 bit timestamp in microseconds.
Definition types.h:43
SHA-256 state used by the API.
Definition sha256.h:48
size_t total_data_size
Total number of bytes added to the calculation so far.
Definition sha256.h:58
dma_channel_config config
DMA channel configuration.
Definition sha256.h:57
int8_t channel
DMA channel in use, or -1 if DMA is not being used.
Definition sha256.h:50
uint8_t bytes[4]
Cache contents as individual bytes.
Definition sha256.h:55
bool locked
Whether the SHA-256 hardware lock is currently held.
Definition sha256.h:51
uint32_t word
Cache contents as a 32-bit word.
Definition sha256.h:54
uint8_t cache_used
Number of bytes currently stored in the partial-word cache.
Definition sha256.h:52
union pico_sha256_state::@262016307016201252276264024006336042341321252243 cache
Partial-word cache for data not yet written to hardware.
enum sha256_endianness endianness
Endianness for data in and data out.
Definition sha256.h:49
SHA-256 result generated by the API.
Definition sha256.h:57