• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*############################################################################
2 # Copyright 2017 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 /// Definition of math types in tiny Intel(R) EPID.
17 /*! \file */
18 
19 #ifndef EPID_MEMBER_TINY_MATH_MATHTYPES_H_
20 #define EPID_MEMBER_TINY_MATH_MATHTYPES_H_
21 
22 /// number of 32bit words in a very large integer
23 #define NUM_ECC_DIGITS 8
24 
25 #include <stdint.h>
26 
27 /// Large integer.
28 /*!
29 VeryLargeInt* is always expected to point to a buffer
30 with NUM_ECC_DIGITS uint32_t sized words.
31 */
32 typedef struct VeryLargeInt {
33   uint32_t word[NUM_ECC_DIGITS];  ///< Large integer data
34 } VeryLargeInt;
35 
36 /// Used for multiplication
37 typedef struct VeryLargeIntProduct {
38   uint32_t word[2 * NUM_ECC_DIGITS];  ///< Large integer data
39 } VeryLargeIntProduct;
40 
41 /// Element of Fp.
42 typedef struct FpElem {
43   VeryLargeInt limbs;  ///< An integer in [0, p-1]
44 } FpElem;
45 
46 /// Element of Fq.
47 typedef struct FqElem {
48   VeryLargeInt limbs;  ///< An integer in [0, q-1]
49 } FqElem;
50 
51 /// Element of Fq2.
52 typedef struct Fq2Elem {
53   FqElem x0;  ///< A coefficent in Fq
54   FqElem x1;  ///< A coefficent in Fq
55 } Fq2Elem;
56 
57 /// Point in EFq.
58 typedef struct EccPointFq {
59   FqElem x;  ///< x coordinate
60   FqElem y;  ///< y coordinate
61 } EccPointFq;
62 
63 /// Point in EFq2.
64 typedef struct EccPointFq2 {
65   Fq2Elem x;  ///< x coordinate
66   Fq2Elem y;  ///< y coordinate
67 } EccPointFq2;
68 
69 /// Element of Fq6.
70 typedef struct Fq6Elem {
71   Fq2Elem y0;  ///< A coefficent in Fq2
72   Fq2Elem y1;  ///< A coefficent in Fq2
73   Fq2Elem y2;  ///< A coefficent in Fq2
74 } Fq6Elem;
75 
76 /// Element of Fq12.
77 typedef struct Fq12Elem {
78   Fq6Elem z0;  ///< A coefficent in Fq6
79   Fq6Elem z1;  ///< A coefficent in Fq6
80 } Fq12Elem;
81 
82 /// Element of EFq in Jacobi format.
83 typedef struct EccPointJacobiFq {
84   FqElem X;  ///< x coordinate
85   FqElem Y;  ///< y coordinate
86   FqElem Z;  ///< z coordinate
87 } EccPointJacobiFq;
88 
89 /// Element of EFq2 in Jacobi format.
90 typedef struct EccPointJacobiFq2 {
91   Fq2Elem X;  ///< x coordinate
92   Fq2Elem Y;  ///< y coordinate
93   Fq2Elem Z;  ///< z coordinate
94 } EccPointJacobiFq2;
95 
96 /// A scratch buffer for stateful pairing calls.
97 typedef struct PairingState {
98   Fq2Elem g[3][5];  ///< pairing scratch data
99 } PairingState;
100 
101 #endif  // EPID_MEMBER_TINY_MATH_MATHTYPES_H_
102