5 * Montgomery Modular Arithmetic Functions.
7 * Copyright (C) Lenka Fibikova 2000
12 #ifndef HEADER_MONT2_H
13 #define HEADER_MONT2_H
19 typedef struct bn_mont_st{
23 BN_ULONG p_inv_b_neg; /* p' = p^{-1} mod b; b = 2^BN_BITS */
26 #define BN_from_mont(x, mont, ctx) (BN_mont_red((x), (mont), (ctx)))
29 BN_MONTGOMERY *BN_mont_new();
30 int BN_to_mont(BIGNUM *x, BN_MONTGOMERY *mont, BN_CTX *ctx);
31 void BN_mont_clear_free(BN_MONTGOMERY *mont);
32 int BN_mont_set(BIGNUM *p, BN_MONTGOMERY *mont, BN_CTX *ctx);
33 int BN_mont_red(BIGNUM *y, BN_MONTGOMERY *mont, BN_CTX *ctx);
34 BN_ULONG BN_mont_inv(BIGNUM *x, int e, BN_CTX *ctx);
35 int BN_mont_mod_mul(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_MONTGOMERY *mont, BN_CTX *ctx);
36 int BN_mont_mod_add(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_MONTGOMERY *mont);
37 int BN_mont_mod_sub(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_MONTGOMERY *mont);
38 int BN_mont_mod_lshift1(BIGNUM *r, BIGNUM *x, BN_MONTGOMERY *mont);
39 int BN_mont_mod_lshift(BIGNUM *r, BIGNUM *x, int n, BN_MONTGOMERY *mont);