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 public:
24  UT_ECurve() { myBits = 0; }
25  UT_ECurve(const uint q[],
26  const char *r,
27  const char *a,
28  const char *b,
29  const char *gx,
30  const char *gy)
31  {
32  setQ(q);
33  myR = r;
34  myA = a;
35  myB = b;
36  myGx = gx;
37  myGy = gy;
38  computeBits();
39  }
40 
41  void setQ(const uint q[])
42  {
43  int i;
44  UT_VeryLong shift;
45  myQ = 1u;
46  for (i = 0; q[i]; i++)
47  {
48  myBasis[i] = q[i];
49  shift = 1;
50  shift <<= q[i];
51  myQ += shift;
52  }
53  myBasis[i] = 1;
54  for (i = i+1; i < UT_ECURVE_MAXBASIS; i++)
55  myBasis[i] = 0;
56  }
57  void setR(int x) { myR = x; computeBits(); }
58  void setR(const char *x) { myR = x; computeBits(); }
59  void setR(const UT_VeryLong &x) { myR = x; computeBits(); }
60  void setA(int x) { myA = x; }
61  void setA(const char *x) { myA = x; }
62  void setA(const UT_PolyField &x) { myA = x; }
63  void setB(int x) { myB = x; }
64  void setB(const char *x) { myB = x; }
65  void setB(const UT_PolyField &x) { myB = x; }
66  void setGx(int x) { myGx = x; }
67  void setGx(const char *x) { myGx = x; }
68  void setGx(const UT_PolyField &x) { myGx = x; }
69  void setGy(int x) { myGy = x; }
70  void setGy(const char *x) { myGy = x; }
71  void setGy(const UT_PolyField &x) { myGy = x; }
72 
73  const UT_VeryLong &getR() const { return myR; }
74  const UT_PolyField &getQ() const { return myQ; }
75  const UT_PolyField &getA() const { return myA; }
76  const UT_PolyField &getB() const { return myB; }
77  const UT_PolyField &getGx() const { return myGx; }
78  const UT_PolyField &getGy() const { return myGy; }
79 
80  // ECC methods
81  void generateRandom(UT_VeryLong &r,
82  const uint *seed, uint seedlen) const;
83  bool generateRandomRaw(UT_VeryLong &r,
84  const uint *seed, uint len) const;
85  void generatePublic(UT_PolyField &pubx, UT_PolyField &puby,
86  const UT_VeryLong &key) const;
87 
88  // Create a digital signature for m with a random key r and return the
89  // result in codea/codeb. If the encoding failed, return 0
90  bool dsa(UT_VeryLong &acode, UT_VeryLong &bcode,
91  const UT_VeryLong &key, const UT_VeryLong &r,
92  const UT_VeryLong &m) const;
93 
94  void partialDSA(UT_VeryLong &code,
95  const UT_VeryLong &key, const UT_VeryLong &rnd) const;
96 
97  // Verify the digital signature of m given codea/codeb
98  bool verify(const UT_VeryLong &m,
99  const UT_VeryLong &code, const UT_VeryLong &codeb,
100  const UT_PolyField &pubx, const UT_PolyField &puby) const;
101 
102  void dump(int base=16) const;
103 
104 private:
105  void computeBits();
106  void mult(UT_PolyField &x, UT_PolyField &y,
107  const UT_VeryLong &m) const
108  {
109  mult(x, y, m, myGx, myGy);
110  }
111  void mult(UT_PolyField &x, UT_PolyField &y, const UT_VeryLong &m,
112  const UT_PolyField &gx, const UT_PolyField &gy) const;
113 
114  void curveDouble(UT_PolyField &x, UT_PolyField &y) const;
115  void curveAdd(UT_PolyField &dx, UT_PolyField &dy,
116  const UT_PolyField &sx, const UT_PolyField &sy,
117  const UT_PolyField &gx, const UT_PolyField &gy) const;
118 
119  UT_VeryLong myR;
120  UT_PolyField myQ;
121  UT_PolyField myA, myB;
122  UT_PolyField myGx, myGy;
123  int myBits;
124  int myBasis[6];
125 };
126 
127 #endif
128 
const UT_PolyField & getB() const
Definition: UT_ECurve.h:76
void setGy(int x)
Definition: UT_ECurve.h:69
void setB(const char *x)
Definition: UT_ECurve.h:64
const UT_PolyField & getA() const
Definition: UT_ECurve.h:75
void setGy(const char *x)
Definition: UT_ECurve.h:70
#define UT_ECURVE_MAXBASIS
Definition: UT_ECurve.h:20
void setB(const UT_PolyField &x)
Definition: UT_ECurve.h:65
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
const UT_PolyField & getGx() const
Definition: UT_ECurve.h:77
void setA(const UT_PolyField &x)
Definition: UT_ECurve.h:62
#define UT_API
Definition: UT_API.h:14
UT_ECurve()
Definition: UT_ECurve.h:24
void setR(const char *x)
Definition: UT_ECurve.h:58
GLint y
Definition: glcorearb.h:103
GLdouble GLdouble GLdouble q
Definition: glad.h:2445
void setR(const UT_VeryLong &x)
Definition: UT_ECurve.h:59
void setR(int x)
Definition: UT_ECurve.h:57
void setQ(const uint q[])
Definition: UT_ECurve.h:41
const UT_PolyField & getGy() const
Definition: UT_ECurve.h:78
void setGx(const UT_PolyField &x)
Definition: UT_ECurve.h:68
const UT_PolyField & getQ() const
Definition: UT_ECurve.h:74
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
void setA(int x)
Definition: UT_ECurve.h:60
GT_Basis myBasis
Definition: GT_CurveEval.h:262
void setA(const char *x)
Definition: UT_ECurve.h:61
GLboolean r
Definition: glcorearb.h:1222
void setGy(const UT_PolyField &x)
Definition: UT_ECurve.h:71
void setB(int x)
Definition: UT_ECurve.h:63
unsigned int uint
Definition: SYS_Types.h:45
const UT_VeryLong & getR() const
Definition: UT_ECurve.h:73
UT_ECurve(const uint q[], const char *r, const char *a, const char *b, const char *gx, const char *gy)
Definition: UT_ECurve.h:25
void setGx(const char *x)
Definition: UT_ECurve.h:67
void setGx(int x)
Definition: UT_ECurve.h:66