| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include "owncp.h" |
| 25 |
|
| 26 |
#if (_IPP32E >= _IPP32E_K1) |
| 27 |
|
| 28 |
#include "pcpbnuimpl.h" |
| 29 |
#include "pcpngmontexpstuff.h" |
| 30 |
|
| 31 |
#define RSA_AVX512_MIN_BITSIZE (1024) |
| 32 |
#define RSA_AVX512_MAX_BITSIZE (13 * 1024) |
| 33 |
|
| 34 |
#define EXP_DIGIT_SIZE_AVX512 (52) |
| 35 |
#define EXP_DIGIT_BASE_AVX512 (1 << EXP_DIGIT_SIZE_AVX512) |
| 36 |
#define EXP_DIGIT_MASK_AVX512 ((Ipp64u)0xFFFFFFFFFFFFF) |
| 37 |
|
| 38 |
|
| 39 |
#define NUMBER_OF_DIGITS(bitsize, digsize) (((bitsize) + (digsize)-1) / (digsize)) |
| 40 |
|
| 41 |
|
| 42 |
IPPCP_INLINE cpSize numofVariable_avx512(int modulusBits) |
| 43 |
{ |
| 44 |
cpSize ammBitSize = |
| 45 |
2 + NUMBER_OF_DIGITS(modulusBits, BITSIZE(BNU_CHUNK_T)) * BITSIZE(BNU_CHUNK_T); |
| 46 |
cpSize redNum = NUMBER_OF_DIGITS(ammBitSize, EXP_DIGIT_SIZE_AVX512); |
| 47 |
return redNum; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
IPPCP_INLINE int numofVariableBuff_avx512(int len, int regCapacity) |
| 57 |
{ |
| 58 |
int tail = len % regCapacity; |
| 59 |
if (0 == tail) |
| 60 |
tail = regCapacity; |
| 61 |
return len + (regCapacity - tail); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
IPPCP_INLINE Ipp64u getDig52(const Ipp8u* pStr, int strLen) |
| 71 |
{ |
| 72 |
Ipp64u digit = 0; |
| 73 |
for (; strLen > 0; strLen--) { |
| 74 |
digit <<= 8; |
| 75 |
digit += (Ipp64u)(pStr[strLen - 1]); |
| 76 |
} |
| 77 |
return digit; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
static void regular_dig52(Ipp64u* out, int outLen , const Ipp64u* in, int inBitSize) |
| 82 |
{ |
| 83 |
Ipp8u* inStr = (Ipp8u*)in; |
| 84 |
|
| 85 |
for (; inBitSize >= (2 * EXP_DIGIT_SIZE_AVX512); |
| 86 |
inBitSize -= (2 * EXP_DIGIT_SIZE_AVX512), out += 2) { |
| 87 |
out[0] = (*(Ipp64u*)inStr) & EXP_DIGIT_MASK_AVX512; |
| 88 |
inStr += 6; |
| 89 |
out[1] = ((*(Ipp64u*)inStr) >> 4) & EXP_DIGIT_MASK_AVX512; |
| 90 |
inStr += 7; |
| 91 |
outLen -= 2; |
| 92 |
} |
| 93 |
if (inBitSize > EXP_DIGIT_SIZE_AVX512) { |
| 94 |
Ipp64u digit = getDig52(inStr, 7); |
| 95 |
out[0] = digit & EXP_DIGIT_MASK_AVX512; |
| 96 |
inStr += 6; |
| 97 |
inBitSize -= EXP_DIGIT_SIZE_AVX512; |
| 98 |
digit = getDig52(inStr, BITS2WORD8_SIZE(inBitSize)); |
| 99 |
out[1] = digit >> 4; |
| 100 |
out += 2; |
| 101 |
outLen -= 2; |
| 102 |
} else if (inBitSize > 0) { |
| 103 |
out[0] = getDig52(inStr, BITS2WORD8_SIZE(inBitSize)); |
| 104 |
out++; |
| 105 |
outLen--; |
| 106 |
} |
| 107 |
for (; outLen > 0; outLen--, out++) |
| 108 |
out[0] = 0; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
IPPCP_INLINE void putDig52(Ipp8u* pStr, int strLen, Ipp64u digit) |
| 116 |
{ |
| 117 |
for (; strLen > 0; strLen--) { |
| 118 |
*pStr++ = (Ipp8u)(digit & 0xFF); |
| 119 |
digit >>= 8; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
static void dig52_regular(Ipp64u* out, const Ipp64u* in, int outBitSize) |
| 124 |
{ |
| 125 |
int i; |
| 126 |
int outLen = BITS2WORD64_SIZE(outBitSize); |
| 127 |
for (i = 0; i < outLen; i++) |
| 128 |
out[i] = 0; |
| 129 |
|
| 130 |
{ |
| 131 |
Ipp8u* outStr = (Ipp8u*)out; |
| 132 |
for (; outBitSize >= (2 * EXP_DIGIT_SIZE_AVX512); |
| 133 |
outBitSize -= (2 * EXP_DIGIT_SIZE_AVX512), in += 2) { |
| 134 |
(*(Ipp64u*)outStr) = in[0]; |
| 135 |
outStr += 6; |
| 136 |
(*(Ipp64u*)outStr) ^= in[1] << 4; |
| 137 |
outStr += 7; |
| 138 |
} |
| 139 |
if (outBitSize > EXP_DIGIT_SIZE_AVX512) { |
| 140 |
putDig52(outStr, 7, in[0]); |
| 141 |
outStr += 6; |
| 142 |
outBitSize -= EXP_DIGIT_SIZE_AVX512; |
| 143 |
putDig52(outStr, BITS2WORD8_SIZE(outBitSize), (in[1] << 4 | in[0] >> 48)); |
| 144 |
} else if (outBitSize) { |
| 145 |
putDig52(outStr, BITS2WORD8_SIZE(outBitSize), in[0]); |
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
#define gsMontExpBinBuffer_avx512 OWNAPI(gsMontExpBinBuffer_avx512) |
| 152 |
IPP_OWN_DECL(cpSize, gsMontExpBinBuffer_avx512, (int modulusBits)) |
| 153 |
#define gsMontExpWinBuffer_avx512 OWNAPI(gsMontExpWinBuffer_avx512) |
| 154 |
IPP_OWN_DECL(cpSize, gsMontExpWinBuffer_avx512, (int modulusBits)) |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
#define gsMontExpBin_BNU_avx512 OWNAPI(gsMontExpBin_BNU_avx512) |
| 159 |
IPP_OWN_DECL (cpSize, gsMontExpBin_BNU_avx512, (BNU_CHUNK_T* dataY, const BNU_CHUNK_T* dataX, cpSize nsX, const BNU_CHUNK_T* dataE, cpSize nsE, gsModEngine* pMont, BNU_CHUNK_T* pBuffer)) |
| 160 |
#define gsMontExpWin_BNU_avx512 OWNAPI(gsMontExpWin_BNU_avx512) |
| 161 |
IPP_OWN_DECL (cpSize, gsMontExpWin_BNU_avx512, (BNU_CHUNK_T* dataY, const BNU_CHUNK_T* dataX, cpSize nsX, const BNU_CHUNK_T* dataE, cpSize nsE, gsModEngine* pMont, BNU_CHUNK_T* pBuffer)) |
| 162 |
#define gsMontExpBin_BNU_sscm_avx512 OWNAPI(gsMontExpBin_BNU_sscm_avx512) |
| 163 |
IPP_OWN_DECL (cpSize, gsMontExpBin_BNU_sscm_avx512, (BNU_CHUNK_T* dataY, const BNU_CHUNK_T* dataX, cpSize nsX, const BNU_CHUNK_T* dataE, cpSize nsE, gsModEngine* pMont, BNU_CHUNK_T* pBuffer)) |
| 164 |
#define gsMontExpWin_BNU_sscm_avx512 OWNAPI(gsMontExpWin_BNU_sscm_avx512) |
| 165 |
IPP_OWN_DECL (cpSize, gsMontExpWin_BNU_sscm_avx512, (BNU_CHUNK_T* dataY, const BNU_CHUNK_T* dataX, cpSize nsX, const BNU_CHUNK_T* dataE, cpSize nsE, gsModEngine* pMont, BNU_CHUNK_T* pBuffer)) |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
#define gsMontDualExpWinBuffer_avx512 OWNAPI(gsMontDualExpWinBuffer_avx512) |
| 170 |
IPP_OWN_DECL(cpSize, gsMontDualExpWinBuffer_avx512, (int modulusBits)) |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
#define gsMontDualExpWin_BNU_sscm_avx512 OWNAPI(gsMontDualExpWin_BNU_sscm_avx512) |
| 175 |
IPP_OWN_DECL(cpSize, gsMontDualExpWin_BNU_sscm_avx512, (BNU_CHUNK_T* dataY[2], const BNU_CHUNK_T* dataX[2], cpSize nsX[2], const BNU_CHUNK_T* dataE[2], gsModEngine* pMont[2], BNU_CHUNK_T* pBuffer)) |
| 176 |
|
| 177 |
|
| 178 |
#endif |