blob: 44a9b528b48cd80f02b3d34dd49c1a7c9b430fe0 [file] [log] [blame]
Jean-Christophe PLAGNIOL-VILLARDc58a6b82008-06-07 12:29:52 +02001#ifndef _SHA256_H
2#define _SHA256_H
3
Heinrich Schuchardtbd198b32024-12-06 12:37:09 +01004#include <linux/kconfig.h>
Tom Rinidec7ea02024-05-20 13:35:03 -06005#include <linux/types.h>
6
Heinrich Schuchardtbd198b32024-12-06 12:37:09 +01007#if CONFIG_IS_ENABLED(MBEDTLS_LIB_CRYPTO)
Raymond Maoa571b982024-10-03 14:50:16 -07008/*
9 * FIXME:
10 * MbedTLS define the members of "mbedtls_sha256_context" as private,
11 * but "state" needs to be access by arch/arm/cpu/armv8/sha256_ce_glue.
12 * MBEDTLS_ALLOW_PRIVATE_ACCESS needs to be enabled to allow the external
13 * access.
14 * Directly including <external/mbedtls/library/common.h> is not allowed,
15 * since this will include <malloc.h> and break the sandbox test.
16 */
17#define MBEDTLS_ALLOW_PRIVATE_ACCESS
18
19#include <mbedtls/sha256.h>
20#endif
21
22#define SHA224_SUM_LEN 28
Jean-Christophe PLAGNIOL-VILLARDc58a6b82008-06-07 12:29:52 +020023#define SHA256_SUM_LEN 32
Andrew Duda3db9ff02016-11-08 18:53:40 +000024#define SHA256_DER_LEN 19
25
26extern const uint8_t sha256_der_prefix[];
Jean-Christophe PLAGNIOL-VILLARDc58a6b82008-06-07 12:29:52 +020027
Simon Glass0df82432012-12-05 14:46:34 +000028/* Reset watchdog each time we process this many bytes */
29#define CHUNKSZ_SHA256 (64 * 1024)
30
Heinrich Schuchardtbd198b32024-12-06 12:37:09 +010031#if CONFIG_IS_ENABLED(MBEDTLS_LIB_CRYPTO)
Raymond Maoa571b982024-10-03 14:50:16 -070032typedef mbedtls_sha256_context sha256_context;
33#else
Jean-Christophe PLAGNIOL-VILLARDc58a6b82008-06-07 12:29:52 +020034typedef struct {
35 uint32_t total[2];
36 uint32_t state[8];
37 uint8_t buffer[64];
38} sha256_context;
Raymond Maoa571b982024-10-03 14:50:16 -070039#endif
Jean-Christophe PLAGNIOL-VILLARDc58a6b82008-06-07 12:29:52 +020040
41void sha256_starts(sha256_context * ctx);
Simon Glass0df82432012-12-05 14:46:34 +000042void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length);
Jean-Christophe PLAGNIOL-VILLARDc58a6b82008-06-07 12:29:52 +020043void sha256_finish(sha256_context * ctx, uint8_t digest[SHA256_SUM_LEN]);
44
Simon Glass0df82432012-12-05 14:46:34 +000045void sha256_csum_wd(const unsigned char *input, unsigned int ilen,
46 unsigned char *output, unsigned int chunk_sz);
47
Jean-Christophe PLAGNIOL-VILLARDc58a6b82008-06-07 12:29:52 +020048#endif /* _SHA256_H */