Debian Codegraph @

sources/ippcp/pcpaesauthgcm_avx512.h

raw symbols SCIP
1 /*************************************************************************
2 * Copyright (C) 2020 Intel Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *************************************************************************/
16
17 /*
18 //
19 // Purpose:
20 // Cryptography Primitive.
21 // AES GCM optimized for AVX512 and AVX512-VAES features
22 // Internal Definitions
23 //
24 //
25 */
26
27 #ifndef _CP_AESAUTH_GCM_AVX512_H
28 #define _CP_AESAUTH_GCM_AVX512_H
29
30 #include "owndefs.h"
31 #include "owncp.h"
32
33 #if (_IPP32E >= _IPP32E_K0)
34
35 #include "pcprij.h"
36
37 #include "aes_gcm_vaes.h"
38 #include "aes_gcm_avx512.h"
39 #include "aes_gcm_avx512_structures.h"
40
41 // Prototypes for internal functions from IPsec
42
43 /* clang-format off */
44 // IV processing
45 IPP_OWN_FUNPTR(void, IvUpdate_, (const struct gcm_key_data* key_data,
46 struct gcm_context_data* context_data,
47 const Ipp8u* iv,
48 const Ipp64u iv_len))
49 IPP_OWN_FUNPTR(void, IvFinalize_, (const struct gcm_key_data* key_data,
50 struct gcm_context_data* context_data,
51 const Ipp8u* iv,
52 const Ipp64u iv_len,
53 const Ipp64u iv_general_len))
54
55 // AAD processing
56 IPP_OWN_FUNPTR(void, AadUpdate_, (const struct gcm_key_data* key_data,
57 struct gcm_context_data* context_data,
58 const Ipp8u* aad,
59 const Ipp64u aad_len))
60
61 // GCM multiplication
62 IPP_OWN_FUNPTR(void, MulGcm_, (const struct gcm_key_data* key_data, Ipp8u* ghash))
63
64 // Encryption-authentication
65 IPP_OWN_FUNPTR(void, EncryptUpdate_, (const struct gcm_key_data* key_data,
66 struct gcm_context_data* context_data,
67 Ipp8u* out,
68 const Ipp8u* in,
69 Ipp64u len))
70
71 // Decryption-verification
72 IPP_OWN_FUNPTR(void, DecryptUpdate_, (const struct gcm_key_data* key_data,
73 struct gcm_context_data* context_data,
74 Ipp8u* out,
75 const Ipp8u* in,Ipp64u len))
76
77 // Get tag
78 IPP_OWN_FUNPTR(void, GetTag_, (const struct gcm_key_data* key_data,
79 const struct gcm_context_data* context_data,
80 Ipp8u* auth_tag,
81 Ipp64u auth_tag_len))
82 /* clang-format on */
83
84 typedef enum { GcmInit, GcmIVprocessing, GcmAADprocessing, GcmTXTprocessing } GcmState;
85
86 #define BLOCK_SIZE (MBS_RIJ128)
87
88 // Structure modified to work with functions from IPsec
89
90 struct _cpAES_GCM {
91
92 Ipp32u idCtx; /* AES-GCM id */
93 GcmState state; /* GCM state: Init, IV|AAD|TXT processing */
94 Ipp64u ivLen; /* IV length (bytes) */
95 Ipp64u aadLen; /* header length (bytes) */
96 Ipp64u txtLen; /* text length (bytes) */
97
98 int bufLen; /* stuff buffer length */
99 __ALIGN16 /* aligned buffers */
100 Ipp8u counter[BLOCK_SIZE]; /* counter */
101 Ipp8u ecounter0[BLOCK_SIZE]; /* encrypted initial counter */
102 Ipp8u ecounter[BLOCK_SIZE]; /* encrypted counter */
103 Ipp8u ghash[BLOCK_SIZE]; /* ghash accumulator */
104
105 __ALIGN16
106 struct gcm_key_data key_data;
107 __ALIGN16
108 struct gcm_context_data context_data;
109 Ipp64u keyLen; /* key length (bytes) */
110
111 IvUpdate_ ivUpdateFunc; // IV processing
112 IvFinalize_ ivFinalizeFunc;
113 AadUpdate_ aadUpdateFunc; // AAD processing
114 MulGcm_ gcmMulFunc; // GCM multiplication
115 EncryptUpdate_ encryptUpdateFunc; // Encryption-authentication
116 DecryptUpdate_ decryptUpdateFunc; // Decryption-verification
117 GetTag_ getTagFunc; // Get tag
118
119 #if (_AES_PROB_NOISE == _FEATURE_ON_)
120 __ALIGN16
121 cpAESNoiseParams noiseParams;
122 #endif
123 };
124
125 // Alignment
126 #define AESGCM_ALIGNMENT (16)
127
128 // Useful macros
129 #define AESGCM_SET_ID(context) \
130 ((context)->idCtx = (Ipp32u)idCtxAESGCM ^ (Ipp32u)IPP_UINT_PTR(context))
131 #define AESGCM_STATE(context) ((context)->state)
132
133 #define AESGCM_IV_LEN(context) ((context)->ivLen)
134
135 #define AESGCM_COUNTER(context) ((context)->counter)
136 #define AESGCM_ECOUNTER0(context) ((context)->ecounter0)
137 #define AESGCM_ECOUNTER(context) ((context)->ecounter)
138
139 #define AES_GCM_KEY_DATA(context) ((context)->key_data)
140 #define AES_GCM_CONTEXT_DATA(context) ((context)->context_data)
141 #define AES_GCM_KEY_LEN(context) ((context)->keyLen)
142
143 #define AES_GCM_IV_UPDATE(context) ((context)->ivUpdateFunc)
144 #define AES_GCM_IV_FINALIZE(context) ((context)->ivFinalizeFunc)
145 #define AES_GCM_AAD_UPDATE(context) ((context)->aadUpdateFunc)
146 #define AES_GCM_GMUL(context) ((context)->gcmMulFunc)
147 #define AES_GCM_ENCRYPT_UPDATE(context) ((context)->encryptUpdateFunc)
148 #define AES_GCM_DECRYPT_UPDATE(context) ((context)->decryptUpdateFunc)
149 #define AES_GCM_GET_TAG(context) ((context)->getTagFunc)
150
151 // Fields retargeted to IPsec context
152 #define AESGCM_GHASH(context) (&(AES_GCM_CONTEXT_DATA(context).aad_hash[0]))
153 #define AESGCM_TXT_LEN(context) (AES_GCM_CONTEXT_DATA(context).in_length)
154 #define AESGCM_AAD_LEN(context) (AES_GCM_CONTEXT_DATA(context).aad_length)
155 #define AESGCM_BUFLEN(context) (AES_GCM_CONTEXT_DATA(context).partial_block_length)
156
157 #if (_AES_PROB_NOISE == _FEATURE_ON_)
158 #define AESGCM_NOISE_PARAMS(ctx) ((ctx)->noiseParams)
159 #endif
160
161 #define AESGCM_VALID_ID(context) \
162 ((((context)->idCtx) ^ (Ipp32u)IPP_UINT_PTR((context))) == (Ipp32u)idCtxAESGCM)
163
164 static int cpSizeofCtx_AESGCM(void)
165 {
166 return (Ipp32s)sizeof(IppsAES_GCMState) + AESGCM_ALIGNMENT - 1;
167 }
168
169 #endif // (_IPP32E>=_IPP32E_K0)
170
171 #endif // _CP_AESAUTH_GCM_AVX512_H