xref: /optee_os/core/drivers/crypto/stm32/stm32_hash.h (revision e880aa971c990f571fe4832de04c6cbd9cb1c65e)
1*e880aa97SNicolas Toromanoff /* SPDX-License-Identifier: BSD-2-Clause */
2*e880aa97SNicolas Toromanoff /*
3*e880aa97SNicolas Toromanoff  * Copyright (c) 2021-2025, STMicroelectronics - All Rights Reserved
4*e880aa97SNicolas Toromanoff  */
5*e880aa97SNicolas Toromanoff 
6*e880aa97SNicolas Toromanoff #ifndef STM32_HASH_H
7*e880aa97SNicolas Toromanoff #define STM32_HASH_H
8*e880aa97SNicolas Toromanoff 
9*e880aa97SNicolas Toromanoff #include <drivers/clk.h>
10*e880aa97SNicolas Toromanoff #include <drivers/rstctrl.h>
11*e880aa97SNicolas Toromanoff #include <mm/core_memprot.h>
12*e880aa97SNicolas Toromanoff #include <stdint.h>
13*e880aa97SNicolas Toromanoff 
14*e880aa97SNicolas Toromanoff /* Max size supported is SHA512 */
15*e880aa97SNicolas Toromanoff #define STM32_HASH_MAX_DIGEST_SIZE	U(64)
16*e880aa97SNicolas Toromanoff 
17*e880aa97SNicolas Toromanoff enum stm32_hash_algo {
18*e880aa97SNicolas Toromanoff 	STM32_HASH_MD5,
19*e880aa97SNicolas Toromanoff 	STM32_HASH_SHA1,
20*e880aa97SNicolas Toromanoff 	STM32_HASH_SHA224,
21*e880aa97SNicolas Toromanoff 	STM32_HASH_SHA256,
22*e880aa97SNicolas Toromanoff 	STM32_HASH_SHA384,
23*e880aa97SNicolas Toromanoff 	STM32_HASH_SHA512,
24*e880aa97SNicolas Toromanoff 	STM32_HASH_SHA3_224,
25*e880aa97SNicolas Toromanoff 	STM32_HASH_SHA3_256,
26*e880aa97SNicolas Toromanoff 	STM32_HASH_SHA3_384,
27*e880aa97SNicolas Toromanoff 	STM32_HASH_SHA3_512,
28*e880aa97SNicolas Toromanoff };
29*e880aa97SNicolas Toromanoff 
30*e880aa97SNicolas Toromanoff enum stm32_hash_mode {
31*e880aa97SNicolas Toromanoff 	STM32_HMAC_MODE,
32*e880aa97SNicolas Toromanoff 	STM32_HASH_MODE,
33*e880aa97SNicolas Toromanoff };
34*e880aa97SNicolas Toromanoff 
35*e880aa97SNicolas Toromanoff struct stm32_hash_remain {
36*e880aa97SNicolas Toromanoff 	uint32_t *buf;
37*e880aa97SNicolas Toromanoff 	size_t len;
38*e880aa97SNicolas Toromanoff };
39*e880aa97SNicolas Toromanoff 
40*e880aa97SNicolas Toromanoff struct stm32_hash_context {
41*e880aa97SNicolas Toromanoff 	struct stm32_hash_device *dev;
42*e880aa97SNicolas Toromanoff 	size_t digest_u32;
43*e880aa97SNicolas Toromanoff 	size_t block_size;
44*e880aa97SNicolas Toromanoff 	size_t queue_size;
45*e880aa97SNicolas Toromanoff 	struct stm32_hash_remain remain;
46*e880aa97SNicolas Toromanoff 	enum stm32_hash_mode mode;
47*e880aa97SNicolas Toromanoff 	enum stm32_hash_algo algo;
48*e880aa97SNicolas Toromanoff 	uint32_t save_mode;
49*e880aa97SNicolas Toromanoff 	uint32_t imr;
50*e880aa97SNicolas Toromanoff 	uint32_t str;
51*e880aa97SNicolas Toromanoff 	uint32_t cr;
52*e880aa97SNicolas Toromanoff 	uint32_t *csr;
53*e880aa97SNicolas Toromanoff };
54*e880aa97SNicolas Toromanoff 
55*e880aa97SNicolas Toromanoff size_t stm32_hash_digest_size(struct stm32_hash_context *c);
56*e880aa97SNicolas Toromanoff TEE_Result stm32_hash_deep_copy(struct stm32_hash_context *dst,
57*e880aa97SNicolas Toromanoff 				struct stm32_hash_context *src);
58*e880aa97SNicolas Toromanoff TEE_Result stm32_hash_alloc(struct stm32_hash_context *c,
59*e880aa97SNicolas Toromanoff 			    enum stm32_hash_mode mode,
60*e880aa97SNicolas Toromanoff 			    enum stm32_hash_algo algo);
61*e880aa97SNicolas Toromanoff void stm32_hash_free(struct stm32_hash_context *c);
62*e880aa97SNicolas Toromanoff TEE_Result stm32_hash_update(struct stm32_hash_context *ctx,
63*e880aa97SNicolas Toromanoff 			     const uint8_t *buffer, size_t length);
64*e880aa97SNicolas Toromanoff TEE_Result stm32_hash_final(struct stm32_hash_context *c, uint8_t *digest,
65*e880aa97SNicolas Toromanoff 			    const uint8_t *key, size_t len);
66*e880aa97SNicolas Toromanoff TEE_Result stm32_hash_init(struct stm32_hash_context *ctx, const uint8_t *key,
67*e880aa97SNicolas Toromanoff 			   size_t len);
68*e880aa97SNicolas Toromanoff #endif /* STM32_HASH_H */
69