ec.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef _EC_H
  2. #define _EC_H
  3. #include "common.h"
  4. #include "mont.h"
  5. #include "modexp_utils.h"
  6. typedef struct {
  7. uint64_t *a, *b, *c, *d, *e, *f, *g, *h, *i, *j, *k;
  8. uint64_t *scratch;
  9. } Workplace;
  10. /*
  11. * The description of a short Weierstrass curve, with y²=x³-3x+b
  12. */
  13. typedef struct _EcContext {
  14. MontContext *mont_ctx;
  15. uint64_t *b; /* encoded in Montgomery form */
  16. uint64_t *order; /* big-endian plain form */
  17. ProtMemory **prot_g; /* optional pre-computed tables for generator */
  18. } EcContext;
  19. /*
  20. * An EC point in Jacobian coordinates
  21. */
  22. typedef struct _EcPoint {
  23. const EcContext *ec_ctx;
  24. uint64_t *x;
  25. uint64_t *y;
  26. uint64_t *z;
  27. } EcPoint;
  28. EXPORT_SYM int ec_ws_new_context(EcContext **pec_ctx,
  29. const uint8_t *modulus,
  30. const uint8_t *b,
  31. const uint8_t *order,
  32. size_t len,
  33. uint64_t seed);
  34. EXPORT_SYM void ec_free_context(EcContext *ec_ctx);
  35. EXPORT_SYM int ec_ws_new_point(EcPoint **pecp,
  36. const uint8_t *x,
  37. const uint8_t *y,
  38. size_t len,
  39. const EcContext *ec_ctx);
  40. EXPORT_SYM void ec_free_point(EcPoint *ecp);
  41. EXPORT_SYM int ec_ws_get_xy(uint8_t *x,
  42. uint8_t *y,
  43. size_t len,
  44. const EcPoint *ecp);
  45. EXPORT_SYM int ec_ws_double(EcPoint *p);
  46. EXPORT_SYM int ec_ws_add(EcPoint *ecpa,
  47. EcPoint *ecpb);
  48. EXPORT_SYM int ec_ws_scalar(EcPoint *ecp,
  49. const uint8_t *k,
  50. size_t len,
  51. uint64_t seed);
  52. EXPORT_SYM int ec_ws_clone(EcPoint **pecp2, const EcPoint *ecp);
  53. EXPORT_SYM int ec_ws_copy(EcPoint *ecp1, const EcPoint *ecp2);
  54. EXPORT_SYM int ec_ws_cmp(const EcPoint *ecp1, const EcPoint *ecp2);
  55. EXPORT_SYM int ec_ws_neg(EcPoint *p);
  56. EXPORT_SYM int ec_ws_normalize(EcPoint *ecp);
  57. EXPORT_SYM int ec_ws_is_pai(EcPoint *ecp);
  58. #endif