Jean-Christophe PLAGNIOL-VILLARD | c58a6b8 | 2008-06-07 12:29:52 +0200 | [diff] [blame] | 1 | #ifndef _SHA256_H |
| 2 | #define _SHA256_H |
| 3 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 4 | #include <linux/types.h> |
| 5 | |
Raymond Mao | a571b98 | 2024-10-03 14:50:16 -0700 | [diff] [blame] | 6 | #if defined(CONFIG_MBEDTLS_LIB_CRYPTO) |
| 7 | /* |
| 8 | * FIXME: |
| 9 | * MbedTLS define the members of "mbedtls_sha256_context" as private, |
| 10 | * but "state" needs to be access by arch/arm/cpu/armv8/sha256_ce_glue. |
| 11 | * MBEDTLS_ALLOW_PRIVATE_ACCESS needs to be enabled to allow the external |
| 12 | * access. |
| 13 | * Directly including <external/mbedtls/library/common.h> is not allowed, |
| 14 | * since this will include <malloc.h> and break the sandbox test. |
| 15 | */ |
| 16 | #define MBEDTLS_ALLOW_PRIVATE_ACCESS |
| 17 | |
| 18 | #include <mbedtls/sha256.h> |
| 19 | #endif |
| 20 | |
| 21 | #define SHA224_SUM_LEN 28 |
Jean-Christophe PLAGNIOL-VILLARD | c58a6b8 | 2008-06-07 12:29:52 +0200 | [diff] [blame] | 22 | #define SHA256_SUM_LEN 32 |
Andrew Duda | 3db9ff0 | 2016-11-08 18:53:40 +0000 | [diff] [blame] | 23 | #define SHA256_DER_LEN 19 |
| 24 | |
| 25 | extern const uint8_t sha256_der_prefix[]; |
Jean-Christophe PLAGNIOL-VILLARD | c58a6b8 | 2008-06-07 12:29:52 +0200 | [diff] [blame] | 26 | |
Simon Glass | 0df8243 | 2012-12-05 14:46:34 +0000 | [diff] [blame] | 27 | /* Reset watchdog each time we process this many bytes */ |
| 28 | #define CHUNKSZ_SHA256 (64 * 1024) |
| 29 | |
Raymond Mao | a571b98 | 2024-10-03 14:50:16 -0700 | [diff] [blame] | 30 | #if defined(CONFIG_MBEDTLS_LIB_CRYPTO) |
| 31 | typedef mbedtls_sha256_context sha256_context; |
| 32 | #else |
Jean-Christophe PLAGNIOL-VILLARD | c58a6b8 | 2008-06-07 12:29:52 +0200 | [diff] [blame] | 33 | typedef struct { |
| 34 | uint32_t total[2]; |
| 35 | uint32_t state[8]; |
| 36 | uint8_t buffer[64]; |
| 37 | } sha256_context; |
Raymond Mao | a571b98 | 2024-10-03 14:50:16 -0700 | [diff] [blame] | 38 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | c58a6b8 | 2008-06-07 12:29:52 +0200 | [diff] [blame] | 39 | |
| 40 | void sha256_starts(sha256_context * ctx); |
Simon Glass | 0df8243 | 2012-12-05 14:46:34 +0000 | [diff] [blame] | 41 | void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length); |
Jean-Christophe PLAGNIOL-VILLARD | c58a6b8 | 2008-06-07 12:29:52 +0200 | [diff] [blame] | 42 | void sha256_finish(sha256_context * ctx, uint8_t digest[SHA256_SUM_LEN]); |
| 43 | |
Simon Glass | 0df8243 | 2012-12-05 14:46:34 +0000 | [diff] [blame] | 44 | void sha256_csum_wd(const unsigned char *input, unsigned int ilen, |
| 45 | unsigned char *output, unsigned int chunk_sz); |
| 46 | |
Jean-Christophe PLAGNIOL-VILLARD | c58a6b8 | 2008-06-07 12:29:52 +0200 | [diff] [blame] | 47 | #endif /* _SHA256_H */ |