1 /** 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * 15 * Description: Provides cipher driver common utils. \n 16 * 17 * History: \n 18 * 2023-03-22, Create file. \n 19 */ 20 #ifndef CRYPTO_DRV_COMMON_H 21 #define CRYPTO_DRV_COMMON_H 22 23 #include "crypto_type.h" 24 #include "drv_common.h" 25 #include "crypto_osal_adapt.h" 26 #include "crypto_pke_struct.h" 27 #include "crypto_hash_struct.h" 28 #include "crypto_symc_struct.h" 29 30 #ifdef __cplusplus 31 #if __cplusplus 32 extern "C" { 33 #endif /* __cplusplus */ 34 #endif /* __cplusplus */ 35 36 td_void *crypto_malloc_coherent(td_u32 size); 37 38 td_void *crypto_malloc_mmz(td_u32 size); 39 40 td_void crypto_free_coherent(td_void *ptr); 41 42 td_phys_addr_t crypto_get_phys_addr(td_void *ptr); 43 44 td_bool crypto_smmu_support(td_void); 45 46 td_void crypto_get_smmu_table_addr(unsigned long *table, unsigned long *rdaddr, unsigned long *wraddr); 47 48 crypto_cpu_type crypto_get_cpu_type(td_void); 49 50 td_u32 crypto_get_pke_rom_lib_start_addr(td_void); 51 52 void crypto_cache_flush(uintptr_t base_addr, td_u32 size); 53 54 void crypto_cache_inv(uintptr_t base_addr, td_u32 size); 55 56 void crypto_cache_all(void); 57 58 td_bool crypto_ecc_support(drv_pke_ecc_curve_type curve_type); 59 60 td_bool crypto_rsa_support(td_u32 klen, drv_pke_rsa_scheme scheme); 61 62 td_bool crypto_hash_support(crypto_hash_type hash_type); 63 64 td_bool crypto_symc_support(crypto_symc_alg alg, crypto_symc_work_mode mode, crypto_symc_key_length key_len, 65 crypto_symc_bit_width bit_width); 66 67 td_s32 crypto_get_multi_random(td_u32 size, td_u8 *randnum); 68 69 typedef enum { 70 CRYPTO_SM_ALG_SM2, 71 CRYPTO_SM_ALG_SM3, 72 CRYPTO_SM_ALG_SM4 73 } crypto_sm_alg; 74 75 td_bool crypto_sm_support(crypto_sm_alg alg); 76 77 typedef enum { 78 TIMER_ID_0 = 0, 79 TIMER_ID_1, 80 TIMER_ID_2, 81 TIMER_ID_3, 82 TIMER_ID_4, 83 TIMER_ID_5, 84 TIMER_ID_6, 85 TIMER_ID_7, 86 TIMER_ID_8, 87 TIMER_ID_9, 88 } crypto_timer_id; 89 #if defined(CONFIG_CRYPTO_PERF_STATISTICS) 90 td_void crypto_timer_start(td_u32 timer_id, const td_char *name); 91 92 td_u64 crypto_timer_end(td_u32 timer_id, const td_char *item_name); 93 94 td_void crypto_timer_print(td_u32 timer_id); 95 96 td_void crypto_timer_print_all(td_void); 97 #else 98 #define crypto_timer_start(...) 99 #define crypto_timer_end(...) 100 #define crypto_timer_print(...) 101 #define crypto_timer_print_all(...) 102 #endif 103 104 typedef struct { 105 td_u32 index; 106 td_u32 value; 107 } crypto_table_item; 108 109 td_s32 crypto_get_value_by_index(const crypto_table_item *table, td_u32 table_size, 110 td_u32 index, td_u32 *value); 111 td_s32 crypto_get_index_by_value(const crypto_table_item *table, td_u32 table_size, 112 td_u32 value, td_u32 *index); 113 114 td_s32 crypto_virt_xor_phys_copy_to_phys(td_phys_addr_t dst_phys_addr, const td_u8 *a_virt_addr, 115 td_phys_addr_t b_phys_addr, td_u32 length); 116 117 td_s32 crypto_virt_copy_to_phys(td_phys_addr_t dst_phys_addr, const td_u8 *src_virt_addr, td_u32 length); 118 119 td_s32 crypto_phys_copy_to_virt(td_u8 *dst_virt_addr, td_phys_addr_t src_phys_addr, td_u32 length); 120 121 /* 122 * This two functions are used for media. 123 */ 124 td_s32 crypto_create_keyslot_handle(td_handle *keyslot_handle); 125 126 td_s32 crypto_destroy_keyslot_handle(td_handle keyslot_handle); 127 128 /* wait function mode control. */ 129 td_void crypto_wait_func_config(td_bool is_enable); 130 131 td_bool crypto_wait_func_is_support(void); 132 133 #ifdef __cplusplus 134 #if __cplusplus 135 } 136 #endif /* __cplusplus */ 137 #endif /* __cplusplus */ 138 139 #endif