xref: /rk3399_ARM-atf/include/drivers/st/stm32_saes.h (revision c3170fd80b722cbd48a340a0a17f740b7676616c)
1*4bb4e836SNicolas Toromanoff /*
2*4bb4e836SNicolas Toromanoff  * Copyright (c) 2022, STMicroelectronics - All Rights Reserved
3*4bb4e836SNicolas Toromanoff  *
4*4bb4e836SNicolas Toromanoff  * SPDX-License-Identifier: BSD-3-Clause
5*4bb4e836SNicolas Toromanoff  */
6*4bb4e836SNicolas Toromanoff 
7*4bb4e836SNicolas Toromanoff #ifndef STM32_SAES_H
8*4bb4e836SNicolas Toromanoff #define STM32_SAES_H
9*4bb4e836SNicolas Toromanoff 
10*4bb4e836SNicolas Toromanoff #include <stdbool.h>
11*4bb4e836SNicolas Toromanoff #include <stddef.h>
12*4bb4e836SNicolas Toromanoff #include <stdint.h>
13*4bb4e836SNicolas Toromanoff 
14*4bb4e836SNicolas Toromanoff #define DT_SAES_COMPAT		"st,stm32-saes"
15*4bb4e836SNicolas Toromanoff 
16*4bb4e836SNicolas Toromanoff struct stm32_saes_platdata {
17*4bb4e836SNicolas Toromanoff 	uintptr_t base;
18*4bb4e836SNicolas Toromanoff 	unsigned long clock_id;
19*4bb4e836SNicolas Toromanoff 	unsigned int reset_id;
20*4bb4e836SNicolas Toromanoff };
21*4bb4e836SNicolas Toromanoff 
22*4bb4e836SNicolas Toromanoff enum stm32_saes_chaining_mode {
23*4bb4e836SNicolas Toromanoff 	STM32_SAES_MODE_ECB,
24*4bb4e836SNicolas Toromanoff 	STM32_SAES_MODE_CBC,
25*4bb4e836SNicolas Toromanoff 	STM32_SAES_MODE_CTR,
26*4bb4e836SNicolas Toromanoff 	STM32_SAES_MODE_GCM,
27*4bb4e836SNicolas Toromanoff 	STM32_SAES_MODE_CCM, /* Not use in TF-A */
28*4bb4e836SNicolas Toromanoff };
29*4bb4e836SNicolas Toromanoff 
30*4bb4e836SNicolas Toromanoff enum stm32_saes_key_selection {
31*4bb4e836SNicolas Toromanoff 	STM32_SAES_KEY_SOFT,
32*4bb4e836SNicolas Toromanoff 	STM32_SAES_KEY_DHU,           /* Derived HW unique key */
33*4bb4e836SNicolas Toromanoff 	STM32_SAES_KEY_BH,            /* Boot HW key */
34*4bb4e836SNicolas Toromanoff 	STM32_SAES_KEY_BHU_XOR_BH,    /* XOR of DHUK and BHK */
35*4bb4e836SNicolas Toromanoff 	STM32_SAES_KEY_WRAPPED
36*4bb4e836SNicolas Toromanoff };
37*4bb4e836SNicolas Toromanoff 
38*4bb4e836SNicolas Toromanoff struct stm32_saes_context {
39*4bb4e836SNicolas Toromanoff 	uintptr_t base;
40*4bb4e836SNicolas Toromanoff 	uint32_t cr;
41*4bb4e836SNicolas Toromanoff 	uint32_t assoc_len;
42*4bb4e836SNicolas Toromanoff 	uint32_t load_len;
43*4bb4e836SNicolas Toromanoff 	uint32_t key[8]; /* In HW byte order */
44*4bb4e836SNicolas Toromanoff 	uint32_t iv[4];  /* In HW byte order */
45*4bb4e836SNicolas Toromanoff };
46*4bb4e836SNicolas Toromanoff 
47*4bb4e836SNicolas Toromanoff int stm32_saes_driver_init(void);
48*4bb4e836SNicolas Toromanoff 
49*4bb4e836SNicolas Toromanoff int stm32_saes_init(struct stm32_saes_context *ctx, bool is_decrypt,
50*4bb4e836SNicolas Toromanoff 		    enum stm32_saes_chaining_mode ch_mode, enum stm32_saes_key_selection key_select,
51*4bb4e836SNicolas Toromanoff 		    const void *key, size_t key_len, const void *iv, size_t iv_len);
52*4bb4e836SNicolas Toromanoff int stm32_saes_update(struct stm32_saes_context *ctx, bool last_block,
53*4bb4e836SNicolas Toromanoff 		      uint8_t *data_in, uint8_t *data_out, size_t data_len);
54*4bb4e836SNicolas Toromanoff int stm32_saes_update_assodata(struct stm32_saes_context *ctx, bool last_block,
55*4bb4e836SNicolas Toromanoff 			       uint8_t *data, size_t data_len);
56*4bb4e836SNicolas Toromanoff int stm32_saes_update_load(struct stm32_saes_context *ctx, bool last_block,
57*4bb4e836SNicolas Toromanoff 			   uint8_t *data_in, uint8_t *data_out, size_t data_len);
58*4bb4e836SNicolas Toromanoff int stm32_saes_final(struct stm32_saes_context *ctx, uint8_t *tag, size_t tag_len);
59*4bb4e836SNicolas Toromanoff #endif
60