1 /***************************************************************************//** 2 * \file cy_crypto_core_aes_v2.h 3 * \version 2.120 4 * 5 * \brief 6 * This file provides constant and parameters for the API for the AES method 7 * in the Crypto driver. 8 * 9 ******************************************************************************** 10 * \copyright 11 * Copyright (c) (2020-2022), Cypress Semiconductor Corporation (an Infineon company) or 12 * an affiliate of Cypress Semiconductor Corporation. 13 * SPDX-License-Identifier: Apache-2.0 14 * 15 * Licensed under the Apache License, Version 2.0 (the "License"); 16 * you may not use this file except in compliance with the License. 17 * You may obtain a copy of the License at 18 * 19 * http://www.apache.org/licenses/LICENSE-2.0 20 * 21 * Unless required by applicable law or agreed to in writing, software 22 * distributed under the License is distributed on an "AS IS" BASIS, 23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 * See the License for the specific language governing permissions and 25 * limitations under the License. 26 *******************************************************************************/ 27 28 29 #if !defined (CY_CRYPTO_CORE_AES_V2_H) 30 #define CY_CRYPTO_CORE_AES_V2_H 31 32 #include "cy_crypto_common.h" 33 34 #if defined(CY_IP_MXCRYPTO) && defined(CY_CRYPTO_CFG_HW_V2_ENABLE) 35 36 #if defined(__cplusplus) 37 extern "C" { 38 #endif 39 40 #if (CPUSS_CRYPTO_AES == 1) && defined(CY_CRYPTO_CFG_AES_C) 41 42 43 #if defined(CY_CRYPTO_CFG_CCM_C) 44 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ccm_Init(CRYPTO_Type *base, 45 cy_stc_crypto_aes_ccm_buffers_t * aesCcmBuffer, cy_stc_crypto_aes_ccm_state_t *aesCcmState); 46 47 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ccm_SetKey(CRYPTO_Type *base, 48 uint8_t const *key, cy_en_crypto_aes_key_length_t keyLength, 49 cy_stc_crypto_aes_ccm_state_t *aesCcmState); 50 51 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ccm_Set_Length(CRYPTO_Type *base, 52 uint32_t aadSize, uint32_t textSize, uint32_t tagLength, 53 cy_stc_crypto_aes_ccm_state_t *aesCcmState); 54 55 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ccm_Start(CRYPTO_Type *base, 56 cy_en_crypto_dir_mode_t dirMode, 57 uint32_t ivSize, uint8_t const * iv, 58 cy_stc_crypto_aes_ccm_state_t *aesCcmState); 59 60 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ccm_Update_Aad(CRYPTO_Type *base, 61 uint32_t aadSize, 62 uint8_t const *aad, 63 cy_stc_crypto_aes_ccm_state_t *aesCcmState); 64 65 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ccm_Update(CRYPTO_Type *base, 66 uint32_t srcSize, 67 uint8_t *dst, 68 uint8_t const *src, 69 cy_stc_crypto_aes_ccm_state_t *aesCcmState); 70 71 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ccm_Finish(CRYPTO_Type *base, uint8_t *tag, cy_stc_crypto_aes_ccm_state_t *aesCcmState); 72 73 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ccm_Encrypt_Tag(CRYPTO_Type *base, 74 uint32_t ivSize, uint8_t const * iv, 75 uint32_t aadSize, uint8_t const *aad, 76 uint32_t srcSize, uint8_t *cipherTxt, uint8_t const *plainTxt, 77 uint32_t tagSize, uint8_t *tag, 78 cy_stc_crypto_aes_ccm_state_t *aesCcmState); 79 80 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ccm_Decrypt(CRYPTO_Type *base, 81 uint32_t ivSize, uint8_t const * iv, 82 uint32_t aadSize, uint8_t const *aad, 83 uint32_t srcSize, uint8_t *plainTxt, uint8_t const *cipherTxt, 84 uint32_t tagSize, uint8_t const *tag, cy_en_crypto_aesccm_tag_verify_result_t *isValid, 85 cy_stc_crypto_aes_ccm_state_t *aesCcmState); 86 87 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ccm_Free(CRYPTO_Type *base, cy_stc_crypto_aes_ccm_state_t *aesCcmState); 88 89 90 #endif /* CY_CRYPTO_CFG_CCM_C*/ 91 92 #if (CPUSS_CRYPTO_GCM == 1) && defined(CY_CRYPTO_CFG_GCM_C) 93 94 /** AES GCM TAG verification status */ 95 typedef enum 96 { 97 CY_CRYPTO_TAG_VALID = 0x05555555u, 98 CY_CRYPTO_TAG_INVALID = 0x0AAAAAAAu, 99 } cy_en_crypto_aesgcm_tag_verify_result_t; 100 101 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_GCM_Init(CRYPTO_Type *base, 102 cy_stc_crypto_aes_gcm_buffers_t *aesGCMBuffers, 103 cy_stc_crypto_aes_gcm_state_t* aesGCMctx); 104 105 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_GCM_SetKey(CRYPTO_Type *base, uint8_t const *aesKey, 106 cy_en_crypto_aes_key_length_t keyLength, 107 cy_stc_crypto_aes_gcm_state_t* aesGCMctx); 108 109 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_GCM_Start(CRYPTO_Type *base, cy_en_crypto_dir_mode_t mode, 110 uint8_t const *iv, uint32_t ivSize, 111 cy_stc_crypto_aes_gcm_state_t* aesGCMctx); 112 113 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_GCM_AAD_Update(CRYPTO_Type *base, uint8_t *aad, uint32_t aadSize, 114 cy_stc_crypto_aes_gcm_state_t* aesGCMctx); 115 116 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_GCM_Update(CRYPTO_Type *base, const uint8_t *input, 117 uint32_t inputSize, uint8_t *output, 118 cy_stc_crypto_aes_gcm_state_t* aesGCMctx); 119 120 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_GCM_Finish(CRYPTO_Type *base, uint8_t *p_tag, uint32_t tagSize, cy_stc_crypto_aes_gcm_state_t* aesGCMctx); 121 122 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_GCM_Free(CRYPTO_Type *base, cy_stc_crypto_aes_gcm_state_t* aesGCMctx); 123 124 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_GCM_Encrypt_Tag(CRYPTO_Type *base, uint8_t const *aesKey, cy_en_crypto_aes_key_length_t keyLength, 125 uint8_t const *iv, uint32_t ivSize, uint8_t *aad, uint32_t aadSize, 126 const uint8_t *input, uint32_t inputSize, uint8_t *output, uint8_t *tag, uint32_t tagSize); 127 128 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_GCM_Decrypt_Tag(CRYPTO_Type *base, uint8_t const *aesKey, cy_en_crypto_aes_key_length_t keyLength, 129 uint8_t const *iv, uint32_t ivSize, uint8_t *aad, uint32_t aadSize, 130 const uint8_t *input, uint32_t inputSize, uint8_t *tag, uint32_t tagSize, uint8_t *output, cy_en_crypto_aesgcm_tag_verify_result_t * isVerified); 131 132 #endif /* (CPUSS_CRYPTO_GCM == 1) && defined(CY_CRYPTO_CFG_GCM_C)*/ 133 134 void Cy_Crypto_Core_V2_Aes_LoadEncKey(CRYPTO_Type *base, 135 cy_stc_crypto_aes_state_t const *aesState); 136 void Cy_Crypto_Core_V2_Aes_LoadDecKey(CRYPTO_Type *base, 137 cy_stc_crypto_aes_state_t const *aesState); 138 139 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Free(CRYPTO_Type *base, cy_stc_crypto_aes_state_t *aesState); 140 141 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Init(CRYPTO_Type *base, 142 uint8_t const *key, 143 cy_en_crypto_aes_key_length_t keyLength, 144 cy_stc_crypto_aes_state_t *aesState, 145 cy_stc_crypto_aes_buffers_t *aesBuffers); 146 147 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ecb(CRYPTO_Type *base, 148 cy_en_crypto_dir_mode_t dirMode, 149 uint8_t *dst, 150 uint8_t const *src, 151 cy_stc_crypto_aes_state_t *aesState); 152 153 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ecb_Setup(CRYPTO_Type *base, 154 cy_en_crypto_dir_mode_t dirMode, 155 cy_stc_crypto_aes_state_t *aesState); 156 157 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ecb_Update(CRYPTO_Type *base, 158 uint32_t srcSize, 159 uint8_t *dst, 160 uint8_t const *src, 161 cy_stc_crypto_aes_state_t *aesState); 162 163 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ecb_Finish(CRYPTO_Type *base, cy_stc_crypto_aes_state_t *aesState); 164 165 #if defined(CY_CRYPTO_CFG_CIPHER_MODE_CBC) 166 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cbc(CRYPTO_Type *base, 167 cy_en_crypto_dir_mode_t dirMode, 168 uint32_t srcSize, 169 uint8_t *ivPtr, 170 uint8_t *dst, 171 uint8_t const *src, 172 cy_stc_crypto_aes_state_t *aesState); 173 174 175 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cbc_Setup(CRYPTO_Type *base, 176 cy_en_crypto_dir_mode_t dirMode, 177 cy_stc_crypto_aes_state_t *aesState); 178 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cbc_Set_IV(CRYPTO_Type *base, 179 uint8_t const * iv, 180 cy_stc_crypto_aes_state_t *aesState); 181 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cbc_Update(CRYPTO_Type *base, 182 uint32_t srcSize, 183 uint8_t *dst, 184 uint8_t const *src, 185 cy_stc_crypto_aes_state_t *aesState); 186 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cbc_Finish(CRYPTO_Type *base, cy_stc_crypto_aes_state_t *aesState); 187 188 #if defined(CY_CRYPTO_CFG_CBC_MAC_C) 189 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_CbcMac_Setup(CRYPTO_Type *base, 190 cy_stc_crypto_aes_state_t *aesState); 191 192 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_CbcMac_Update(CRYPTO_Type *base, 193 uint32_t srcSize, 194 uint8_t const *src, 195 cy_stc_crypto_aes_state_t *aesState); 196 197 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_CbcMac_Finish(CRYPTO_Type *base, uint8_t *mac, 198 cy_stc_crypto_aes_state_t *aesState); 199 #endif /* defined(CY_CRYPTO_CFG_CBC_MAC_C) */ 200 201 202 #endif /* defined(CY_CRYPTO_CFG_CIPHER_MODE_CBC) */ 203 204 #if defined(CY_CRYPTO_CFG_CIPHER_MODE_CFB) 205 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cfb(CRYPTO_Type *base, 206 cy_en_crypto_dir_mode_t dirMode, 207 uint32_t srcSize, 208 uint8_t *ivPtr, 209 uint8_t *dst, 210 uint8_t const *src, 211 cy_stc_crypto_aes_state_t *aesState); 212 213 214 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cfb_Setup(CRYPTO_Type *base, 215 cy_en_crypto_dir_mode_t dirMode, 216 cy_stc_crypto_aes_state_t *aesState); 217 218 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cfb_Set_IV(CRYPTO_Type *base, 219 uint8_t const * iv, 220 cy_stc_crypto_aes_state_t *aesState); 221 222 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cfb_Update(CRYPTO_Type *base, 223 uint32_t srcSize, 224 uint8_t *dst, 225 uint8_t const *src, 226 cy_stc_crypto_aes_state_t *aesState); 227 228 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cfb_Finish(CRYPTO_Type *base, cy_stc_crypto_aes_state_t *aesState); 229 230 #endif /* defined(CY_CRYPTO_CFG_CIPHER_MODE_CFB) */ 231 232 #if defined(CY_CRYPTO_CFG_CIPHER_MODE_CTR) 233 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ctr(CRYPTO_Type *base, 234 uint32_t srcSize, 235 uint32_t *srcOffset, 236 uint8_t *ivPtr, 237 uint8_t *streamBlock, 238 uint8_t *dst, 239 uint8_t const *src, 240 cy_stc_crypto_aes_state_t *aesState); 241 242 243 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ctr_Setup(CRYPTO_Type *base, 244 cy_stc_crypto_aes_state_t *aesState); 245 246 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ctr_Set_IV(CRYPTO_Type *base, 247 const uint8_t *iv, 248 cy_stc_crypto_aes_state_t *aesState); 249 250 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ctr_Update(CRYPTO_Type *base, 251 uint32_t srcSize, 252 uint8_t *dst, 253 uint8_t const *src, 254 cy_stc_crypto_aes_state_t *aesState); 255 256 cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ctr_Finish(CRYPTO_Type *base, cy_stc_crypto_aes_state_t *aesState); 257 258 #endif /* defined(CY_CRYPTO_CFG_CIPHER_MODE_CTR) */ 259 260 #endif /* (CPUSS_CRYPTO_AES == 1) && defined(CY_CRYPTO_CFG_AES_C) */ 261 262 #if defined(__cplusplus) 263 } 264 #endif 265 266 #endif /* defined(CY_IP_MXCRYPTO) && defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */ 267 268 #endif /* #if !defined (CY_CRYPTO_CORE_AES_V2_H) */ 269 270 271 /* [] END OF FILE */ 272