bn_mont2.h 765 字节
Newer Older
B
Bodo Möller 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 *
 *	bn_mont2.h
 *
 *	Montgomery Modular Arithmetic Functions.
 *
 *	Copyright (C) Lenka Fibikova 2000
 *
 *
 */

#ifndef HEADER_MONT2_H
#define HEADER_MONT2_H

#define MONTGOMERY

B
Bodo Möller 已提交
17
#include <openssl/bn.h>
B
Bodo Möller 已提交
18 19 20 21 22 23 24 25

typedef struct bn_mont_st{
	int R_num_bits;
	int p_num_bytes;
	BIGNUM *p;
	BN_ULONG p_inv_b_neg;	/* p' = p^{-1} mod b; b = 2^BN_BITS */
} BN_MONTGOMERY;

26
#define BN_from_mont(x, mont) (BN_mont_red((x), (mont)))
B
Bodo Möller 已提交
27 28 29 30 31 32


BN_MONTGOMERY *BN_mont_new();
int BN_to_mont(BIGNUM *x, BN_MONTGOMERY *mont, BN_CTX *ctx); 
void BN_mont_clear_free(BN_MONTGOMERY *mont);
int BN_mont_set(BIGNUM *p, BN_MONTGOMERY *mont, BN_CTX *ctx);
33
int BN_mont_red(BIGNUM *y, BN_MONTGOMERY *mont);
34
int BN_mont_mod_mul(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_MONTGOMERY *mont, BN_CTX *);
B
Bodo Möller 已提交
35

B
Bodo Möller 已提交
36
#endif