123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- #ifndef ECC_PK_CRYPTO_H_
- #define ECC_PK_CRYPTO_H_
- #include "pk-crypto.h"
- extern "C"
- {
- #include <relic.h>
- }
- #include <memory>
- #include <vector>
- #include <mutex>
- class ecc_num;
- class ecc_fe;
- class ecc_brickexp;
- static std::mutex relic_mutex;
- class ecc_field: public pk_crypto {
- public:
- ecc_field(seclvl sp, uint8_t* seed) :
- pk_crypto(sp) {
- init(sp, seed);
- };
- ~ecc_field();
- num* get_num();
- num* get_rnd_num(uint32_t bitlen = 0);
- fe* get_fe();
- fe* get_rnd_fe();
- fe* get_generator();
- fe* get_rnd_generator();
- uint32_t get_size();
-
- num* get_order();
- uint32_t num_byte_size();
- uint32_t get_field_size();
- brickexp* get_brick(fe* gen);
- ctx_t* get_context();
- protected:
- void init(seclvl sp, uint8_t* seed);
- private:
- fe* sample_random_point();
- ecc_fe* generator;
- ctx_t* context;
- };
- class ecc_num: public num {
- public:
- ecc_num(ecc_field* fld);
- ecc_num(ecc_field* fld, bn_t src);
- ~ecc_num();
- void set(num* src);
- void set_si(int32_t src);
- void set_add(num* a, num* b);
- void set_sub(num* a, num* b);
- void set_mul(num* a, num* b);
- void mod(num* mod);
- void set_mul_mod(num* a, num* b, num* modulus) ;
- void get_val(bn_t res);
- void export_to_bytes(uint8_t* buf, uint32_t field_size_bytes);
- void import_from_bytes(uint8_t* buf, uint32_t field_size_bytes);
-
- void print();
- private:
- void shallow_copy(bn_t to, bn_t from);
- bn_t val;
- ecc_field* field;
- ctx_t* context;
- };
- class ecc_fe: public fe {
- public:
- ecc_fe(ecc_field* fld);
- ecc_fe(ecc_field* fld, eb_t src);
- ~ecc_fe();
- void set(fe* src);
- void get_val(eb_t res);
- void set_mul(fe* a, fe* b);
- void set_pow(fe* b, num* e);
- void set_div(fe* a, fe* b);
- void set_double_pow_mul(fe* b1, num* e1, fe* b2, num* e2);
- void export_to_bytes(uint8_t* buf);
- void import_from_bytes(uint8_t* buf);
- void sample_fe_from_bytes(uint8_t* buf, uint32_t bytelen);
- bool eq(fe* a);
- void print();
- private:
- void init();
- void shallow_copy(eb_t to, eb_t from);
- eb_t val;
- ecc_field* field;
- ctx_t* context;
- };
- class ecc_brickexp: public brickexp {
- public:
- ecc_brickexp(fe* generator, ecc_field* field);
- ~ecc_brickexp();
- void pow(fe* res, num* e);
- private:
- uint32_t eb_pre_size;
- eb_t* eb_table;
- ecc_field* field;
- ctx_t* context;
- };
- #endif
|