blob: b58d5b58d39e1123e52effa8c190f49cacfe0204 [file] [log] [blame]
Jean-Christophe PLAGNIOL-VILLARDc58a6b82008-06-07 12:29:52 +02001#ifndef _SHA256_H
2#define _SHA256_H
3
Tom Rinidec7ea02024-05-20 13:35:03 -06004#include <linux/types.h>
5
Raymond Maoa571b982024-10-03 14:50:16 -07006#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-VILLARDc58a6b82008-06-07 12:29:52 +020022#define SHA256_SUM_LEN 32
Andrew Duda3db9ff02016-11-08 18:53:40 +000023#define SHA256_DER_LEN 19
24
25extern const uint8_t sha256_der_prefix[];
Jean-Christophe PLAGNIOL-VILLARDc58a6b82008-06-07 12:29:52 +020026
Simon Glass0df82432012-12-05 14:46:34 +000027/* Reset watchdog each time we process this many bytes */
28#define CHUNKSZ_SHA256 (64 * 1024)
29
Raymond Maoa571b982024-10-03 14:50:16 -070030#if defined(CONFIG_MBEDTLS_LIB_CRYPTO)
31typedef mbedtls_sha256_context sha256_context;
32#else
Jean-Christophe PLAGNIOL-VILLARDc58a6b82008-06-07 12:29:52 +020033typedef struct {
34 uint32_t total[2];
35 uint32_t state[8];
36 uint8_t buffer[64];
37} sha256_context;
Raymond Maoa571b982024-10-03 14:50:16 -070038#endif
Jean-Christophe PLAGNIOL-VILLARDc58a6b82008-06-07 12:29:52 +020039
40void sha256_starts(sha256_context * ctx);
Simon Glass0df82432012-12-05 14:46:34 +000041void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length);
Jean-Christophe PLAGNIOL-VILLARDc58a6b82008-06-07 12:29:52 +020042void sha256_finish(sha256_context * ctx, uint8_t digest[SHA256_SUM_LEN]);
43
Simon Glass0df82432012-12-05 14:46:34 +000044void sha256_csum_wd(const unsigned char *input, unsigned int ilen,
45 unsigned char *output, unsigned int chunk_sz);
46
Jean-Christophe PLAGNIOL-VILLARDc58a6b82008-06-07 12:29:52 +020047#endif /* _SHA256_H */