5 * Elliptic Curve Arithmetic Functions
7 * Copyright (C) Lenka Fibikova 2000
17 #include <openssl/bn.h>
20 typedef struct bn_ec_struct /* E: y^2 = x^3 + Ax + B (mod p) */
22 BIGNUM *A, *B, *p, *h; /* h = 1/2 mod p = (p + 1)/2 */
26 typedef struct bn_ec_point_struct /* P = [X, Y, Z] */
32 typedef struct bn_ecp_precompute_struct /* Pi[i] = [2i + 1]P i = 0..2^{r-1} - 1 */
39 #define ECP_is_infty(P) (BN_is_zero(P->Z))
40 #define ECP_is_norm(P) (BN_is_one(P->Z))
42 #define ECP_mont_minus(P, mont) (ECP_minus((P), (mont)->p))
46 void EC_clear_free(EC *E);
47 int EC_set_half(EC *E);
49 int EC_to_montgomery(EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);
50 int EC_from_montgomery(EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);
51 #endif /* MONTGOMERY */
55 void ECP_clear_free(EC_POINT *P);
56 void ECP_clear_free_precompute(ECP_PRECOMPUTE *prec);
58 EC_POINT *ECP_generate(BIGNUM *x, BIGNUM *z, EC *E, BN_CTX *ctx);
59 EC_POINT *ECP_dup(EC_POINT *P);
60 int ECP_copy(EC_POINT *R, EC_POINT *P);
61 int ECP_normalize(EC_POINT *P, EC *E, BN_CTX *ctx);
62 EC_POINT *ECP_minus(EC_POINT *P, BIGNUM *p);
63 int ECP_is_on_ec(EC_POINT *P, EC *E, BN_CTX *ctx);
64 int ECP_ecp2bin(EC_POINT *P, unsigned char *to, int form); /* form(ANSI 9.62): 1-compressed; 2-uncompressed; 3-hybrid */
65 int ECP_bin2ecp(unsigned char *from, int len, EC_POINT *P, EC *E, BN_CTX *ctx);
68 int ECP_cmp(EC_POINT *P, EC_POINT *Q, BIGNUM *p, BN_CTX *ctx);
69 int ECP_double(EC_POINT *R, EC_POINT *P, EC *E, BN_CTX *ctx);
70 int ECP_add(EC_POINT *R, EC_POINT *P, EC_POINT *Q, EC *E, BN_CTX *ctx);
71 ECP_PRECOMPUTE *ECP_precompute(int r, EC_POINT *P, EC *E, BN_CTX *ctx);
72 int ECP_multiply(EC_POINT *R, BIGNUM *k, ECP_PRECOMPUTE *prec, EC *E, BN_CTX *ctx);
76 int ECP_to_montgomery(EC_POINT *P, BN_MONTGOMERY *mont, BN_CTX *ctx);
77 int ECP_from_montgomery(EC_POINT *P, BN_MONTGOMERY *mont, BN_CTX *ctx);
78 int ECP_mont_cmp(EC_POINT *P, EC_POINT *Q, BN_MONTGOMERY *mont, BN_CTX *ctx);
79 int ECP_mont_double(EC_POINT *R, EC_POINT *P, EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);
80 int ECP_mont_add(EC_POINT *R, EC_POINT *P, EC_POINT *Q, EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);
81 ECP_PRECOMPUTE *ECP_mont_precompute(int r, EC_POINT *P, EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);
82 int ECP_mont_multiply(EC_POINT *R, BIGNUM *k, ECP_PRECOMPUTE *prec, EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);
83 int ECP_mont_multiply2(EC_POINT *R, BIGNUM *k, EC_POINT *P, EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);
84 #endif /* MONTGOMERY */