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 * Description: hash kernel API header file. 15 * 16 * Create: 2023-05-26 17 */ 18 19 #ifndef KAPI_HASH_H 20 #define KAPI_HASH_H 21 22 #include "crypto_type.h" 23 #include "crypto_hash_struct.h" 24 #include "crypto_kdf_struct.h" 25 #include "crypto_drv_common.h" 26 27 #ifdef __cplusplus 28 #if __cplusplus 29 extern "C" { 30 #endif /* __cplusplus */ 31 #endif /* __cplusplus */ 32 33 #define KAPI_HASH_MODULE_ID 0x02 34 35 typedef struct { 36 long tid; 37 td_bool is_open; 38 td_bool is_long_term; 39 td_handle drv_hash_handle; 40 crypto_hash_clone_ctx hash_clone_ctx; 41 } crypto_kapi_hash_ctx; 42 43 typedef struct { 44 td_u32 pid; 45 crypto_owner owner; 46 crypto_kapi_hash_ctx hash_ctx_list[CRYPTO_HASH_VIRT_CHN_NUM]; 47 crypto_mutex hash_ctx_mutex[CRYPTO_HASH_VIRT_CHN_NUM]; 48 td_u32 ctx_num; 49 td_u32 init_counter; 50 td_bool is_used; 51 } crypto_kapi_hash_process; 52 53 td_s32 kapi_cipher_hash_init(td_void); 54 55 td_s32 kapi_cipher_hash_deinit(td_void); 56 57 td_s32 kapi_cipher_hash_start(td_handle *kapi_hash_handle, const crypto_hash_attr *hash_attr); 58 59 td_s32 kapi_cipher_hash_update(td_handle kapi_hash_handle, const crypto_buf_attr *src_buf, const td_u32 len); 60 61 td_s32 kapi_cipher_hash_finish(td_handle kapi_hash_handle, td_u8 *out, td_u32 *out_len); 62 63 td_s32 kapi_cipher_hash_get(td_handle kapi_hash_handle, crypto_hash_clone_ctx *hash_clone_ctx); 64 65 td_s32 kapi_cipher_hash_set(td_handle kapi_hash_handle, const crypto_hash_clone_ctx *hash_clone_ctx); 66 67 td_s32 kapi_cipher_hash_destroy(td_handle kapi_hash_handle); 68 69 td_s32 kapi_cipher_pbkdf2(const crypto_kdf_pbkdf2_param *param, td_u8 *out, const td_u32 out_len); 70 71 td_s32 kapi_cipher_hkdf_extract(crypto_hkdf_extract_t *extract_param, td_u8 *prk, td_u32 *prk_length); 72 73 td_s32 kapi_cipher_hkdf_expand(const crypto_hkdf_expand_t *expand_param, td_u8 *okm, td_u32 okm_length); 74 75 td_s32 kapi_cipher_hkdf(crypto_hkdf_t *hkdf_param, td_u8 *okm, td_u32 okm_length); 76 77 #ifdef __cplusplus 78 #if __cplusplus 79 } 80 #endif /* __cplusplus */ 81 #endif /* __cplusplus */ 82 83 #endif