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/clk.h> 10 #include <drivers/rstctrl.h> 11 #include <kernel/mutex.h> 12 #include <mm/core_memprot.h> 13 #include <stdbool.h> 14 #include <stddef.h> 15 #include <stdint.h> 16 17 /* 18 * Platform data related to CRYP instance 19 * @base - IO memory base address 20 * @clk - CRYP clock reference 21 * @rstctrl - CRYP reset controller reference 22 */ 23 struct stm32_cryp_platdata { 24 struct io_pa_va base; 25 struct clk *clock; 26 struct rstctrl *reset; 27 }; 28 29 enum stm32_cryp_algo_mode { 30 STM32_CRYP_MODE_TDES_ECB, 31 STM32_CRYP_MODE_TDES_CBC, 32 STM32_CRYP_MODE_DES_ECB, 33 STM32_CRYP_MODE_DES_CBC, 34 STM32_CRYP_MODE_AES_ECB, 35 STM32_CRYP_MODE_AES_CBC, 36 STM32_CRYP_MODE_AES_CTR, 37 STM32_CRYP_MODE_AES_GCM, 38 STM32_CRYP_MODE_AES_CCM, 39 }; 40 41 /* 42 * Full CRYP context. 43 * Store CRYP internal state to be able to compute any supported algorithm. 44 */ 45 struct stm32_cryp_context { 46 vaddr_t base; 47 uint32_t cr; 48 struct mutex *lock; /* Protect CRYP HW instance access */ 49 uint32_t assoc_len; 50 uint32_t load_len; 51 uint32_t key[8]; /* In HW byte order */ 52 size_t key_size; 53 size_t block_u32; 54 uint32_t iv[4]; /* In HW byte order */ 55 uint32_t pm_gcmccm[8]; 56 union { 57 uint32_t pm_gcm[8]; 58 uint32_t ctr0_ccm[4]; 59 }; 60 uint32_t extra[4]; 61 size_t extra_size; 62 }; 63 64 TEE_Result stm32_cryp_init(struct stm32_cryp_context *ctx, bool is_decrypt, 65 enum stm32_cryp_algo_mode mode, 66 const void *key, size_t key_size, const void *iv, 67 size_t iv_size); 68 TEE_Result stm32_cryp_update(struct stm32_cryp_context *ctx, bool last_block, 69 uint8_t *data_in, uint8_t *data_out, 70 size_t data_size); 71 TEE_Result stm32_cryp_update_assodata(struct stm32_cryp_context *ctx, 72 uint8_t *data, size_t data_size); 73 TEE_Result stm32_cryp_update_load(struct stm32_cryp_context *ctx, 74 uint8_t *data_in, uint8_t *data_out, 75 size_t data_size); 76 TEE_Result stm32_cryp_final(struct stm32_cryp_context *ctx, uint8_t *tag, 77 size_t tag_size); 78 #endif 79