| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) |
| 28 |
#pragma warning(disable : 4206) // empty translation unit in MSVC |
| 29 |
#endif |
| 30 |
|
| 31 |
#if 0 |
| 32 |
|
| 33 |
#include "owncp.h" |
| 34 |
#include "pcpaesm.h" |
| 35 |
#include "pcpaes_encrypt_vaes512.h" |
| 36 |
#include "pcpaes_gcm_vaes512.h" |
| 37 |
#include "pcpaesauthgcm.h" |
| 38 |
|
| 39 |
#if (_IPP32E >= _IPP32E_K1) |
| 40 |
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) |
| 41 |
#pragma warning(disable : 4310) // cast truncates constant value in MSVC |
| 42 |
#endif |
| 43 |
|
| 44 |
|
| 45 |
IPP_OWN_DEFN (void, AesGcmAuth_vaes, (Ipp8u* pGHash, const Ipp8u* pSrc, int len, const Ipp8u* pHKey, const void* pParam)) |
| 46 |
{ |
| 47 |
IPP_UNREFERENCED_PARAMETER(pParam); |
| 48 |
|
| 49 |
__m512i* pSrc512 = (__m512i*)pSrc; |
| 50 |
__m512i* pHKey512 = (__m512i*)pHKey; |
| 51 |
|
| 52 |
|
| 53 |
__m512i hKeys0 = _mm512_loadu_si512(pHKey512); |
| 54 |
__m512i hKeys1 = _mm512_loadu_si512(pHKey512 + 1); |
| 55 |
__m512i hKeys2 = _mm512_loadu_si512(pHKey512 + 2); |
| 56 |
__m512i hKeys3 = _mm512_loadu_si512(pHKey512 + 3); |
| 57 |
|
| 58 |
|
| 59 |
__m512i hKeysKaratsuba0 = _mm512_loadu_si512(pHKey512 + 4); |
| 60 |
__m512i hKeysKaratsuba1 = _mm512_loadu_si512(pHKey512 + 5); |
| 61 |
__m512i hKeysKaratsuba2 = _mm512_loadu_si512(pHKey512 + 6); |
| 62 |
__m512i hKeysKaratsuba3 = _mm512_loadu_si512(pHKey512 + 7); |
| 63 |
|
| 64 |
|
| 65 |
__m128i ghash128; |
| 66 |
__m512i ghash512 = _mm512_maskz_loadu_epi64(0x03, pGHash); |
| 67 |
ghash512 = _mm512_shuffle_epi8(ghash512, M512(swapBytes)); |
| 68 |
|
| 69 |
int blocks; |
| 70 |
for (blocks = len / MBS_RIJ128; blocks >= (4 * 4); blocks -= (4 * 4)) { |
| 71 |
__m512i blk0 = _mm512_loadu_si512(pSrc512); |
| 72 |
__m512i blk1 = _mm512_loadu_si512(pSrc512 + 1); |
| 73 |
__m512i blk2 = _mm512_loadu_si512(pSrc512 + 2); |
| 74 |
__m512i blk3 = _mm512_loadu_si512(pSrc512 + 3); |
| 75 |
|
| 76 |
|
| 77 |
blk0 = _mm512_shuffle_epi8(blk0, M512(swapBytes)); |
| 78 |
blk1 = _mm512_shuffle_epi8(blk1, M512(swapBytes)); |
| 79 |
blk2 = _mm512_shuffle_epi8(blk2, M512(swapBytes)); |
| 80 |
blk3 = _mm512_shuffle_epi8(blk3, M512(swapBytes)); |
| 81 |
|
| 82 |
|
| 83 |
blk0 = _mm512_mask_xor_epi64(blk0, 0x03, blk0, ghash512); |
| 84 |
|
| 85 |
|
| 86 |
__m512i H, M, L, tmp1, tmp2, tmp3; |
| 87 |
AesGcmKaratsubaMul4(&blk0, &hKeys3, &hKeysKaratsuba3, &H, &M, &L); |
| 88 |
AesGcmKaratsubaMul4(&blk1, &hKeys2, &hKeysKaratsuba2, &tmp1, &tmp2, &tmp3); |
| 89 |
H = _mm512_xor_si512(H, tmp1); |
| 90 |
M = _mm512_xor_si512(M, tmp2); |
| 91 |
L = _mm512_xor_si512(L, tmp3); |
| 92 |
AesGcmKaratsubaMul4(&blk2, &hKeys1, &hKeysKaratsuba1, &tmp1, &tmp2, &tmp3); |
| 93 |
H = _mm512_xor_si512(H, tmp1); |
| 94 |
M = _mm512_xor_si512(M, tmp2); |
| 95 |
L = _mm512_xor_si512(L, tmp3); |
| 96 |
AesGcmKaratsubaMul4(&blk3, &hKeys0, &hKeysKaratsuba0, &tmp1, &tmp2, &tmp3); |
| 97 |
H = _mm512_xor_si512(H, tmp1); |
| 98 |
M = _mm512_xor_si512(M, tmp2); |
| 99 |
L = _mm512_xor_si512(L, tmp3); |
| 100 |
|
| 101 |
AggregateKaratsubaPartialProducts(&H, &M, &L, &ghash128); |
| 102 |
|
| 103 |
|
| 104 |
ghash512 = _mm512_castsi128_si512(ghash128); |
| 105 |
|
| 106 |
pSrc512 += 4; |
| 107 |
} |
| 108 |
|
| 109 |
if ((3 * 4) <= blocks) { |
| 110 |
__m512i blk0 = _mm512_loadu_si512(pSrc512); |
| 111 |
__m512i blk1 = _mm512_loadu_si512(pSrc512+1); |
| 112 |
__m512i blk2 = _mm512_loadu_si512(pSrc512+2); |
| 113 |
|
| 114 |
|
| 115 |
blk0 = _mm512_shuffle_epi8(blk0, M512(swapBytes)); |
| 116 |
blk1 = _mm512_shuffle_epi8(blk1, M512(swapBytes)); |
| 117 |
blk2 = _mm512_shuffle_epi8(blk2, M512(swapBytes)); |
| 118 |
|
| 119 |
|
| 120 |
blk0 = _mm512_mask_xor_epi64(blk0, 0x03, blk0, ghash512); |
| 121 |
|
| 122 |
__m512i H, M, L, tmp1, tmp2, tmp3; |
| 123 |
AesGcmKaratsubaMul4(&blk0, &hKeys2, &hKeysKaratsuba2, &H, &M, &L); |
| 124 |
AesGcmKaratsubaMul4(&blk1, &hKeys1, &hKeysKaratsuba1, &tmp1, &tmp2, &tmp3); |
| 125 |
H = _mm512_xor_si512(H, tmp1); |
| 126 |
M = _mm512_xor_si512(M, tmp2); |
| 127 |
L = _mm512_xor_si512(L, tmp3); |
| 128 |
AesGcmKaratsubaMul4(&blk2, &hKeys0, &hKeysKaratsuba0, &tmp1, &tmp2, &tmp3); |
| 129 |
H = _mm512_xor_si512(H, tmp1); |
| 130 |
M = _mm512_xor_si512(M, tmp2); |
| 131 |
L = _mm512_xor_si512(L, tmp3); |
| 132 |
|
| 133 |
AggregateKaratsubaPartialProducts(&H, &M, &L, &ghash128); |
| 134 |
|
| 135 |
|
| 136 |
ghash512 = _mm512_castsi128_si512(ghash128); |
| 137 |
|
| 138 |
pSrc512 += 3; |
| 139 |
} |
| 140 |
|
| 141 |
if ((4 * 2) <= blocks) { |
| 142 |
__m512i blk0 = _mm512_loadu_si512(pSrc512); |
| 143 |
__m512i blk1 = _mm512_loadu_si512(pSrc512+1); |
| 144 |
|
| 145 |
|
| 146 |
blk0 = _mm512_shuffle_epi8(blk0, M512(swapBytes)); |
| 147 |
blk1 = _mm512_shuffle_epi8(blk1, M512(swapBytes)); |
| 148 |
|
| 149 |
|
| 150 |
blk0 = _mm512_mask_xor_epi64(blk0, 0x03, blk0, ghash512); |
| 151 |
|
| 152 |
__m512i H, M, L, tmp1, tmp2, tmp3; |
| 153 |
AesGcmKaratsubaMul4(&blk0, &hKeys1, &hKeysKaratsuba1, &H, &M, &L); |
| 154 |
AesGcmKaratsubaMul4(&blk1, &hKeys0, &hKeysKaratsuba0, &tmp1, &tmp2, &tmp3); |
| 155 |
H = _mm512_xor_si512(H, tmp1); |
| 156 |
M = _mm512_xor_si512(M, tmp2); |
| 157 |
L = _mm512_xor_si512(L, tmp3); |
| 158 |
|
| 159 |
AggregateKaratsubaPartialProducts(&H, &M, &L, &ghash128); |
| 160 |
|
| 161 |
|
| 162 |
ghash512 = _mm512_castsi128_si512(ghash128); |
| 163 |
|
| 164 |
pSrc512 += 2; |
| 165 |
} |
| 166 |
|
| 167 |
for (; blocks >= 4; blocks -= 4) { |
| 168 |
__m512i blk0 = _mm512_loadu_si512(pSrc512); |
| 169 |
blk0 = _mm512_shuffle_epi8(blk0, M512(swapBytes)); |
| 170 |
|
| 171 |
|
| 172 |
blk0 = _mm512_mask_xor_epi64(blk0, 0x03, blk0, ghash512); |
| 173 |
|
| 174 |
__m512i H, M, L; |
| 175 |
AesGcmKaratsubaMul4(&blk0, &hKeys0, &hKeysKaratsuba0, &H, &M, &L); |
| 176 |
|
| 177 |
AggregateKaratsubaPartialProducts(&H, &M, &L, &ghash128); |
| 178 |
|
| 179 |
|
| 180 |
ghash512 = _mm512_castsi128_si512(ghash128); |
| 181 |
|
| 182 |
pSrc512 += 1; |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
if (blocks) { |
| 187 |
__mmask8 k8 = (__mmask8)((1 << (blocks + blocks)) - 1); |
| 188 |
|
| 189 |
__m512i blk0 = _mm512_maskz_loadu_epi64(k8, pSrc512); |
| 190 |
blk0 = _mm512_shuffle_epi8(blk0, M512(swapBytes)); |
| 191 |
|
| 192 |
|
| 193 |
blk0 = _mm512_mask_xor_epi64(blk0, 0x03, blk0, ghash512); |
| 194 |
|
| 195 |
__m512i H = _mm512_setzero_si512(); |
| 196 |
__m512i M = _mm512_setzero_si512(); |
| 197 |
__m512i L = _mm512_setzero_si512(); |
| 198 |
|
| 199 |
|
| 200 |
switch (blocks) { |
| 201 |
case 1: { |
| 202 |
hKeys0 = _mm512_alignr_epi64(_mm512_setzero_si512(), hKeys0, 6); |
| 203 |
hKeysKaratsuba0 = _mm512_alignr_epi64(_mm512_setzero_si512(), hKeysKaratsuba0, 6); |
| 204 |
break; |
| 205 |
} |
| 206 |
case 2: { |
| 207 |
hKeys0 = _mm512_alignr_epi64(_mm512_setzero_si512(), hKeys0, 4); |
| 208 |
hKeysKaratsuba0 = _mm512_alignr_epi64(_mm512_setzero_si512(), hKeysKaratsuba0, 4); |
| 209 |
break; |
| 210 |
} |
| 211 |
default: { |
| 212 |
hKeys0 = _mm512_alignr_epi64(_mm512_setzero_si512(), hKeys0, 2); |
| 213 |
hKeysKaratsuba0 = _mm512_alignr_epi64(_mm512_setzero_si512(), hKeysKaratsuba0, 2); |
| 214 |
} |
| 215 |
} |
| 216 |
AesGcmKaratsubaMul4(&blk0, &hKeys0, &hKeysKaratsuba0, &H, &M, &L); |
| 217 |
|
| 218 |
AggregateKaratsubaPartialProducts(&H, &M, &L, &ghash128); |
| 219 |
|
| 220 |
|
| 221 |
ghash512 = _mm512_castsi128_si512(ghash128); |
| 222 |
} |
| 223 |
|
| 224 |
ghash512 = _mm512_shuffle_epi8(ghash512, M512(swapBytes)); |
| 225 |
_mm512_mask_storeu_epi64(pGHash, 0x03, ghash512); |
| 226 |
} |
| 227 |
|
| 228 |
#endif |
| 229 |
|
| 230 |
#endif |