Elliptic curves over GF(p), new BIGNUM functions, Montgomery re-implementation.
[openssl.git] / crypto / bn / bn_mont2.h
1 /*\r
2  *\r
3  *      bn_mont2.h\r
4  *\r
5  *      Montgomery Modular Arithmetic Functions.\r
6  *\r
7  *      Copyright (C) Lenka Fibikova 2000\r
8  *\r
9  *\r
10  */\r
11 \r
12 #ifndef HEADER_MONT2_H\r
13 #define HEADER_MONT2_H\r
14 \r
15 #define MONTGOMERY\r
16 \r
17 #include "bn.h"\r
18 \r
19 typedef struct bn_mont_st{\r
20         int R_num_bits;\r
21         int p_num_bytes;\r
22         BIGNUM *p;\r
23         BN_ULONG p_inv_b_neg;   /* p' = p^{-1} mod b; b = 2^BN_BITS */\r
24 } BN_MONTGOMERY;\r
25 \r
26 #define BN_from_mont(x, mont, ctx) (BN_mont_red((x), (mont), (ctx)))\r
27 \r
28 \r
29 BN_MONTGOMERY *BN_mont_new();\r
30 int BN_to_mont(BIGNUM *x, BN_MONTGOMERY *mont, BN_CTX *ctx); \r
31 void BN_mont_clear_free(BN_MONTGOMERY *mont);\r
32 int BN_mont_set(BIGNUM *p, BN_MONTGOMERY *mont, BN_CTX *ctx);\r
33 int BN_mont_red(BIGNUM *y, BN_MONTGOMERY *mont, BN_CTX *ctx);\r
34 BN_ULONG BN_mont_inv(BIGNUM *x, int e, BN_CTX *ctx);\r
35 int BN_mont_mod_mul(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_MONTGOMERY *mont, BN_CTX *ctx);\r
36 int BN_mont_mod_add(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_MONTGOMERY *mont);\r
37 int BN_mont_mod_sub(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_MONTGOMERY *mont);\r
38 int BN_mont_mod_lshift1(BIGNUM *r, BIGNUM *x, BN_MONTGOMERY *mont);\r
39 int BN_mont_mod_lshift(BIGNUM *r, BIGNUM *x, int n, BN_MONTGOMERY *mont);\r
40 \r
41 #endif