1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2021-2023, STMicroelectronics - All Rights Reserved 4 */ 5 6 #ifndef STM32_SAES_H 7 #define STM32_SAES_H 8 9 #include <drivers/clk.h> 10 #include <drivers/rstctrl.h> 11 #include <kernel/mutex.h> 12 #include <stdbool.h> 13 #include <stddef.h> 14 #include <stdint.h> 15 #include <tee_api_defines.h> 16 17 enum stm32_saes_chaining_mode { 18 STM32_SAES_MODE_ECB, 19 STM32_SAES_MODE_CBC, 20 STM32_SAES_MODE_CTR, 21 STM32_SAES_MODE_GCM, 22 STM32_SAES_MODE_CCM, 23 }; 24 25 enum stm32_saes_key_selection { 26 STM32_SAES_KEY_SOFT, 27 STM32_SAES_KEY_DHU, /* Derived HW unique key */ 28 STM32_SAES_KEY_BH, /* Boot HW key */ 29 STM32_SAES_KEY_BHU_XOR_BH, /* XOR of DHUK and BHK */ 30 STM32_SAES_KEY_WRAPPED 31 }; 32 33 struct stm32_saes_context { 34 vaddr_t base; 35 uint32_t cr; 36 struct mutex *lock; /* Save the HW instance mutex */ 37 uint32_t assoc_len; 38 uint32_t load_len; 39 uint32_t key[8]; /* In HW byte order */ 40 uint32_t iv[4]; /* In HW byte order */ 41 uint32_t susp[8]; 42 uint32_t extra[4]; 43 size_t extra_size; 44 }; 45 46 TEE_Result stm32_saes_init(struct stm32_saes_context *ctx, bool is_decrypt, 47 enum stm32_saes_chaining_mode ch_mode, 48 enum stm32_saes_key_selection key_select, 49 const void *key, size_t key_len, const void *iv, 50 size_t iv_len); 51 TEE_Result stm32_saes_update(struct stm32_saes_context *ctx, bool last_block, 52 uint8_t *data_in, uint8_t *data_out, 53 size_t data_len); 54 TEE_Result stm32_saes_update_assodata(struct stm32_saes_context *ctx, 55 uint8_t *data, size_t data_len); 56 TEE_Result stm32_saes_update_load(struct stm32_saes_context *ctx, 57 bool last_block, uint8_t *data_in, 58 uint8_t *data_out, size_t data_len); 59 TEE_Result stm32_saes_final(struct stm32_saes_context *ctx, uint8_t *tag, 60 size_t tag_len); 61 62 TEE_Result stm32_saes_kdf(struct stm32_saes_context *ctx, 63 enum stm32_saes_key_selection key_sel, 64 const void *key, size_t key_size, 65 const void *input, size_t input_size, 66 uint8_t *subkey, size_t subkey_size); 67 68 #endif 69