Debian Codegraph @

sources/ippcp/gfpec/ecnist/ifma_ec_dh_p384.c

raw symbols SCIP
1 /*************************************************************************
2 * Copyright (C) 2021 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 #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 /* clang-format off */
29 IPP_OWN_DEFN(int, gfec_SharedSecretDH_nistp384_avx512, (IppsGFpECPoint* pR,
30 const IppsGFpECPoint* pP,
31 const BNU_CHUNK_T* pScalar,
32 int scalarLen,
33 IppsGFpECState* pEC,
34 Ipp8u* pScratchBuffer))
35 /* clang-format on */
36 {
37 FIX_BNU(pScalar, scalarLen);
38 {
39 IPP_UNREFERENCED_PARAMETER(pScratchBuffer);
40
41 gsModEngine* pME = GFP_PMA(ECP_GFP(pEC));
42
43 const int orderBits = ECP_ORDBITSIZE(pEC);
44 const int orderLen = BITS_BNU_CHUNK(orderBits);
45
46 ifmaArithMethod* pmeth = (ifmaArithMethod*)GFP_METHOD_ALT(pME);
47
48 ifma_export from_radix52 = pmeth->export_to64;
49
50 /* Mod engine (mod p) */
51 ifma_decode p_from_mont = pmeth->decode;
52
53 /* Copy scalar */
54 BNU_CHUNK_T* pExtendedScalar = cpGFpGetPool(2, pME);
55 cpGFpElementCopyPad(pExtendedScalar, orderLen + 1, pScalar, scalarLen);
56
57 __ALIGN64 P384_POINT_IFMA P52, R52;
58 BNU_CHUNK_T* pPool = cpGFpGetPool(3, pME);
59
60 /* Convert point coordinates to a new Montgomery domain */
61 recode_point_to_mont52(&P52, ECP_POINT_DATA(pP), pPool, pmeth, pME);
62
63 ifma_ec_nistp384_mul_point(&R52, &P52, (Ipp8u*)pExtendedScalar, orderBits);
64
65
66 /* Check if the point - point to infinity */
67 const mask8 is_zero_z = is_zero_i64(R52.z);
68 int finite_point = ((mask8)0xFF != is_zero_z);
69
70 /* Get X affine coordinate */
71 ifma_ec_nistp384_get_affine_coords(&(R52.x), NULL, &R52);
72
73 R52.x = p_from_mont(R52.x);
74 from_radix52(ECP_POINT_X(pR), R52.x);
75
76 cpGFpReleasePool(5, pME);
77
78 return finite_point;
79 }
80 }
81
82 #endif // IPP32E >= _IPP32E_K1