Remove CR at line ends.
[openssl.git] / crypto / ec / ec.h
1 /*
2  *
3  *      ec.h
4  *
5  *      Elliptic Curve Arithmetic Functions
6  *
7  *      Copyright (C) Lenka Fibikova 2000
8  *
9  *
10  */
11
12
13 #ifndef HEADER_EC_H
14 #define HEADER_EC_H
15
16
17 #include "bn.h"
18 #include "bn_mont2.h"
19
20 typedef struct bn_ec_struct             /* E: y^2 = x^3 + Ax + B  (mod p) */
21 {
22         BIGNUM  *A, *B, *p, *h;         /* h = 1/2 mod p = (p + 1)/2 */
23         int is_in_mont;
24 } EC;
25
26 typedef struct bn_ec_point_struct /* P = [X, Y, Z] */
27 {
28         BIGNUM  *X, *Y, *Z;
29         int is_in_mont;
30 } EC_POINT;
31
32 typedef struct bn_ecp_precompute_struct /* Pi[i] = [2i + 1]P    i = 0..2^{r-1} - 1 */
33 {
34         int r;
35         EC_POINT **Pi;
36 } ECP_PRECOMPUTE;
37
38
39 #define ECP_is_infty(P) (BN_is_zero(P->Z))
40 #define ECP_is_norm(P) (BN_is_one(P->Z))
41
42 #define ECP_mont_minus(P, mont) (ECP_minus((P), (mont)->p))
43
44
45 EC *EC_new();
46 void EC_clear_free(EC *E);
47 int EC_set_half(EC *E);
48 #ifdef MONTGOMERY
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 */
52
53
54 EC_POINT *ECP_new();
55 void ECP_clear_free(EC_POINT *P);
56 void ECP_clear_free_precompute(ECP_PRECOMPUTE *prec);
57
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);
66
67 #ifdef SIMPLE
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);
73 #endif /* SIMPLE */
74
75 #ifdef MONTGOMERY
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 */
85
86 #endif