1 /* 2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 */ 18 19 #ifndef _DRV_KLAD_H_ 20 #define _DRV_KLAD_H_ 21 22 #include "hi_cipher_compat.h" 23 24 /* Define the union klad_ctrl */ 25 typedef union { 26 struct { 27 hi_u32 start : 1; /* [0] */ 28 hi_u32 decrypt : 1; /* [1] */ 29 hi_u32 type : 2; /* [3..2] */ 30 hi_u32 high_low_128bit_flag : 1; /* [4] */ 31 hi_u32 resv1 : 11; /* [15..5] */ 32 hi_u32 klad2ci_addr : 3; /* [18..16] */ 33 hi_u32 resv2 : 13; /* [31..19] */ 34 } bits; 35 36 hi_u32 u32; 37 } klad_ctrl; 38 39 #define klad_data_in(id) (0x10 + (id) * WORD_WIDTH) 40 #define klad_data_out(id) (0x20 + (id) * WORD_WIDTH) 41 42 #define KLAD_CTRL_NOT_START 0 43 #define KLAD_CTRL_START 1 44 45 #define KLAD_HIGH_128BIT_BLOCK 1 46 #define KLAD_CTRL_LOW_128BIT_FLAG 0 47 #define KLAD_CTRL_HIGH_128BIT_FLAG 1 48 49 hi_s32 hal_cipher_klad_config(hi_u32 chn_id, hi_u32 opt_id, hi_cipher_klad_target target, hi_bool is_decrypt); 50 hi_void hal_cipher_start_klad(hi_u32 block_num); 51 hi_void hal_cipher_set_klad_data(const hi_u32 *data_in, hi_u32 data_len_in_word); 52 hi_void hal_cipher_get_klad_data(hi_u32 *data_out, hi_u32 data_len_in_word); 53 hi_s32 hal_cipher_wait_klad_done(hi_void); 54 55 hi_s32 drv_cipher_klad_init(hi_void); 56 hi_void drv_cipher_klad_deinit(hi_void); 57 58 hi_s32 drv_cipher_klad_load_key(hi_u32 chn_id, 59 hi_cipher_ca_type root_key, hi_cipher_klad_target target, const hi_u8 *data_in, hi_u32 key_len); 60 61 hi_s32 drv_cipher_klad_encrypt_key(hi_cipher_ca_type root_key, hi_cipher_klad_target target, 62 hi_u8 *clean_key, hi_u8 *encrypt_key, hi_u32 key_len); 63 64 #endif 65