]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/ec/ec.h
Elliptic curves over GF(p), new BIGNUM functions, Montgomery re-implementation.
[thirdparty/openssl.git] / crypto / ec / ec.h
CommitLineData
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
20typedef 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
26typedef 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
32typedef 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
45EC *EC_new();\r
46void EC_clear_free(EC *E);\r
47int EC_set_half(EC *E);\r
48#ifdef MONTGOMERY\r
49int EC_to_montgomery(EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);\r
50int EC_from_montgomery(EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);\r
51#endif /* MONTGOMERY */\r
52\r
53\r
54EC_POINT *ECP_new();\r
55void ECP_clear_free(EC_POINT *P);\r
56void ECP_clear_free_precompute(ECP_PRECOMPUTE *prec);\r
57\r
58EC_POINT *ECP_generate(BIGNUM *x, BIGNUM *z, EC *E, BN_CTX *ctx);\r
59EC_POINT *ECP_dup(EC_POINT *P);\r
60int ECP_copy(EC_POINT *R, EC_POINT *P);\r
61int ECP_normalize(EC_POINT *P, EC *E, BN_CTX *ctx);\r
62EC_POINT *ECP_minus(EC_POINT *P, BIGNUM *p);\r
63int ECP_is_on_ec(EC_POINT *P, EC *E, BN_CTX *ctx);\r
64int ECP_ecp2bin(EC_POINT *P, unsigned char *to, int form); /* form(ANSI 9.62): 1-compressed; 2-uncompressed; 3-hybrid */\r
65int ECP_bin2ecp(unsigned char *from, int len, EC_POINT *P, EC *E, BN_CTX *ctx);\r
66\r
67#ifdef SIMPLE\r
68int ECP_cmp(EC_POINT *P, EC_POINT *Q, BIGNUM *p, BN_CTX *ctx);\r
69int ECP_double(EC_POINT *R, EC_POINT *P, EC *E, BN_CTX *ctx);\r
70int ECP_add(EC_POINT *R, EC_POINT *P, EC_POINT *Q, EC *E, BN_CTX *ctx);\r
71ECP_PRECOMPUTE *ECP_precompute(int r, EC_POINT *P, EC *E, BN_CTX *ctx);\r
72int 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
76int ECP_to_montgomery(EC_POINT *P, BN_MONTGOMERY *mont, BN_CTX *ctx);\r
77int ECP_from_montgomery(EC_POINT *P, BN_MONTGOMERY *mont, BN_CTX *ctx);\r
78int ECP_mont_cmp(EC_POINT *P, EC_POINT *Q, BN_MONTGOMERY *mont, BN_CTX *ctx);\r
79int ECP_mont_double(EC_POINT *R, EC_POINT *P, EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);\r
80int ECP_mont_add(EC_POINT *R, EC_POINT *P, EC_POINT *Q, EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);\r
81ECP_PRECOMPUTE *ECP_mont_precompute(int r, EC_POINT *P, EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);\r
82int ECP_mont_multiply(EC_POINT *R, BIGNUM *k, ECP_PRECOMPUTE *prec, EC *E, BN_MONTGOMERY *mont, BN_CTX *ctx);\r
83int 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