1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 
4 /**
5  ***************************************************************************
6  * @file lac_sym_hash_precomputes.h
7  *
8  * @defgroup LacHashDefs Hash Definitions
9  *
10  * @ingroup  LacHash
11  *
12  * Constants for hash algorithms
13  *
14  ***************************************************************************/
15 #ifndef LAC_SYM_HASH_PRECOMPUTES_H
16 #define LAC_SYM_HASH_PRECOMPUTES_H
17 
18 #include "lac_sym_hash.h"
19 
20 #define LAC_SYM_AES_CMAC_RB_128 0x87 /* constant used for   */
21 				     /* CMAC calculation    */
22 
23 #define LAC_SYM_HASH_MSBIT_MASK 0x80 /* Mask to check MSB top bit */
24 				     /* zero or one */
25 
26 #define LAC_SINGLE_BUFFER_HW_META_SIZE                                         \
27 	(sizeof(icp_buffer_list_desc_t) + sizeof(icp_flat_buffer_desc_t))
28 /**< size of memory to allocate for the HW buffer list that is sent to the
29  * QAT */
30 
31 #define LAC_SYM_HASH_PRECOMP_MAX_WORKING_BUFFER                                \
32 	((sizeof(lac_sym_hash_precomp_op_data_t) * 2) +                        \
33 	 sizeof(lac_sym_hash_precomp_op_t))
34 /**< maximum size of the working data for the HMAC precompute operations
35  *
36  * Maximum size of lac_sym_hash_precomp_op_data_t is 264 bytes. For hash
37  * precomputes there are 2 of these structrues and a further
38  * lac_sym_hash_precomp_op_t structure required. This comes to a total of 536
39  * bytes.
40  * For the asynchronous version of the precomputes, the memory for the hash
41  * state prefix buffer is used as the working memory. There are 584 bytes
42  * which are alloacted for the hash state prefix buffer which is enough to
43  * carve up for the precomputes.
44  */
45 
46 #define LAC_SYM_HASH_PRECOMP_MAX_AES_ECB_DATA                                  \
47 	((ICP_QAT_HW_AES_128_KEY_SZ) * (3))
48 /**< Maximum size for the data that an AES ECB precompute is generated on */
49 
50 /**
51  *****************************************************************************
52  * @ingroup LacHashDefs
53  *      Precompute type enum
54  * @description
55  *      Enum used to distinguish between precompute types
56  *
57  *****************************************************************************/
58 typedef enum {
59 	LAC_SYM_HASH_PRECOMP_HMAC = 1,
60 	/**< Hmac precompute operation. Copy state from hash state buffer */
61 	LAC_SYM_HASH_PRECOMP_AES_ECB,
62 	/**< XCBC/CGM precompute, Copy state from data buffer */
63 } lac_sym_hash_precomp_type_t;
64 
65 /**
66  *****************************************************************************
67  * @ingroup LacHashDefs
68  *      overall precompute management structure
69  * @description
70  *      structure used to manage the precompute operations for a session
71  *
72  *****************************************************************************/
73 typedef struct lac_sym_hash_precomp_op_s {
74 	lac_hash_precompute_done_cb_t callbackFn;
75 	/**< Callback function to be invoked when the final precompute completes
76 	 */
77 
78 	void *pCallbackTag;
79 	/**< Opaque data to be passed back as a parameter in the callback */
80 
81 	QatUtilsAtomic opsPending;
82 	/**< counter used to determine if the current precompute is the
83 	 * final one. */
84 
85 } lac_sym_hash_precomp_op_t;
86 
87 /**
88  *****************************************************************************
89  * @ingroup LacHashDefs
90  *      hmac precompute structure as used by the QAT
91  * @description
92  *      data used by the QAT for HMAC precomputes
93  *
94  *      Must be allocated on an 8-byte aligned memory address.
95  *
96  *****************************************************************************/
97 typedef struct lac_sym_hash_hmac_precomp_qat_s {
98 	Cpa8U data[LAC_HASH_SHA512_BLOCK_SIZE];
99 	/**< data to be hashed - block size of data for the algorithm */
100 	/* NOTE: to save space we could have got the QAT to overwrite
101 	 * this with the hash state storage */
102 	icp_qat_fw_la_auth_req_params_t hashReqParams;
103 	/**< Request parameters as read in by the QAT */
104 	Cpa8U bufferDesc[LAC_SINGLE_BUFFER_HW_META_SIZE];
105 	/**< Buffer descriptor structure */
106 	Cpa8U hashStateStorage[LAC_MAX_HASH_STATE_STORAGE_SIZE];
107 	/**< Internal buffer where QAT writes the intermediate partial
108 	 * state that is used in the precompute */
109 } lac_sym_hash_hmac_precomp_qat_t;
110 
111 /**
112  *****************************************************************************
113  * @ingroup LacHashDefs
114  *      AES ECB precompute structure as used by the QAT
115  * @description
116  *      data used by the QAT for AES ECB precomptes
117  *
118  *      Must be allocated on an 8-byte aligned memory address.
119  *
120  *****************************************************************************/
121 typedef struct lac_sym_hash_aes_precomp_qat_s {
122 	Cpa8U contentDesc[LAC_SYM_QAT_MAX_CIPHER_SETUP_BLK_SZ];
123 	/**< Content descriptor for a cipher operation */
124 	Cpa8U data[LAC_SYM_HASH_PRECOMP_MAX_AES_ECB_DATA];
125 	/**< The data to be ciphered is conatined here and the result is
126 	 * written in place back into this buffer */
127 	icp_qat_fw_la_cipher_req_params_t cipherReqParams;
128 	/**< Request parameters as read in by the QAT */
129 	Cpa8U bufferDesc[LAC_SINGLE_BUFFER_HW_META_SIZE];
130 	/**< Buffer descriptor structure */
131 } lac_sym_hash_aes_precomp_qat_t;
132 
133 /**
134  *****************************************************************************
135  * @ingroup LacHashDefs
136  *      overall structure for managing a single precompute operation
137  * @description
138  *      overall structure for managing a single precompute operation
139  *
140  *      Must be allocated on an 8-byte aligned memory address.
141  *
142  *****************************************************************************/
143 typedef struct lac_sym_hash_precomp_op_data_s {
144 	sal_crypto_service_t *pInstance;
145 	/**< Instance handle for the operation */
146 	Cpa8U reserved[4];
147 	/**< padding to align later structures on minimum 8-Byte address */
148 	lac_sym_hash_precomp_type_t opType;
149 	/**< operation type to determine the precompute type in the callback */
150 	lac_sym_hash_precomp_op_t *pOpStatus;
151 	/**< structure containing the counter and the condition for the overall
152 	 * precompute operation. This is a pointer because the memory structure
153 	 * may be shared between precomputes when there are more than 1 as in
154 	 * the
155 	 * case of HMAC */
156 	union {
157 		lac_sym_hash_hmac_precomp_qat_t hmacQatData;
158 		/**< Data sent to the QAT for hmac precomputes */
159 		lac_sym_hash_aes_precomp_qat_t aesQatData;
160 		/**< Data sent to the QAT for AES ECB precomputes */
161 	} u;
162 
163 	/**< ASSUMPTION: The above structures are 8 byte aligned if the overall
164 	 * struct is 8 byte aligned, as there are two 4 byte fields before this
165 	 * union */
166 	Cpa32U stateSize;
167 	/**< Size of the state to be copied into the state pointer in the
168 	 * content
169 	 * descriptor */
170 	Cpa8U *pState;
171 	/**< pointer to the state in the content descriptor where the result of
172 	 * the precompute should be copied to */
173 } lac_sym_hash_precomp_op_data_t;
174 
175 #endif /* LAC_SYM_HASH_PRECOMPUTES_H */
176