monotone

monotone Mtn Source Tree

Root/botan/numthry.h

1/*************************************************
2* Number Theory Header File *
3* (C) 1999-2006 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
61SecureVector<byte> generate_dsa_primes(BigInt&, BigInt&, u32bit);
62bool generate_dsa_primes(BigInt&, BigInt&, const byte[], u32bit, u32bit,
63 u32bit = 0);
64
65/*************************************************
66* Prime Numbers *
67*************************************************/
68const u32bit PRIME_TABLE_SIZE = 6541;
69const u32bit PRIME_PRODUCTS_TABLE_SIZE = 256;
70
71extern const u16bit PRIMES[];
72extern const u64bit PRIME_PRODUCTS[];
73
74/*************************************************
75* Miller-Rabin Primality Tester *
76*************************************************/
77class MillerRabin_Test
78 {
79 public:
80 bool passes_test(const BigInt&);
81 MillerRabin_Test(const BigInt&);
82 private:
83 BigInt n, r, n_minus_1;
84 u32bit s;
85 Fixed_Exponent_Power_Mod pow_mod;
86 Modular_Reducer reducer;
87 };
88
89}
90
91#endif

Archive Download this file

Branches

Tags

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