1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 
4 /**
5  *****************************************************************************
6  * @file lac_sym_auth_enc.h
7  *
8  * @defgroup LacAuthEnc Authenticated Encryption
9  *
10  * @ingroup LacSym
11  *
12  * @description
13  *  Authenticated encryption specific functionality.
14  *  For CCM related code NIST SP 800-38C is followed.
15  *  For GCM related code NIST SP 800-38D is followed.
16  *
17  ***************************************************************************/
18 #ifndef LAC_SYM_AUTH_ENC_H_
19 #define LAC_SYM_AUTH_ENC_H_
20 
21 /* This define for CCM describes constant sum of n and q */
22 #define LAC_ALG_CHAIN_CCM_NQ_CONST 15
23 
24 /* These defines for CCM describe maximum and minimum
25  * length of nonce in bytes*/
26 #define LAC_ALG_CHAIN_CCM_N_LEN_IN_BYTES_MAX 13
27 #define LAC_ALG_CHAIN_CCM_N_LEN_IN_BYTES_MIN 7
28 
29 /**
30  * @ingroup LacAuthEnc
31  * This function applies any necessary padding to additional authentication data
32  * pointed by pAdditionalAuthData field of pOpData as described in
33  * NIST SP 800-38D
34  *
35  * @param[in] pSessionDesc              Pointer to the session descriptor
36  * @param[in,out] pAdditionalAuthData   Pointer to AAD
37  *
38  * @retval CPA_STATUS_SUCCESS          Operation finished successfully
39  *
40  * @pre pAdditionalAuthData has been param checked
41  *
42  */
43 void LacSymAlgChain_PrepareGCMData(lac_session_desc_t *pSessionDesc,
44 				   Cpa8U *pAdditionalAuthData);
45 
46 /**
47  * @ingroup LacAuthEnc
48  * This function prepares param checks iv and aad for CCM
49  *
50  * @param[in,out] pAdditionalAuthData   Pointer to AAD
51  * @param[in,out] pIv                   Pointer to IV
52  * @param[in] messageLenToCipherInBytes Size of the message to cipher
53  * @param[in] ivLenInBytes              Size of the IV
54  *
55  * @retval CPA_STATUS_SUCCESS          Operation finished successfully
56  * @retval CPA_STATUS_INVALID_PARAM    Invalid parameter passed
57  *
58  */
59 CpaStatus LacSymAlgChain_CheckCCMData(Cpa8U *pAdditionalAuthData,
60 				      Cpa8U *pIv,
61 				      Cpa32U messageLenToCipherInBytes,
62 				      Cpa32U ivLenInBytes);
63 
64 /**
65  * @ingroup LacAuthEnc
66  * This function prepares Ctr0 and B0-Bn blocks for CCM algorithm as described
67  * in NIST SP 800-38C. Ctr0 block is placed in pIv field of pOpData and B0-BN
68  * blocks are placed in pAdditionalAuthData.
69  *
70  * @param[in] pSessionDesc              Pointer to the session descriptor
71  * @param[in,out] pAdditionalAuthData   Pointer to AAD
72  * @param[in,out] pIv                   Pointer to IV
73  * @param[in] messageLenToCipherInBytes Size of the message to cipher
74  * @param[in] ivLenInBytes              Size of the IV
75  *
76  * @retval none
77  *
78  * @pre parameters have been checked using LacSymAlgChain_CheckCCMData()
79  */
80 void LacSymAlgChain_PrepareCCMData(lac_session_desc_t *pSessionDesc,
81 				   Cpa8U *pAdditionalAuthData,
82 				   Cpa8U *pIv,
83 				   Cpa32U messageLenToCipherInBytes,
84 				   Cpa32U ivLenInBytes);
85 
86 #endif /* LAC_SYM_AUTH_ENC_H_ */
87