ABY Framework  1.0
Arithmetic Bool Yao Framework
 All Classes Files Functions Variables Enumerations Enumerator Macros
ecc-pk-crypto.h
Go to the documentation of this file.
1 
19 #ifndef ECC_PK_CRYPTO_H_
20 #define ECC_PK_CRYPTO_H_
21 
22 #include "pk-crypto.h"
23 
24 #include "../miracl_lib/ecn.h"
25 #include "../miracl_lib/big.h"
26 #include "../miracl_lib/ec2.h"
27 
28 #define fe2ec2(fieldele) (((ecc_fe*) (fieldele))->get_val())
29 #define num2Big(number) (((ecc_num*) (number))->get_val())
30 
31 //how many repetitions of random point samplings should be performed
32 #define MAXMSGSAMPLE 256
33 
34 struct ecc_fparams {
35  Big* BA;
36  Big* BB;
37  Big* X;
38  Big* Y;
39  Big* BP;
40  int32_t m;
41  int32_t a;
42  int32_t b;
43  int32_t c;
44  uint32_t secparam;
45 };
46 
47 class ecc_num;
48 class ecc_fe;
49 class ecc_brickexp;
50 
51 class ecc_field: public pk_crypto {
52 public:
53  ecc_field(seclvl sp, uint8_t* seed) :
54  pk_crypto(sp, seed) {
55  init(sp, seed);
56  }
57  ;
58  ~ecc_field();
59 
60  num* get_num();
61  num* get_rnd_num(uint32_t bitlen = 0);
62  fe* get_fe();
63  fe* get_rnd_fe(uint32_t bitlen);
64  fe* get_generator();
65  fe* get_rnd_generator();
66  uint32_t get_size();
67  //fe* sample_fe_from_bytes(uint8_t* buf, uint32_t bytelen);
68  uint32_t num_byte_size() {
69  return ceil_divide(secparam.ecckcbits, 8);
70  }
71  uint32_t get_field_size() {
72  return secparam.ecckcbits;
73  }
74  ;
75 
76  brickexp* get_brick(fe* gen);
77  ecc_fparams* get_params() {
78  return fparams;
79  }
80  ;
81 
82 protected:
83  void init(seclvl sp, uint8_t* seed);
84 private:
85  fe* sample_random_point();
86  ecc_fparams* fparams;
87 };
88 
89 class ecc_num: public num {
90  //This is a Big
91 public:
92  ecc_num(ecc_field* fld);
93  ecc_num(ecc_field* fld, Big* src);
94  ~ecc_num();
95  void set(num* src);
96  void set_si(int32_t src);
97  void set_add(num* a, num* b);
98  void set_mul(num* a, num* b);
99 
100  Big* get_val();
101 
102  void export_to_bytes(uint8_t* buf, uint32_t field_size_bytes);
103  void import_from_bytes(uint8_t* buf, uint32_t field_size_bytes);
104  void set_rnd(uint32_t bits);
105  void print() {
106  cout << (*val) << endl;
107  }
108  ;
109 
110 private:
111  Big* val;
112  ecc_field* field;
113 };
114 
115 class ecc_fe: public fe {
116 public:
117  ecc_fe(ecc_field* fld);
118  ecc_fe(ecc_field* fld, EC2* src);
119  ~ecc_fe();
120  void set(fe* src);
121  EC2* get_val();
122  void set_mul(fe* a, fe* b);
123 
124  void set_pow(fe* b, num* e);
125  void set_div(fe* a, fe* b);
126  void set_double_pow_mul(fe* b1, num* e1, fe* b2, num* e2);
127  void export_to_bytes(uint8_t* buf);
128  void import_from_bytes(uint8_t* buf);
129  void sample_fe_from_bytes(uint8_t* buf, uint32_t bytelen);
130 
131  void print() {
132  cout << (*val) << endl;
133  }
134  ;
135 
136 private:
137  void init() {
138  val = new EC2();
139  }
140  ;
141  EC2* val;
142  ecc_field* field;
143 };
144 
145 class ecc_brickexp: public brickexp {
146 public:
147  ecc_brickexp(fe* point, ecc_fparams* fparams);
148  ~ecc_brickexp() {
149  ebrick2_end(&br);
150  }
151 
152  void pow(fe* res, num* e);
153 private:
154  ebrick2 br;
155 };
156 
157 void point_to_byte(uint8_t* pBufIdx, uint32_t field_size_bytes, EC2* to_export);
158 void byte_to_point(EC2* to_export, uint32_t field_size_bytes, uint8_t* pBufIdx);
159 
160 #endif /* ECC_PK_CRYPTO_H_ */
Definition: pk-crypto.h:77
Definition: ecc-pk-crypto.h:145
Definition: pk-crypto.h:99
Definition: pk-crypto.h:59
Definition: pk-crypto.h:30
Definition: ecc-pk-crypto.h:115
Virtual class for public-key operations.
Definition: ecc-pk-crypto.h:34
Definition: ecc-pk-crypto.h:51
Definition: typedefs.h:79
Definition: ecc-pk-crypto.h:89