1 /*******************************************************************************
2 * Copyright 2010-2018 Intel Corporation
3 * All Rights Reserved.
4 *
5 * If this software was obtained under the Intel Simplified Software License,
6 * the following terms apply:
7 *
8 * The source code, information and material ("Material") contained herein is
9 * owned by Intel Corporation or its suppliers or licensors, and title to such
10 * Material remains with Intel Corporation or its suppliers or licensors. The
11 * Material contains proprietary information of Intel or its suppliers and
12 * licensors. The Material is protected by worldwide copyright laws and treaty
13 * provisions. No part of the Material may be used, copied, reproduced,
14 * modified, published, uploaded, posted, transmitted, distributed or disclosed
15 * in any way without Intel's prior express written permission. No license under
16 * any patent, copyright or other intellectual property rights in the Material
17 * is granted to or conferred upon you, either expressly, by implication,
18 * inducement, estoppel or otherwise. Any license under such intellectual
19 * property rights must be express and approved by Intel in writing.
20 *
21 * Unless otherwise agreed by Intel in writing, you may not remove or alter this
22 * notice or any other notice embedded in Materials by Intel or Intel's
23 * suppliers or licensors in any way.
24 *
25 *
26 * If this software was obtained under the Apache License, Version 2.0 (the
27 * "License"), the following terms apply:
28 *
29 * You may not use this file except in compliance with the License. You may
30 * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
31 *
32 *
33 * Unless required by applicable law or agreed to in writing, software
34 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
35 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36 *
37 * See the License for the specific language governing permissions and
38 * limitations under the License.
39 *******************************************************************************/
40
41 /*
42 //
43 // Purpose:
44 // Intel(R) Integrated Performance Primitives. Cryptography Primitives.
45 // Internal EC over GF(p^m) basic Definitions & Function Prototypes
46 //
47 // Context:
48 // gfec_base_point_mul()
49 //
50 */
51
52 #include "owndefs.h"
53 #include "owncp.h"
54 #include "pcpgfpecstuff.h"
55 #include "pcpmask_ct.h"
56
gfec_base_point_mul(BNU_CHUNK_T * pRdata,const Ipp8u * pScalar8,int scalarBitSize,IppsGFpECState * pEC)57 void gfec_base_point_mul(BNU_CHUNK_T* pRdata, const Ipp8u* pScalar8, int scalarBitSize, IppsGFpECState* pEC)
58 {
59 /* size of window, get function and pre-computed table */
60 int window_size = ECP_PREMULBP(pEC)->w;
61 selectAP select_affine_point = ECP_PREMULBP(pEC)->select_affine_point;
62 const BNU_CHUNK_T* pTbl = ECP_PREMULBP(pEC)->pTbl;
63
64 IppsGFpState* pGF = ECP_GFP(pEC);
65 gsModEngine* pGFE = GFP_PMA(pGF);
66 int elmLen = GFP_FELEN(pGFE);
67
68 mod_neg negF = GFP_METHOD(pGFE)->neg;
69
70 BNU_CHUNK_T* mont1 = GFP_MNT_R(pGFE);
71
72 /* number of points per table slot */
73 int tslot_point = 1<<(window_size-1);
74 int tslot_size = tslot_point * (elmLen*2);
75
76 BNU_CHUNK_T* negtmp = cpGFpGetPool(1, pGFE); /* temporary element */
77 BNU_CHUNK_T* pointT = cpEcGFpGetPool(1, pEC); /* temporary point */
78
79 Ipp8u digit, sign;
80 int mask = (1<<(window_size+1)) -1;
81 int bit = 0;
82
83 /* processing of window[0] */
84 int wvalue = *((Ipp16u*)&pScalar8[0]);
85 wvalue = (wvalue << 1) & mask;
86
87 booth_recode(&sign, &digit, (Ipp8u)wvalue, window_size);
88 select_affine_point(pRdata, pTbl, digit);
89
90 negF(negtmp, pRdata+elmLen, pGFE);
91 cpMaskedReplace_ct(pRdata+elmLen, negtmp, elmLen, ~cpIsZero_ct(sign));
92 cpGFpElementCopy(pRdata+elmLen*2, mont1, elmLen);
93 cpGFpElementCopy(pointT+elmLen*2, mont1, elmLen);
94
95 /* processing of other windows.. [1],[2],... */
96 for(bit+=window_size, pTbl+=tslot_size; bit<=scalarBitSize; bit+=window_size, pTbl+=tslot_size) {
97 wvalue = *((Ipp16u*)&pScalar8[(bit-1)/8]);
98 wvalue = (wvalue>> ((bit-1)%8)) & mask;
99
100 booth_recode(&sign, &digit, (Ipp8u)wvalue, window_size);
101 select_affine_point(pointT, pTbl, digit);
102
103 negF(negtmp, pointT+elmLen, pGFE);
104 cpMaskedReplace_ct(pointT+elmLen, negtmp, elmLen, ~cpIsZero_ct(sign));
105
106 gfec_affine_point_add(pRdata, pRdata, pointT, pEC);
107 }
108
109 cpEcGFpReleasePool(1, pEC);
110 cpGFpReleasePool(1, pGFE);
111 }
112