1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2021, STMicroelectronics - All Rights Reserved 4 */ 5 6 #ifndef STM32_CRYP_H 7 #define STM32_CRYP_H 8 9 #include <drivers/rstctrl.h> 10 #include <kernel/mutex.h> 11 #include <mm/core_memprot.h> 12 #include <stdbool.h> 13 #include <stddef.h> 14 #include <stdint.h> 15 16 struct stm32_cryp_platdata { 17 struct io_pa_va base; 18 unsigned long clock_id; 19 struct rstctrl *reset; 20 }; 21 22 enum stm32_cryp_algo_mode { 23 STM32_CRYP_MODE_TDES_ECB, 24 STM32_CRYP_MODE_TDES_CBC, 25 STM32_CRYP_MODE_DES_ECB, 26 STM32_CRYP_MODE_DES_CBC, 27 STM32_CRYP_MODE_AES_ECB, 28 STM32_CRYP_MODE_AES_CBC, 29 STM32_CRYP_MODE_AES_CTR, 30 STM32_CRYP_MODE_AES_GCM, 31 STM32_CRYP_MODE_AES_CCM, 32 }; 33 34 /* 35 * Full CRYP context. 36 * Store CRYP internal state to be able to compute any supported algorithm. 37 */ 38 struct stm32_cryp_context { 39 vaddr_t base; 40 uint32_t cr; 41 struct mutex *lock; /* Protect CRYP HW instance access */ 42 uint32_t assoc_len; 43 uint32_t load_len; 44 uint32_t key[8]; /* In HW byte order */ 45 size_t key_size; 46 size_t block_u32; 47 uint32_t iv[4]; /* In HW byte order */ 48 uint32_t pm_gcmccm[8]; 49 union { 50 uint32_t pm_gcm[8]; 51 uint32_t ctr0_ccm[4]; 52 }; 53 uint32_t extra[4]; 54 size_t extra_size; 55 }; 56 57 TEE_Result stm32_cryp_init(struct stm32_cryp_context *ctx, bool is_decrypt, 58 enum stm32_cryp_algo_mode mode, 59 const void *key, size_t key_size, const void *iv, 60 size_t iv_size); 61 TEE_Result stm32_cryp_update(struct stm32_cryp_context *ctx, bool last_block, 62 uint8_t *data_in, uint8_t *data_out, 63 size_t data_size); 64 TEE_Result stm32_cryp_update_assodata(struct stm32_cryp_context *ctx, 65 uint8_t *data, size_t data_size); 66 TEE_Result stm32_cryp_update_load(struct stm32_cryp_context *ctx, 67 uint8_t *data_in, uint8_t *data_out, 68 size_t data_size); 69 TEE_Result stm32_cryp_final(struct stm32_cryp_context *ctx, uint8_t *tag, 70 size_t tag_size); 71 #endif 72