| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "owndefs.h" |
| 18 |
|
| 19 |
#if (_IPP32E >= _IPP32E_K1) |
| 20 |
|
| 21 |
#include "gfpec/pcpgfpecstuff.h" |
| 22 |
#include "gfpec/pcpgfpstuff.h" |
| 23 |
|
| 24 |
#include "gfpec/ecnist/ifma_defs.h" |
| 25 |
#include "gfpec/ecnist/ifma_ecpoint_p384.h" |
| 26 |
#include "gfpec/ecnist/ifma_arith_method.h" |
| 27 |
|
| 28 |
|
| 29 |
IPP_OWN_DEFN(IppStatus, gfec_SignDSA_nistp384_avx512, (const IppsBigNumState* pMsgDigest, |
| 30 |
const IppsBigNumState* pRegPrivate, |
| 31 |
IppsBigNumState* pEphPrivate, |
| 32 |
IppsBigNumState* pSignR, |
| 33 |
IppsBigNumState* pSignS, |
| 34 |
IppsGFpECState* pEC, |
| 35 |
Ipp8u* pScratchBuffer)) |
| 36 |
|
| 37 |
{ |
| 38 |
IPP_UNREFERENCED_PARAMETER(pScratchBuffer); |
| 39 |
|
| 40 |
IppStatus sts = ippStsNoErr; |
| 41 |
|
| 42 |
gsModEngine* pME = GFP_PMA(ECP_GFP(pEC)); |
| 43 |
gsModEngine* nME = ECP_MONT_R(pEC); |
| 44 |
|
| 45 |
const int orderBits = ECP_ORDBITSIZE(pEC); |
| 46 |
const int orderLen = BITS_BNU_CHUNK(orderBits); |
| 47 |
|
| 48 |
ifmaArithMethod* pmeth = (ifmaArithMethod*)GFP_METHOD_ALT(pME); |
| 49 |
ifmaArithMethod* nmeth = (ifmaArithMethod*)GFP_METHOD_ALT(nME); |
| 50 |
|
| 51 |
ifma_import to_radix52 = pmeth->import_to52; |
| 52 |
ifma_export from_radix52 = pmeth->export_to64; |
| 53 |
|
| 54 |
|
| 55 |
ifma_decode p_from_mont = pmeth->decode; |
| 56 |
|
| 57 |
|
| 58 |
ifma_encode n_to_mont = nmeth->encode; |
| 59 |
ifma_decode n_from_mont = nmeth->decode; |
| 60 |
ifma_mul n_mul = nmeth->mul; |
| 61 |
ifma_add n_add = nmeth->add; |
| 62 |
ifma_inv n_inv = nmeth->inv; |
| 63 |
ifma_red n_red = nmeth->red; |
| 64 |
|
| 65 |
|
| 66 |
BNU_CHUNK_T* pExtendedScalar = cpGFpGetPool(2, pME); |
| 67 |
cpGFpElementCopyPad(pExtendedScalar, |
| 68 |
orderLen + 1, |
| 69 |
BN_NUMBER(pEphPrivate), |
| 70 |
BN_SIZE(pEphPrivate)); |
| 71 |
|
| 72 |
__ALIGN64 P384_POINT_IFMA P; |
| 73 |
|
| 74 |
if (ECP_PREMULBP(pEC)) { |
| 75 |
ifma_ec_nistp384_mul_pointbase(&P, (Ipp8u*)pExtendedScalar, orderBits); |
| 76 |
} else { |
| 77 |
BNU_CHUNK_T* pPool = cpGFpGetPool(3, pME); |
| 78 |
|
| 79 |
|
| 80 |
__ALIGN64 P384_POINT_IFMA G52; |
| 81 |
recode_point_to_mont52(&G52, ECP_G(pEC), pPool, pmeth, pME); |
| 82 |
|
| 83 |
ifma_ec_nistp384_mul_point(&P, &G52, (Ipp8u*)pExtendedScalar, orderBits); |
| 84 |
|
| 85 |
cpGFpReleasePool(3, pME); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
ifma_ec_nistp384_get_affine_coords(&(P.x), NULL, &P); |
| 93 |
|
| 94 |
P.x = p_from_mont(P.x); |
| 95 |
P.x = n_red(P.x); |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
m512 ephPrivateInv = setzero_i64(); |
| 101 |
BNU_CHUNK_T* pTmp = cpGFpGetPool(1, pME); |
| 102 |
ZEXPAND_COPY_BNU(pTmp, orderLen, BN_NUMBER(pEphPrivate), BN_SIZE(pEphPrivate)); |
| 103 |
ephPrivateInv = to_radix52(pTmp); |
| 104 |
|
| 105 |
ephPrivateInv = n_to_mont(ephPrivateInv); |
| 106 |
ephPrivateInv = n_inv(ephPrivateInv); |
| 107 |
|
| 108 |
|
| 109 |
m512 msgDigest = setzero_i64(); |
| 110 |
ZEXPAND_COPY_BNU(pTmp, orderLen, BN_NUMBER(pMsgDigest), BN_SIZE(pMsgDigest)); |
| 111 |
msgDigest = to_radix52(pTmp); |
| 112 |
msgDigest = n_red(msgDigest); |
| 113 |
msgDigest = n_to_mont(msgDigest); |
| 114 |
|
| 115 |
|
| 116 |
m512 regPrivate = setzero_i64(); |
| 117 |
ZEXPAND_COPY_BNU(pTmp, orderLen, BN_NUMBER(pRegPrivate), BN_SIZE(pRegPrivate)); |
| 118 |
regPrivate = to_radix52(pTmp); |
| 119 |
regPrivate = n_to_mont(regPrivate); |
| 120 |
|
| 121 |
m512 signS; |
| 122 |
|
| 123 |
signS = n_to_mont(P.x); |
| 124 |
signS = n_mul(regPrivate, signS); |
| 125 |
signS = n_add(signS, msgDigest); |
| 126 |
signS = n_mul(signS, ephPrivateInv); |
| 127 |
signS = n_from_mont(signS); |
| 128 |
|
| 129 |
const mask8 isZero = (mask8)(is_zero_i64(signS) | is_zero_i64(P.x)); |
| 130 |
if ((mask8)0xFF == isZero) |
| 131 |
sts = ippStsEphemeralKeyErr; |
| 132 |
|
| 133 |
from_radix52((Ipp64u*)pTmp, signS); |
| 134 |
BN_SIGN(pSignS) = ippBigNumPOS; |
| 135 |
BN_SIZE(pSignS) = orderLen; |
| 136 |
ZEXPAND_COPY_BNU(BN_NUMBER(pSignS), BN_ROOM(pSignS), pTmp, orderLen); |
| 137 |
|
| 138 |
from_radix52((Ipp64u*)pTmp, P.x); |
| 139 |
BN_SIGN(pSignR) = ippBigNumPOS; |
| 140 |
BN_SIZE(pSignR) = orderLen; |
| 141 |
ZEXPAND_COPY_BNU(BN_NUMBER(pSignR), BN_ROOM(pSignR), pTmp, orderLen); |
| 142 |
|
| 143 |
|
| 144 |
clear_secrets(®Private, &(P.x), &signS); |
| 145 |
|
| 146 |
cpGFpReleasePool(3, pME); |
| 147 |
|
| 148 |
return sts; |
| 149 |
} |
| 150 |
|
| 151 |
#endif |