• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2 * Copyright 2017-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 #if !defined(_GS_MOD_METHOD_H)
42 #define _GS_MOD_METHOD_H
43 
44 //#include "owndefs.h"
45 #include "owncp.h"
46 
47 #include "pcpbnuimpl.h"
48 //#include "gsmodstuff.h"
49 
50 typedef struct _gsModEngine gsEngine;
51 
52 /* modular arith methods */
53 typedef BNU_CHUNK_T* (*mod_encode)(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, gsEngine* pMA);
54 typedef BNU_CHUNK_T* (*mod_decode)(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, gsEngine* pMA);
55 typedef BNU_CHUNK_T* (*mod_red)   (BNU_CHUNK_T* pR,       BNU_CHUNK_T* pA, gsEngine* pMA);
56 typedef BNU_CHUNK_T* (*mod_sqr)   (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, gsEngine* pMA);
57 typedef BNU_CHUNK_T* (*mod_mul)   (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, gsEngine* pMA);
58 typedef BNU_CHUNK_T* (*mod_add)   (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, gsEngine* pMA);
59 typedef BNU_CHUNK_T* (*mod_sub)   (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, gsEngine* pMA);
60 typedef BNU_CHUNK_T* (*mod_neg)   (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, gsEngine* pMA);
61 typedef BNU_CHUNK_T* (*mod_div2)  (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, gsEngine* pMA);
62 typedef BNU_CHUNK_T* (*mod_mul2)  (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, gsEngine* pMA);
63 typedef BNU_CHUNK_T* (*mod_mul3)  (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, gsEngine* pMA);
64 
65 typedef struct _gsModMethod {
66    mod_encode encode;
67    mod_decode decode;
68    mod_mul  mul;
69    mod_sqr  sqr;
70    mod_red  red;
71    mod_add  add;
72    mod_sub  sub;
73    mod_neg  neg;
74    mod_div2 div2;
75    mod_mul2 mul2;
76    mod_mul3 mul3;
77 } gsModMethod;
78 
cpIsZero(BNU_CHUNK_T x)79 __INLINE BNU_CHUNK_T cpIsZero(BNU_CHUNK_T x)
80 {  return x==0; }
cpIsNonZero(BNU_CHUNK_T x)81 __INLINE BNU_CHUNK_T cpIsNonZero(BNU_CHUNK_T x)
82 {  return x!=0; }
cpIsOdd(BNU_CHUNK_T x)83 __INLINE BNU_CHUNK_T cpIsOdd(BNU_CHUNK_T x)
84 {  return x&1; }
cpIsEven(BNU_CHUNK_T x)85 __INLINE BNU_CHUNK_T cpIsEven(BNU_CHUNK_T x)
86 {  return 1-cpIsOdd(x); }
87 
88 /* dst[] = (flag)? src[] : dst[] */
cpMaskMove_gs(BNU_CHUNK_T * dst,const BNU_CHUNK_T * src,int len,BNU_CHUNK_T moveFlag)89 __INLINE void cpMaskMove_gs(BNU_CHUNK_T* dst, const BNU_CHUNK_T* src, int len, BNU_CHUNK_T moveFlag)
90 {
91    BNU_CHUNK_T srcMask = 0-cpIsNonZero(moveFlag);
92    BNU_CHUNK_T dstMask = ~srcMask;
93    int n;
94    for(n=0; n<len; n++)
95       dst[n] = (src[n] & srcMask) ^  (dst[n] & dstMask);
96 }
97 
98 /* common available pre-defined methos */
99 #define      gsModArith OWNAPI(gsModArith)
100 gsModMethod* gsModArith(void);
101 
102 /* available pre-defined methos for RSA */
103 #define      gsModArithRSA OWNAPI(gsModArithRSA)
104 gsModMethod* gsModArithRSA(void);
105 
106 /* available pre-defined methos for ippsMont* */
107 #define      gsModArithMont OWNAPI(gsModArithMont)
108 gsModMethod* gsModArithMont(void);
109 
110 /* available pre-defined methos for DLP * */
111 #define      gsModArithDLP OWNAPI(gsModArithDLP)
112 gsModMethod* gsModArithDLP(void);
113 
114 /* available pre-defined common methos for GF over prime * */
115 #define      gsArithGFp OWNAPI(gsArithGFp)
116 gsModMethod* gsArithGFp(void);
117 
118 /* ... and etc ... */
119 
120 #endif /* _GS_MOD_METHOD_H */
121 
122