HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_ECurve.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_ECurve.h ( UT Library, C++)
7  *
8  * COMMENTS: Defines an elliptic curve over a binary Galois field -- GF(2^m)
9  * Useful for cryptography.
10  */
11 
12 #ifndef __UT_ECurve__
13 #define __UT_ECurve__
14 
15 #include "UT_API.h"
16 #include <SYS/SYS_Types.h>
17 #include "UT_VeryLong.h"
18 #include "UT_PolyField.h"
19 
20 #define UT_ECURVE_MAXBASIS 6
21 
23 {
24 public:
25  UT_ECurve() { myBits = 0; }
26  UT_ECurve(const uint q[],
27  const char *r,
28  const char *a,
29  const char *b,
30  const char *gx,
31  const char *gy)
32  {
33  setQ(q);
34  myR = r;
35  myA = a;
36  myB = b;
37  myGx = gx;
38  myGy = gy;
39  computeBits();
40  }
41 
42  void setQ(const uint q[])
43  {
44  int i;
45  UT_VeryLong shift;
46  myQ = 1u;
47  for (i = 0; q[i]; i++)
48  {
49  myBasis[i] = q[i];
50  shift = 1;
51  shift <<= q[i];
52  myQ += shift;
53  }
54  myBasis[i] = 1;
55  for (i = i+1; i < UT_ECURVE_MAXBASIS; i++)
56  myBasis[i] = 0;
57  }
58  void setR(int x) { myR = x; computeBits(); }
59  void setR(const char *x) { myR = x; computeBits(); }
60  void setR(const UT_VeryLong &x) { myR = x; computeBits(); }
61  void setA(int x) { myA = x; }
62  void setA(const char *x) { myA = x; }
63  void setA(const UT_PolyField &x) { myA = x; }
64  void setB(int x) { myB = x; }
65  void setB(const char *x) { myB = x; }
66  void setB(const UT_PolyField &x) { myB = x; }
67  void setGx(int x) { myGx = x; }
68  void setGx(const char *x) { myGx = x; }
69  void setGx(const UT_PolyField &x) { myGx = x; }
70  void setGy(int x) { myGy = x; }
71  void setGy(const char *x) { myGy = x; }
72  void setGy(const UT_PolyField &x) { myGy = x; }
73 
74  const UT_VeryLong &getR() const { return myR; }
75  const UT_PolyField &getQ() const { return myQ; }
76  const UT_PolyField &getA() const { return myA; }
77  const UT_PolyField &getB() const { return myB; }
78  const UT_PolyField &getGx() const { return myGx; }
79  const UT_PolyField &getGy() const { return myGy; }
80 
81  // ECC methods
82  void generateRandom(UT_VeryLong &r,
83  const uint *seed, uint seedlen) const;
84  bool generateRandomRaw(UT_VeryLong &r,
85  const uint *seed, uint len) const;
86  void generatePublic(UT_PolyField &pubx, UT_PolyField &puby,
87  const UT_VeryLong &key) const;
88 
89  // Create a digital signature for m with a random key r and return the
90  // result in codea/codeb. If the encoding failed, return 0
91  bool dsa(UT_VeryLong &acode, UT_VeryLong &bcode,
92  const UT_VeryLong &key, const UT_VeryLong &r,
93  const UT_VeryLong &m) const;
94 
95  void partialDSA(UT_VeryLong &code,
96  const UT_VeryLong &key, const UT_VeryLong &rnd) const;
97 
98  // Verify the digital signature of m given codea/codeb
99  bool verify(const UT_VeryLong &m,
100  const UT_VeryLong &code, const UT_VeryLong &codeb,
101  const UT_PolyField &pubx, const UT_PolyField &puby) const;
102 
103  void dump(int base=16) const;
104 
105 private:
106  void computeBits();
107  void mult(UT_PolyField &x, UT_PolyField &y,
108  const UT_VeryLong &m) const
109  {
110  mult(x, y, m, myGx, myGy);
111  }
112  void mult(UT_PolyField &x, UT_PolyField &y, const UT_VeryLong &m,
113  const UT_PolyField &gx, const UT_PolyField &gy) const;
114 
115  void curveDouble(UT_PolyField &x, UT_PolyField &y) const;
116  void curveAdd(UT_PolyField &dx, UT_PolyField &dy,
117  const UT_PolyField &sx, const UT_PolyField &sy,
118  const UT_PolyField &gx, const UT_PolyField &gy) const;
119 
120  UT_VeryLong myR;
121  UT_PolyField myQ;
122  UT_PolyField myA, myB;
123  UT_PolyField myGx, myGy;
124  int myBits;
125  int myBasis[6];
126 };
127 
128 #endif
129 
const UT_PolyField & getB() const
Definition: UT_ECurve.h:77
void setGy(int x)
Definition: UT_ECurve.h:70
void setB(const char *x)
Definition: UT_ECurve.h:65
const UT_PolyField & getA() const
Definition: UT_ECurve.h:76
void setGy(const char *x)
Definition: UT_ECurve.h:71
#define UT_ECURVE_MAXBASIS
Definition: UT_ECurve.h:20
void setB(const UT_PolyField &x)
Definition: UT_ECurve.h:66
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
const UT_PolyField & getGx() const
Definition: UT_ECurve.h:78
void setA(const UT_PolyField &x)
Definition: UT_ECurve.h:63
#define UT_API
Definition: UT_API.h:14
UT_ECurve()
Definition: UT_ECurve.h:25
void setR(const char *x)
Definition: UT_ECurve.h:59
GLint y
Definition: glcorearb.h:103
GLdouble GLdouble GLdouble q
Definition: glad.h:2445
void setR(const UT_VeryLong &x)
Definition: UT_ECurve.h:60
void setR(int x)
Definition: UT_ECurve.h:58
void setQ(const uint q[])
Definition: UT_ECurve.h:42
const UT_PolyField & getGy() const
Definition: UT_ECurve.h:79
void setGx(const UT_PolyField &x)
Definition: UT_ECurve.h:69
const UT_PolyField & getQ() const
Definition: UT_ECurve.h:75
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
void setA(int x)
Definition: UT_ECurve.h:61
GT_Basis myBasis
Definition: GT_CurveEval.h:262
void setA(const char *x)
Definition: UT_ECurve.h:62
GLboolean r
Definition: glcorearb.h:1222
void setGy(const UT_PolyField &x)
Definition: UT_ECurve.h:72
void setB(int x)
Definition: UT_ECurve.h:64
unsigned int uint
Definition: SYS_Types.h:45
const UT_VeryLong & getR() const
Definition: UT_ECurve.h:74
UT_ECurve(const uint q[], const char *r, const char *a, const char *b, const char *gx, const char *gy)
Definition: UT_ECurve.h:26
void setGx(const char *x)
Definition: UT_ECurve.h:68
void setGx(int x)
Definition: UT_ECurve.h:67