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 mac driver header \n 16 * 17 * History: \n 18 * 2024-01-24, Create file. \n 19 */ 20 #ifndef CIPHER_MAC_H 21 #define CIPHER_MAC_H 22 23 #include <stdint.h> 24 #include <stdbool.h> 25 #include "errcode.h" 26 27 #ifdef __cplusplus 28 #if __cplusplus 29 extern "C" { 30 #endif 31 #endif 32 33 /** 34 * @defgroup security_unified_cipher_mac Cipher MAC 35 * @ingroup drivers_driver_security_unified 36 * @{ 37 */ 38 39 /** 40 * @if Eng 41 * @brief AES-CMAC compute MAC. 42 * @param [in] data Data of the MAC value to be calculated. 43 * @param [in] data_len Data length, in bytes. 44 * @param [in] key Decryption key. 45 * @param [in] key_len Decryption key length in byte. Only support 16,24,32. 46 * @param [in] keyslot_handle The keyslot handle which store the decryption key. 47 * @param [out] out_mac Stores the calculated MAC value. The capacity is 16 bytes. 48 * @retval ERRCODE_SUCC Success. 49 * @retval Other Failure. For details, see @ref errcode_t 50 * @note There are two methods to set the key: 51 1)Using key/key_len, in which case, the keyslot_handle is set to 0. 52 2) Calling keyslot api to create one keyslot_handle and set it, in which case, 53 the key is set to NULL and key_len is 0. 54 When keyslot is supported, you must use method 2, otherwise you should use method 1. 55 * @else 56 * @brief AES-CMAC 计算 MAC 值. 57 * @param [in] data 待计算 MAC 值的数据. 58 * @param [in] data_len 数据长度,单位是 Byte. 59 * @param [in] key 解密密钥. 60 * @param [in] key_len 解密密钥长度,单位是 Byte. 只支持 16,24,32. 61 * @param [in] keyslot_handle 保存解密密钥的 keyslot 句柄. 62 * @param [out] out_mac 保存计算的 MAC 值,容量为 16 字节. 63 * @retval ERRCODE_SUCC 成功。 64 * @retval Other 失败,参考 @ref errcode_t 。 65 * @note 有两种方法设置密钥: 66 1)使用 key/key_len 组合,在这种情况下,keyslot_handle 传入 0. 67 2)使用 keyslot 接口创建 keyslot 句柄传入,在这种情况下,key 传入为 NULL,key_len 传入为 0. 68 若支持 keyslot,则必须使用方法2,否则只能使用方法1. 69 * @endif 70 */ 71 errcode_t uapi_drv_cipher_symc_aes_cmac(const uint8_t *data, uint32_t data_len, 72 const uint8_t *key, uint32_t key_len, uint32_t keyslot_handle, 73 uint8_t out_mac[16]); 74 75 /** 76 * @} 77 */ 78 79 #ifdef __cplusplus 80 #if __cplusplus 81 } 82 #endif 83 #endif 84 85 #endif 86