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