github.com/jiajun1992/watercarver@v0.0.0-20191031150618-dfc2b17c0c4a/StadiumForWaterCarver/src/edgamal.h (about) 1 #ifndef EDGAMAL_H 2 #define EDGAMAL_H 3 4 // everything is static so the idea is to inline everything (or at least keep it module-private) 5 6 // forward declarations (subject to change) 7 8 #include "edgamal_internal_decl.h" 9 10 // API 11 12 #define EDGAMAL_CURVE_SCALAR_SIZE 32 13 typedef uint8_t edgamal_curve_scalar[EDGAMAL_CURVE_SCALAR_SIZE]; 14 15 // typedef <OPAQUE> edgamal_curve_point; 16 #define EDGAMAL_CURVE_POINT_SIZE sizeof(edgamal_curve_point) 17 18 // these are defined in edgamal_internal_impl.h 19 // static const edgamal_curve_point edgamal_basepoint; 20 // static const edgamal_curve_point edgamal_zeropoint; 21 22 static inline void edgamal_copy_point(edgamal_curve_point *out, const edgamal_curve_point *in); 23 24 static inline int edgamal_compare_scalars(const edgamal_curve_scalar a, const edgamal_curve_scalar b); 25 static inline int edgamal_compare_points(const edgamal_curve_point *a, const edgamal_curve_point *b); 26 27 static inline void edgamal_compress_point(uint8_t out[32], const edgamal_curve_point *in); 28 static inline void edgamal_decompress_point(edgamal_curve_point *out, const uint8_t in[32]); 29 30 static inline void edgamal_serialize_point(uint8_t out[128], const edgamal_curve_point *in); 31 static inline void edgamal_deserialize_point(edgamal_curve_point *out, const uint8_t in[128]); 32 33 static inline void edgamal_random_scalar(edgamal_curve_scalar s); 34 static inline void edgamal_random_point(edgamal_curve_point *p); 35 static inline void edgamal_random_pair(edgamal_curve_scalar s, edgamal_curve_point *p); 36 37 static inline void edgamal_add_scalars(edgamal_curve_scalar out, const edgamal_curve_scalar a, const edgamal_curve_scalar b); 38 static inline void edgamal_multiply_scalars(edgamal_curve_scalar out, const edgamal_curve_scalar a, const edgamal_curve_scalar b); 39 40 static inline void edgamal_add_points(edgamal_curve_point *out, const edgamal_curve_point *a, const edgamal_curve_point *b); 41 static inline void edgamal_double_point(edgamal_curve_point *out, const edgamal_curve_point *in); 42 static inline void edgamal_negate_point(edgamal_curve_point *out, const edgamal_curve_point *in); 43 static inline void edgamal_scalar_multiply_point(edgamal_curve_point *out, const edgamal_curve_point *base, const edgamal_curve_scalar exponent); 44 static inline void edgamal_scalar_multiply_basepoint(edgamal_curve_point *out, const edgamal_curve_scalar exponent); 45 46 // debug (subject to change) 47 48 // static inline void edgamal_print_point(const edgamal_curve_point *p); 49 // static inline void edgamal_print_point_packed(const edgamal_curve_point *p); 50 51 // internals (very subject to change) 52 53 #include "edgamal_internal_impl.h" 54 55 #endif