xref: /optee_os/core/drivers/crypto/stm32/stm32_saes.h (revision b47697c078cd85dc91544d04cf0dcdf69ba3cf8c)
14320f5cfSThomas Bourgoin /* SPDX-License-Identifier: BSD-2-Clause */
24320f5cfSThomas Bourgoin /*
34320f5cfSThomas Bourgoin  * Copyright (c) 2021-2023, STMicroelectronics - All Rights Reserved
44320f5cfSThomas Bourgoin  */
54320f5cfSThomas Bourgoin 
64320f5cfSThomas Bourgoin #ifndef STM32_SAES_H
74320f5cfSThomas Bourgoin #define STM32_SAES_H
84320f5cfSThomas Bourgoin 
94320f5cfSThomas Bourgoin #include <drivers/clk.h>
104320f5cfSThomas Bourgoin #include <drivers/rstctrl.h>
114320f5cfSThomas Bourgoin #include <kernel/mutex.h>
124320f5cfSThomas Bourgoin #include <stdbool.h>
134320f5cfSThomas Bourgoin #include <stddef.h>
144320f5cfSThomas Bourgoin #include <stdint.h>
154320f5cfSThomas Bourgoin #include <tee_api_defines.h>
164320f5cfSThomas Bourgoin 
174320f5cfSThomas Bourgoin enum stm32_saes_chaining_mode {
184320f5cfSThomas Bourgoin 	STM32_SAES_MODE_ECB,
194320f5cfSThomas Bourgoin 	STM32_SAES_MODE_CBC,
204320f5cfSThomas Bourgoin 	STM32_SAES_MODE_CTR,
214320f5cfSThomas Bourgoin 	STM32_SAES_MODE_GCM,
224320f5cfSThomas Bourgoin 	STM32_SAES_MODE_CCM,
234320f5cfSThomas Bourgoin };
244320f5cfSThomas Bourgoin 
254320f5cfSThomas Bourgoin enum stm32_saes_key_selection {
264320f5cfSThomas Bourgoin 	STM32_SAES_KEY_SOFT,
274320f5cfSThomas Bourgoin 	STM32_SAES_KEY_DHU,           /* Derived HW unique key */
284320f5cfSThomas Bourgoin 	STM32_SAES_KEY_BH,            /* Boot HW key */
294320f5cfSThomas Bourgoin 	STM32_SAES_KEY_BHU_XOR_BH,    /* XOR of DHUK and BHK */
304320f5cfSThomas Bourgoin 	STM32_SAES_KEY_WRAPPED
314320f5cfSThomas Bourgoin };
324320f5cfSThomas Bourgoin 
334320f5cfSThomas Bourgoin struct stm32_saes_context {
344320f5cfSThomas Bourgoin 	vaddr_t base;
354320f5cfSThomas Bourgoin 	uint32_t cr;
364320f5cfSThomas Bourgoin 	struct mutex *lock;	/* Save the HW instance mutex */
374320f5cfSThomas Bourgoin 	uint32_t assoc_len;
384320f5cfSThomas Bourgoin 	uint32_t load_len;
394320f5cfSThomas Bourgoin 	uint32_t key[8]; /* In HW byte order */
404320f5cfSThomas Bourgoin 	uint32_t iv[4];  /* In HW byte order */
414320f5cfSThomas Bourgoin 	uint32_t susp[8];
424320f5cfSThomas Bourgoin 	uint32_t extra[4];
434320f5cfSThomas Bourgoin 	size_t extra_size;
444320f5cfSThomas Bourgoin };
454320f5cfSThomas Bourgoin 
464320f5cfSThomas Bourgoin TEE_Result stm32_saes_init(struct stm32_saes_context *ctx, bool is_decrypt,
474320f5cfSThomas Bourgoin 			   enum stm32_saes_chaining_mode ch_mode,
484320f5cfSThomas Bourgoin 			   enum stm32_saes_key_selection key_select,
494320f5cfSThomas Bourgoin 			   const void *key, size_t key_len, const void *iv,
504320f5cfSThomas Bourgoin 			   size_t iv_len);
514320f5cfSThomas Bourgoin TEE_Result stm32_saes_update(struct stm32_saes_context *ctx, bool last_block,
524320f5cfSThomas Bourgoin 			     uint8_t *data_in, uint8_t *data_out,
534320f5cfSThomas Bourgoin 			     size_t data_len);
544320f5cfSThomas Bourgoin TEE_Result stm32_saes_update_assodata(struct stm32_saes_context *ctx,
554320f5cfSThomas Bourgoin 				      uint8_t *data, size_t data_len);
564320f5cfSThomas Bourgoin TEE_Result stm32_saes_update_load(struct stm32_saes_context *ctx,
574320f5cfSThomas Bourgoin 				  bool last_block, uint8_t *data_in,
584320f5cfSThomas Bourgoin 				  uint8_t *data_out, size_t data_len);
594320f5cfSThomas Bourgoin TEE_Result stm32_saes_final(struct stm32_saes_context *ctx, uint8_t *tag,
604320f5cfSThomas Bourgoin 			    size_t tag_len);
61*b47697c0SThomas Bourgoin 
62*b47697c0SThomas Bourgoin TEE_Result stm32_saes_kdf(struct stm32_saes_context *ctx,
63*b47697c0SThomas Bourgoin 			  enum stm32_saes_key_selection key_sel,
64*b47697c0SThomas Bourgoin 			  const void *key, size_t key_size,
65*b47697c0SThomas Bourgoin 			  const void *input, size_t input_size,
66*b47697c0SThomas Bourgoin 			  uint8_t *subkey, size_t subkey_size);
67*b47697c0SThomas Bourgoin 
684320f5cfSThomas Bourgoin #endif
69