7#ifndef _HARDWARE_SHA256_H
8#define _HARDWARE_SHA256_H
11#include "hardware/structs/sha256.h"
33#ifndef PARAM_ASSERTIONS_ENABLED_HARDWARE_SHA256
34#ifdef PARAM_ASSERTIONS_ENABLED_SHA256
35#define PARAM_ASSERTIONS_ENABLED_HARDWARE_SHA256 PARAM_ASSERTIONS_ENABLED_SHA256
37#define PARAM_ASSERTIONS_ENABLED_HARDWARE_SHA256 0
44#define SHA256_RESULT_BYTES 32
71 invalid_params_if(HARDWARE_SHA256, size_in_bytes != 1 && size_in_bytes != 2 && size_in_bytes != 4);
72 if (size_in_bytes == 1) {
73 val = SHA256_CSR_DMA_SIZE_VALUE_8BIT;
74 }
else if (size_in_bytes == 2) {
75 val = SHA256_CSR_DMA_SIZE_VALUE_16BIT;
77 val = SHA256_CSR_DMA_SIZE_VALUE_32BIT;
79 hw_write_masked(&sha256_hw->csr, val << SHA256_CSR_DMA_SIZE_LSB, SHA256_CSR_DMA_SIZE_BITS);
93 hw_set_bits(&sha256_hw->csr, SHA256_CSR_BSWAP_BITS);
105 hw_set_bits(&sha256_hw->csr, SHA256_CSR_START_BITS);
118 return sha256_hw->csr & SHA256_CSR_SUM_VLD_BITS;
130 return sha256_hw->csr & SHA256_CSR_WDATA_RDY_BITS;
175 return sha256_hw->csr & SHA256_CSR_ERR_WDATA_NOT_RDY_BITS;
184 hw_clear_bits(&sha256_hw->csr, SHA256_CSR_ERR_WDATA_NOT_RDY_BITS);
195 return &sha256_hw->wdata;
204 sha256_hw->wdata = word;
213 *((io_rw_8*)&sha256_hw->wdata) = b;
static __force_inline void hw_set_bits(io_rw_32 *addr, uint32_t mask)
Atomically set the specified bits to 1 in a HW register.
Definition address_mapped.h:135
static __force_inline void hw_write_masked(io_rw_32 *addr, uint32_t values, uint32_t write_mask)
Set new values for a sub-set of the bits in a HW register.
Definition address_mapped.h:171
static __force_inline void hw_clear_bits(io_rw_32 *addr, uint32_t mask)
Atomically clear the specified bits to 0 in a HW register.
Definition address_mapped.h:145
void sha256_get_result(sha256_result_t *out, enum sha256_endianness endianness)
Get the checksum result.
Definition sha256.c:9
#define SHA256_RESULT_BYTES
Size of a sha256 result in bytes.
Definition sha256.h:44
static void sha256_set_bswap(bool swap)
Enable or disable byte swapping of 32-bit values.
Definition sha256.h:91
static void sha256_start(void)
Prepare the hardware for a new checksum.
Definition sha256.h:104
static void sha256_set_dma_size(uint size_in_bytes)
Configure the correct DMA data size.
Definition sha256.h:69
static bool sha256_is_ready(void)
Check if a the hardware is ready to accept more data.
Definition sha256.h:129
static void sha256_put_word(uint32_t word)
Write one 32bit word of data to the SHA-256 hardware.
Definition sha256.h:203
static bool sha256_is_sum_valid(void)
Check if a valid checksum has been calculated.
Definition sha256.h:117
static void sha256_wait_valid_blocking(void)
Wait until the checksum is valid.
Definition sha256.h:140
static void sha256_put_byte(uint8_t b)
Write one byte of data to the SHA-256 hardware.
Definition sha256.h:212
static void sha256_wait_ready_blocking(void)
Wait until the hardware is ready to accept more data.
Definition sha256.h:152
sha256_endianness
SHA-256 endianness definition used in the API.
Definition sha256.h:49
static bool sha256_err_not_ready(void)
Check if data was written before the hardware was ready.
Definition sha256.h:174
static volatile void * sha256_get_write_addr(void)
Address to write the data to be hashed.
Definition sha256.h:194
static void sha256_err_not_ready_clear(void)
Clear the "not ready" error condition.
Definition sha256.h:183
@ SHA256_BIG_ENDIAN
Big Endian.
Definition sha256.h:51
@ SHA256_LITTLE_ENDIAN
Little Endian.
Definition sha256.h:50
SHA-256 result generated by the API.
Definition sha256.h:57