1 /* 2 * Copyright (C) 2017-2024 Alibaba Group Holding Limited 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 /****************************************************************************** 19 * @file drv/hmac.h 20 * @brief Header File for HMAC 21 * @version V1.0 22 * @date 27. Apri 2023 23 * @model hmac 24 ******************************************************************************/ 25 #ifndef _DRV_HMAC_H_ 26 #define _DRV_HMAC_H_ 27 28 #include <drv/common.h> 29 #include <drv/dma.h> 30 #include <drv/sha.h> 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 /****** HMAC Event ******/ 37 typedef enum { 38 HMAC_EVENT_COMPLETE = 0U, /* Calculate completed */ 39 HMAC_EVENT_ERROR /* Calculate error */ 40 } csi_hmac_event_t; 41 42 /****** HMAC Context ******/ 43 typedef struct { 44 csi_sha_mode_t mode; /* SHA mode */ 45 uint32_t total[2]; /* Number of bytes processed */ 46 uint8_t buffer[128]; /* Data block being processed */ 47 } csi_hmac_context_t; 48 49 /****** HMAC Ctrl ******/ 50 typedef struct csi_hmac { 51 csi_dev_t dev; 52 void *priv; 53 }csi_hmac_t; 54 55 /** 56 \brief Initialize MAC Interface. Initializes the resources needed for the MAC interface 57 \param[in] mac operate handle. 58 \param[in] idx index of mac 59 \return error code \ref csi_error_t 60 */ 61 csi_error_t csi_hmac_init(csi_hmac_t *mac, uint32_t idx); 62 63 /** 64 \brief De-initialize MAC Interface. stops operation and releases the software resources used by the interface 65 \param[in] mac mac handle to operate. 66 \return none 67 */ 68 void csi_hmac_uninit(csi_hmac_t *mac); 69 70 /** 71 \brief MAC set key function. 72 \param[in] mac mac handle to operate. 73 \param[in] key Pointer to the mac key. 74 \param[in] key_len Length of key. 75 \return error code \ref csi_error_t 76 */ 77 csi_error_t csi_hmac_set_key(csi_hmac_t *mac, uint8_t *key, uint32_t key_len); 78 79 /** 80 \brief MAC start operation function. 81 \param[in] mac mac handle to operate. 82 \param[in] context mac context pointer. 83 \param[in] mode sc_sha_mode_t. 84 \return error code \ref csi_error_t 85 */ 86 csi_error_t csi_hmac_start(csi_hmac_t *mac, csi_hmac_context_t *context, csi_sha_mode_t mode); 87 88 /** 89 \brief MAC start operation function. 90 \param[in] mac mac handle to operate. 91 \param[in] msg Pointer to the mac input message. 92 \param[in] msg_len Length of msg. 93 \return error code \ref csi_error_t 94 */ 95 csi_error_t csi_hmac_update(csi_hmac_t *mac, csi_hmac_context_t *context, uint8_t *msg, uint32_t msg_len); 96 97 /** 98 \brief MAC start operation function. 99 \param[in] mac mac handle to operate. 100 \param[out] out mac buffer, malloc by caller. 101 \param[out] out_len out mac length, 102 \return error code \ref csi_error_t 103 */ 104 csi_error_t csi_hmac_finish(csi_hmac_t *mac, csi_hmac_context_t *context, uint8_t *out, uint32_t *out_len); 105 106 /** 107 \brief MAC cacl operation function. 108 \param[in] mac mac handle to operate. 109 \param[in] mode sc_sha_mode_t. 110 \param[in] msg Pointer to the mac input message. 111 \param[in] msg_len Length of msg. 112 \param[out] out mac buffer, malloc by caller. 113 \param[out] out_len out mac length, 114 \return error code \ref csi_error_t 115 */ 116 csi_error_t csi_hmac_calc(csi_hmac_t *mac, csi_sha_mode_t mode, uint8_t *msg, 117 uint32_t msg_len, uint8_t *out, uint32_t *out_len); 118 #ifdef __cplusplus 119 } 120 #endif 121 122 #endif /* _SC_MAC_H_ */ 123