1 /* 2 * Copyright (c) 2001-2022, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 8 #ifndef _AESGCM_DRIVER_H 9 #define _AESGCM_DRIVER_H 10 11 #include "mbedtls/build_info.h" 12 13 /* 14 * All the includes that are needed for code using this file to 15 * compile correctly should be #included here. 16 */ 17 #include "driver_defs.h" 18 #include "cc_aes_defs.h" 19 #include "cc_pal_types.h" 20 #include "cc_bitops.h" 21 22 #ifdef __cplusplus 23 extern "C" 24 { 25 #endif 26 27 /************************ Defines ******************************/ 28 29 /* 128 bits */ 30 #define CC_AESGCM_GHASH_DIGEST_SIZE_BYTES 16 31 #define CC_AESGCM_GHASH_DIGEST_SIZE_WORDS CC_AESGCM_GHASH_DIGEST_SIZE_BYTES>>2 32 33 /************************ Enums ********************************/ 34 35 /*! AES GCM driver process modes. */ 36 typedef enum { 37 /*! Calculate H. */ 38 DRV_AESGCM_Process_CalcH = 0, 39 /*! Calculate J0 - First phase. */ 40 DRV_AESGCM_Process_CalcJ0_FirstPhase = 1, 41 /*! Calculate J0 - Second phase. */ 42 DRV_AESGCM_Process_CalcJ0_SecondPhase = 2, 43 /*! GHASH AAD. */ 44 DRV_AESGCM_Process_A = 3, 45 /*! GCTR and GHASH Data In. */ 46 DRV_AESGCM_Process_DataIn = 4, 47 /*! GHASH Len(A) || Len(C). */ 48 DRV_AESGCM_Process_LenA_LenC = 5, 49 /*! GCTR Final. */ 50 DRV_AESGCM_Process_GctrFinal = 6, 51 52 /*! Number of optional key sizes. */ 53 DRV_AESGCM_ProcessesTotal, 54 /*! Reserved. */ 55 DRV_AESGCM_ProcessLast = 0x7FFFFFFF, 56 }drvAesGcmProcessModes_t; 57 58 59 /************************ Typedefs ****************************/ 60 61 /* NOTE: make sure that structure size equals to CC_AESGCM_USER_CTX_SIZE_IN_WORDS */ 62 typedef struct AesGcmContext_t { 63 /* AES max key size supported is 256 bit */ 64 uint32_t keyBuf[AES_256_BIT_KEY_SIZE_WORDS]; 65 /* H buffer size is 128 bit */ 66 uint32_t H[AES_128_BIT_KEY_SIZE_WORDS]; 67 /* J0 buffer size is 128 bit */ 68 uint32_t J0[CC_AESGCM_GHASH_DIGEST_SIZE_WORDS]; 69 /* Temp. buffer size is 128 bit */ 70 uint32_t tempBuf[CC_AESGCM_GHASH_DIGEST_SIZE_WORDS]; 71 /* AES Counter buffer size is 128 bit */ 72 uint32_t aesCntrBuf[CC_AESGCM_GHASH_DIGEST_SIZE_WORDS]; 73 /* GHASH Result buffer size is 128 bit */ 74 uint32_t ghashResBuf[CC_AESGCM_GHASH_DIGEST_SIZE_WORDS]; 75 /* Pre-Tag buffer size is 128 bit */ 76 uint8_t preTagBuf[CC_AESGCM_GHASH_DIGEST_SIZE_BYTES]; 77 /* J0 Inc32 flag */ 78 CCBool J0Inc32DoneFlg; 79 /* keySize: 128, 192, 256 */ 80 keySizeId_t keySizeId; 81 /* Encrypt / Decrypt */ 82 cryptoDirection_t dir; 83 /* Tag size */ 84 uint8_t tagSize; 85 /* Alignment */ 86 uint8_t RFU[3]; 87 /* Driver process mode */ 88 drvAesGcmProcessModes_t processMode; 89 /* Data size (Plain/Cipher text) */ 90 uint32_t dataSize; 91 /* IV size */ 92 uint32_t ivSize; 93 /* AAD size */ 94 uint32_t aadSize; 95 }AesGcmContext_t; 96 97 98 /****************************************************************************** 99 * FUNCTION PROTOTYPES 100 ******************************************************************************/ 101 102 /*! 103 * This function is used to process block of data using the AES and / or Hash machines. 104 * 105 * \param pAesGcmCtx A pointer to the AES-GCM context buffer. 106 * \param pInputBuffInfo A structure which represents the data input buffer. 107 * \param pOutputBuffInfo A structure which represents the data output buffer. 108 * \param blockSize - number of bytes to copy. 109 * 110 * \return drvError_t defined in driver_defs.h. 111 */ 112 drvError_t ProcessAesGcm(AesGcmContext_t *pAesGcmCtx, CCBuffInfo_t *pInputBuffInfo, CCBuffInfo_t *pOutputBuffInfo, uint32_t blockSize); 113 114 #ifdef __cplusplus 115 } 116 #endif 117 118 #endif // _AESGCM_DRIVER_H 119