monotone

monotone Mtn Source Tree

Root/botan/numthry.h

1/*************************************************
2* Number Theory Header File *
3* (C) 1999-2007 The Botan Project *
4*************************************************/
5
6#ifndef BOTAN_NUMBTHRY_H__
7#define BOTAN_NUMBTHRY_H__
8
9#include <botan/bigint.h>
10#include <botan/reducer.h>
11#include <botan/pow_mod.h>
12
13namespace Botan {
14
15/*************************************************
16* Fused Arithmetic Operations *
17*************************************************/
18BigInt mul_add(const BigInt&, const BigInt&, const BigInt&);
19BigInt sub_mul(const BigInt&, const BigInt&, const BigInt&);
20
21/*************************************************
22* Number Theory Functions *
23*************************************************/
24inline BigInt abs(const BigInt& n) { return n.abs(); }
25
26void divide(const BigInt&, const BigInt&, BigInt&, BigInt&);
27
28BigInt gcd(const BigInt&, const BigInt&);
29BigInt lcm(const BigInt&, const BigInt&);
30
31BigInt square(const BigInt&);
32BigInt inverse_mod(const BigInt&, const BigInt&);
33s32bit jacobi(const BigInt&, const BigInt&);
34
35BigInt power_mod(const BigInt&, const BigInt&, const BigInt&);
36
37/*************************************************
38* Utility Functions *
39*************************************************/
40u32bit low_zero_bits(const BigInt&);
41
42/*************************************************
43* Primality Testing *
44*************************************************/
45bool check_prime(const BigInt&);
46bool is_prime(const BigInt&);
47bool verify_prime(const BigInt&);
48
49s32bit simple_primality_tests(const BigInt&);
50bool passes_mr_tests(const BigInt&, u32bit = 1);
51bool run_primality_tests(const BigInt&, u32bit = 1);
52
53/*************************************************
54* Random Number Generation *
55*************************************************/
56BigInt random_integer(u32bit);
57BigInt random_integer(const BigInt&, const BigInt&);
58BigInt random_prime(u32bit, const BigInt& = 1, u32bit = 1, u32bit = 2);
59BigInt random_safe_prime(u32bit);
60
61/*************************************************
62* Prime Numbers *
63*************************************************/
64const u32bit PRIME_TABLE_SIZE = 6541;
65const u32bit PRIME_PRODUCTS_TABLE_SIZE = 256;
66
67extern const u16bit PRIMES[];
68extern const u64bit PRIME_PRODUCTS[];
69
70/*************************************************
71* Miller-Rabin Primality Tester *
72*************************************************/
73class MillerRabin_Test
74 {
75 public:
76 bool passes_test(const BigInt&);
77 MillerRabin_Test(const BigInt&);
78 private:
79 BigInt n, r, n_minus_1;
80 u32bit s;
81 Fixed_Exponent_Power_Mod pow_mod;
82 Modular_Reducer reducer;
83 };
84
85}
86
87#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status