]>
Commit | Line | Data |
---|---|---|
7e0c5264 BM |
1 | /*\r |
2 | *\r | |
3 | * ec.h\r | |
4 | *\r | |
5 | * Elliptic Curve Arithmetic Functions\r | |
6 | *\r | |
7 | * Copyright (C) Lenka Fibikova 2000\r | |
8 | *\r | |
9 | *\r | |
10 | */\r | |
11 | \r | |
12 | \r | |
13 | #ifndef HEADER_EC_H\r | |
14 | #define HEADER_EC_H\r | |
15 | \r | |
16 | \r | |
17 | #include "bn.h"\r | |
18 | #include "bn_mont2.h"\r | |
19 | \r | |
20 | typedef struct bn_ec_struct /* E: y^2 = x^3 + Ax + B (mod p) */\r | |
21 | {\r | |
22 | BIGNUM *A, *B, *p, *h; /* h = 1/2 mod p = (p + 1)/2 */\r | |
23 | int is_in_mont;\r | |
24 | } EC;\r | |
25 | \r | |
26 | typedef struct bn_ec_point_struct /* P = [X, Y, Z] */\r | |
27 | {\r | |
28 | BIGNUM *X, *Y, *Z;\r | |
29 | int is_in_mont;\r | |
30 | } EC_POINT;\r | |
31 | \r | |
32 | typedef struct bn_ecp_precompute_struct /* Pi[i] = [2i + 1]P i = 0..2^{r-1} - 1 */\r | |
33 | {\r | |
34 | int r;\r | |
35 | EC_POINT **Pi;\r | |
36 | } ECP_PRECOMPUTE;\r | |
37 | \r | |
38 | \r | |
39 | #define ECP_is_infty(P) (BN_is_zero(P->Z))\r | |
40 | #define ECP_is_norm(P) (BN_is_one(P->Z))\r | |
41 | \r | |
42 | #define ECP_mont_minus(P, mont) (ECP_minus((P), (mont)->p))\r | |
43 | \r | |
44 | \r | |
45 | EC *EC_new();\r | |
46 | void EC_clear_free(EC *E);\r | |
47 | int EC_set_half(EC *E);\r | |
48 | #ifdef MONTGOMERY\r | |
49 | int EC_to_montgomery(EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);\r | |
50 | int EC_from_montgomery(EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);\r | |
51 | #endif /* MONTGOMERY */\r | |
52 | \r | |
53 | \r | |
54 | EC_POINT *ECP_new();\r | |
55 | void ECP_clear_free(EC_POINT *P);\r | |
56 | void ECP_clear_free_precompute(ECP_PRECOMPUTE *prec);\r | |
57 | \r | |
58 | EC_POINT *ECP_generate(BIGNUM *x, BIGNUM *z, EC *E, BN_CTX *ctx);\r | |
59 | EC_POINT *ECP_dup(EC_POINT *P);\r | |
60 | int ECP_copy(EC_POINT *R, EC_POINT *P);\r | |
61 | int ECP_normalize(EC_POINT *P, EC *E, BN_CTX *ctx);\r | |
62 | EC_POINT *ECP_minus(EC_POINT *P, BIGNUM *p);\r | |
63 | int ECP_is_on_ec(EC_POINT *P, EC *E, BN_CTX *ctx);\r | |
64 | int ECP_ecp2bin(EC_POINT *P, unsigned char *to, int form); /* form(ANSI 9.62): 1-compressed; 2-uncompressed; 3-hybrid */\r | |
65 | int ECP_bin2ecp(unsigned char *from, int len, EC_POINT *P, EC *E, BN_CTX *ctx);\r | |
66 | \r | |
67 | #ifdef SIMPLE\r | |
68 | int ECP_cmp(EC_POINT *P, EC_POINT *Q, BIGNUM *p, BN_CTX *ctx);\r | |
69 | int ECP_double(EC_POINT *R, EC_POINT *P, EC *E, BN_CTX *ctx);\r | |
70 | int ECP_add(EC_POINT *R, EC_POINT *P, EC_POINT *Q, EC *E, BN_CTX *ctx);\r | |
71 | ECP_PRECOMPUTE *ECP_precompute(int r, EC_POINT *P, EC *E, BN_CTX *ctx);\r | |
72 | int ECP_multiply(EC_POINT *R, BIGNUM *k, ECP_PRECOMPUTE *prec, EC *E, BN_CTX *ctx);\r | |
73 | #endif /* SIMPLE */\r | |
74 | \r | |
75 | #ifdef MONTGOMERY\r | |
76 | int ECP_to_montgomery(EC_POINT *P, BN_MONTGOMERY *mont, BN_CTX *ctx);\r | |
77 | int ECP_from_montgomery(EC_POINT *P, BN_MONTGOMERY *mont, BN_CTX *ctx);\r | |
78 | int ECP_mont_cmp(EC_POINT *P, EC_POINT *Q, BN_MONTGOMERY *mont, BN_CTX *ctx);\r | |
79 | int ECP_mont_double(EC_POINT *R, EC_POINT *P, EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);\r | |
80 | int ECP_mont_add(EC_POINT *R, EC_POINT *P, EC_POINT *Q, EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);\r | |
81 | ECP_PRECOMPUTE *ECP_mont_precompute(int r, EC_POINT *P, EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);\r | |
82 | int ECP_mont_multiply(EC_POINT *R, BIGNUM *k, ECP_PRECOMPUTE *prec, EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);\r | |
83 | int ECP_mont_multiply2(EC_POINT *R, BIGNUM *k, EC_POINT *P, EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);\r | |
84 | #endif /* MONTGOMERY */\r | |
85 | \r | |
86 | #endif |