1 /*******************************************************************************
2 * Copyright 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 // Intel(R) Integrated Performance Primitives. Cryptography Primitives.
43 // internal functions for GF(p^d) methods, if binomial generator
44 // with Intel(R) Enhanced Privacy ID (Intel(R) EPID) 2.0 specific
45 //
46 */
47 #include "owncp.h"
48
49 #include "pcpgfpxstuff.h"
50 #include "pcpgfpxmethod_com.h"
51
52 //tbcd: temporary excluded: #include <assert.h>
53
54 /*
55 // Intel(R) EPID 2.0 specific.
56 //
57 // Intel(R) EPID 2.0 uses the following finite field hierarchy:
58 //
59 // 1) prime field GF(p),
60 // p = 0xFFFFFFFFFFFCF0CD46E5F25EEE71A49F0CDC65FB12980A82D3292DDBAED33013
61 //
62 // 2) 2-degree extension of GF(p): GF(p^2) == GF(p)[x]/g(x), g(x) = x^2 -beta,
63 // beta =-1 mod p, so "beta" represents as {1}
64 //
65 // 3) 3-degree extension of GF(p^2) ~ GF(p^6): GF((p^2)^3) == GF(p)[v]/g(v), g(v) = v^3 -xi,
66 // xi belongs GF(p^2), xi=x+2, so "xi" represents as {2,1} ---- "2" is low- and "1" is high-order coefficients
67 //
68 // 4) 2-degree extension of GF((p^2)^3) ~ GF(p^12): GF(((p^2)^3)^2) == GF(p)[w]/g(w), g(w) = w^2 -vi,
69 // psi belongs GF((p^2)^3), vi=0*v^2 +1*v +0, so "vi" represents as {0,1,0}---- "0", '1" and "0" are low-, middle- and high-order coefficients
70 //
71 // See representations in t_gfpparam.cpp
72 //
73 */
74
75 /*
76 // Multiplication case: mul(a, xi) over GF(p^2),
77 // where:
78 // a, belongs to GF(p^2)
79 // xi belongs to GF(p^2), xi={2,1}
80 //
81 // The case is important in GF((p^2)^3) arithmetic for Intel(R) EPID 2.0.
82 //
83 */
cpFq2Mul_xi(BNU_CHUNK_T * pR,const BNU_CHUNK_T * pA,gsEngine * pGFEx)84 __INLINE BNU_CHUNK_T* cpFq2Mul_xi(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, gsEngine* pGFEx)
85 {
86 gsEngine* pGroundGFE = GFP_PARENT(pGFEx);
87 mod_mul addF = GFP_METHOD(pGroundGFE)->add;
88 mod_sub subF = GFP_METHOD(pGroundGFE)->sub;
89
90 int termLen = GFP_FELEN(pGroundGFE);
91 BNU_CHUNK_T* t0 = cpGFpGetPool(2, pGroundGFE);
92 BNU_CHUNK_T* t1 = t0+termLen;
93
94 const BNU_CHUNK_T* pA0 = pA;
95 const BNU_CHUNK_T* pA1 = pA+termLen;
96 BNU_CHUNK_T* pR0 = pR;
97 BNU_CHUNK_T* pR1 = pR+termLen;
98
99 //tbcd: temporary excluded: assert(NULL!=t0);
100 addF(t0, pA0, pA0, pGroundGFE);
101 addF(t1, pA0, pA1, pGroundGFE);
102 subF(pR0, t0, pA1, pGroundGFE);
103 addF(pR1, t1, pA1, pGroundGFE);
104
105 cpGFpReleasePool(2, pGroundGFE);
106 return pR;
107 }
108
109 /*
110 // Multiplication case: mul(a, g0) over GF(()),
111 // where:
112 // a and g0 belongs to GF(()) - field is being extension
113 //
114 // The case is important in GF(()^d) arithmetic if constructed polynomial is generic binomial g(t) = t^d +g0.
115 //
116 */
cpGFpxMul_G0(BNU_CHUNK_T * pR,const BNU_CHUNK_T * pA,gsEngine * pGFEx)117 static BNU_CHUNK_T* cpGFpxMul_G0(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, gsEngine* pGFEx)
118 {
119 gsEngine* pGroundGFE = GFP_PARENT(pGFEx);
120 BNU_CHUNK_T* pGFpolynomial = GFP_MODULUS(pGFEx); /* g(x) = t^d + g0 */
121 return GFP_METHOD(pGroundGFE)->mul(pR, pA, pGFpolynomial, pGroundGFE);
122 }
123