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