diff options
author | lloyd <[email protected]> | 2008-09-29 18:12:16 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-29 18:12:16 +0000 |
commit | 0d8e9744ef02aba33ddd89c93194ce526f6ff6ee (patch) | |
tree | e60064db23397f9a9dc3b847f9c4199be7c7ca0d | |
parent | 26abd45c61294aacdd59fa4763ff1cd78aefbc7c (diff) |
Put only the implementation of BigInt in src/bigint, mathematical functions
on top of BigInt go to src/math. Some prototypes were moved in order to
complete the split, in particular random_integer() is now a static member
of BigInt instead of being a global function, and divide() is in divide.h
instead of numthry.h
-rw-r--r-- | src/bigint/big_code.cpp | 2 | ||||
-rw-r--r-- | src/bigint/big_ops3.cpp | 2 | ||||
-rw-r--r-- | src/bigint/big_rand.cpp | 21 | ||||
-rw-r--r-- | src/bigint/bigint.h | 3 | ||||
-rw-r--r-- | src/bigint/divide.cpp | 2 | ||||
-rw-r--r-- | src/bigint/info.txt | 27 | ||||
-rw-r--r-- | src/cert/x509/x509_ca.cpp | 2 | ||||
-rw-r--r-- | src/core/def_powm.cpp (renamed from src/bigint/def_powm.cpp) | 0 | ||||
-rw-r--r-- | src/core/info.txt | 6 | ||||
-rw-r--r-- | src/math/blinding.cpp (renamed from src/bigint/blinding.cpp) | 0 | ||||
-rw-r--r-- | src/math/blinding.h (renamed from src/bigint/blinding.h) | 0 | ||||
-rw-r--r-- | src/math/def_powm.h (renamed from src/bigint/def_powm.h) | 0 | ||||
-rw-r--r-- | src/math/dsa_gen.cpp (renamed from src/bigint/dsa_gen.cpp) | 0 | ||||
-rw-r--r-- | src/math/info.txt | 29 | ||||
-rw-r--r-- | src/math/jacobi.cpp (renamed from src/bigint/jacobi.cpp) | 0 | ||||
-rw-r--r-- | src/math/make_prm.cpp (renamed from src/bigint/make_prm.cpp) | 16 | ||||
-rw-r--r-- | src/math/mp_numth.cpp (renamed from src/bigint/mp_numth.cpp) | 0 | ||||
-rw-r--r-- | src/math/numthry.cpp (renamed from src/bigint/numthry.cpp) | 0 | ||||
-rw-r--r-- | src/math/numthry.h (renamed from src/bigint/numthry.h) | 11 | ||||
-rw-r--r-- | src/math/pow_mod.cpp (renamed from src/bigint/pow_mod.cpp) | 0 | ||||
-rw-r--r-- | src/math/pow_mod.h (renamed from src/bigint/pow_mod.h) | 0 | ||||
-rw-r--r-- | src/math/powm_fw.cpp (renamed from src/bigint/powm_fw.cpp) | 0 | ||||
-rw-r--r-- | src/math/powm_mnt.cpp (renamed from src/bigint/powm_mnt.cpp) | 0 | ||||
-rw-r--r-- | src/math/primes.cpp (renamed from src/bigint/primes.cpp) | 0 | ||||
-rw-r--r-- | src/math/reducer.cpp (renamed from src/bigint/reducer.cpp) | 0 | ||||
-rw-r--r-- | src/math/reducer.h (renamed from src/bigint/reducer.h) | 0 | ||||
-rw-r--r-- | src/math/ressol.cpp (renamed from src/bigint/ressol.cpp) | 0 | ||||
-rw-r--r-- | src/pk/dsa/dsa.cpp | 2 | ||||
-rw-r--r-- | src/pk/nr/nr.cpp | 2 | ||||
-rw-r--r-- | src/pk/pubkey/info.txt | 1 |
30 files changed, 71 insertions, 55 deletions
diff --git a/src/bigint/big_code.cpp b/src/bigint/big_code.cpp index 824cbb63e..e7a5e4946 100644 --- a/src/bigint/big_code.cpp +++ b/src/bigint/big_code.cpp @@ -4,7 +4,7 @@ *************************************************/ #include <botan/bigint.h> -#include <botan/numthry.h> +#include <botan/divide.h> #include <botan/charset.h> #include <botan/hex.h> diff --git a/src/bigint/big_ops3.cpp b/src/bigint/big_ops3.cpp index 7f412f6db..ff24eab1c 100644 --- a/src/bigint/big_ops3.cpp +++ b/src/bigint/big_ops3.cpp @@ -4,7 +4,7 @@ *************************************************/ #include <botan/bigint.h> -#include <botan/numthry.h> +#include <botan/divide.h> #include <botan/mp_core.h> #include <botan/bit_ops.h> #include <algorithm> diff --git a/src/bigint/big_rand.cpp b/src/bigint/big_rand.cpp index b8cad3a4c..055873642 100644 --- a/src/bigint/big_rand.cpp +++ b/src/bigint/big_rand.cpp @@ -5,7 +5,6 @@ #include <botan/bigint.h> #include <botan/parsing.h> -#include <botan/numthry.h> namespace Botan { @@ -46,8 +45,8 @@ void BigInt::randomize(RandomNumberGenerator& rng, /************************************************* * Generate a random integer within given range * *************************************************/ -BigInt random_integer(RandomNumberGenerator& rng, - const BigInt& min, const BigInt& max) +BigInt BigInt::random_integer(RandomNumberGenerator& rng, + const BigInt& min, const BigInt& max) { BigInt range = max - min; @@ -57,20 +56,4 @@ BigInt random_integer(RandomNumberGenerator& rng, return (min + (BigInt(rng, range.bits() + 2) % range)); } -/************************************************* -* Generate a random safe prime * -*************************************************/ -BigInt random_safe_prime(RandomNumberGenerator& rng, u32bit bits) - { - if(bits <= 64) - throw Invalid_Argument("random_safe_prime: Can't make a prime of " + - to_string(bits) + " bits"); - - BigInt p; - do - p = (random_prime(rng, bits - 1) << 1) + 1; - while(!is_prime(p, rng)); - return p; - } - } diff --git a/src/bigint/bigint.h b/src/bigint/bigint.h index b1286551e..bb1d7ef7b 100644 --- a/src/bigint/bigint.h +++ b/src/bigint/bigint.h @@ -115,6 +115,9 @@ class BOTAN_DLL BigInt void binary_decode(const MemoryRegion<byte>&); u32bit encoded_size(Base = Binary) const; + static BigInt random_integer(RandomNumberGenerator&, + const BigInt&, const BigInt&); + static SecureVector<byte> encode(const BigInt&, Base = Binary); static void encode(byte[], const BigInt&, Base = Binary); static BigInt decode(const byte[], u32bit, Base = Binary); diff --git a/src/bigint/divide.cpp b/src/bigint/divide.cpp index 003a06d83..ba088ced4 100644 --- a/src/bigint/divide.cpp +++ b/src/bigint/divide.cpp @@ -3,7 +3,7 @@ * (C) 1999-2007 Jack Lloyd * *************************************************/ -#include <botan/numthry.h> +#include <botan/divide.h> #include <botan/mp_core.h> namespace Botan { diff --git a/src/bigint/info.txt b/src/bigint/info.txt index 33b738d49..b82d1cd72 100644 --- a/src/bigint/info.txt +++ b/src/bigint/info.txt @@ -6,43 +6,26 @@ define BIGINT <requires> hex -mp_ia32 +mp_amd64 </requires> <add> +bigint.h +divide.h +mp_core.h +mp_types.h big_code.cpp big_io.cpp big_ops2.cpp big_ops3.cpp big_rand.cpp bigint.cpp -bigint.h -blinding.cpp -blinding.h -def_powm.h -def_powm.cpp divide.cpp -dsa_gen.cpp -jacobi.cpp -make_prm.cpp mp_asm.cpp mp_comba.cpp -mp_core.h mp_karat.cpp mp_misc.cpp mp_monty.cpp mp_mulop.cpp -mp_numth.cpp mp_shift.cpp -mp_types.h -numthry.cpp -numthry.h -pow_mod.cpp -pow_mod.h -powm_fw.cpp -powm_mnt.cpp -primes.cpp -reducer.cpp -reducer.h -ressol.cpp </add> diff --git a/src/cert/x509/x509_ca.cpp b/src/cert/x509/x509_ca.cpp index 16cfc662c..f4edcc479 100644 --- a/src/cert/x509/x509_ca.cpp +++ b/src/cert/x509/x509_ca.cpp @@ -9,7 +9,7 @@ #include <botan/ber_dec.h> #include <botan/lookup.h> #include <botan/look_pk.h> -#include <botan/numthry.h> +#include <botan/bigint.h> #include <botan/parsing.h> #include <botan/oids.h> #include <botan/util.h> diff --git a/src/bigint/def_powm.cpp b/src/core/def_powm.cpp index a28438f5b..a28438f5b 100644 --- a/src/bigint/def_powm.cpp +++ b/src/core/def_powm.cpp diff --git a/src/core/info.txt b/src/core/info.txt index df98e51ab..802f5bcef 100644 --- a/src/core/info.txt +++ b/src/core/info.txt @@ -6,8 +6,11 @@ define CORE_MODULE <requires> aes -bigint sha1 +sha2 +hmac +bigint +math allocators filters pubkey @@ -19,6 +22,7 @@ data_src.cpp datastor.cpp def_alg.cpp def_mode.cpp +def_powm.cpp eng_base.cpp engine.cpp exceptn.cpp diff --git a/src/bigint/blinding.cpp b/src/math/blinding.cpp index 740904d10..740904d10 100644 --- a/src/bigint/blinding.cpp +++ b/src/math/blinding.cpp diff --git a/src/bigint/blinding.h b/src/math/blinding.h index 958686fb1..958686fb1 100644 --- a/src/bigint/blinding.h +++ b/src/math/blinding.h diff --git a/src/bigint/def_powm.h b/src/math/def_powm.h index c91ff002c..c91ff002c 100644 --- a/src/bigint/def_powm.h +++ b/src/math/def_powm.h diff --git a/src/bigint/dsa_gen.cpp b/src/math/dsa_gen.cpp index baaba66ee..baaba66ee 100644 --- a/src/bigint/dsa_gen.cpp +++ b/src/math/dsa_gen.cpp diff --git a/src/math/info.txt b/src/math/info.txt new file mode 100644 index 000000000..6ce3583c8 --- /dev/null +++ b/src/math/info.txt @@ -0,0 +1,29 @@ +realname "Math Functions" + +load_on auto + +define BIGINT_MATH + +<requires> +bigint +</requires> + +<add> +blinding.cpp +blinding.h +def_powm.h +dsa_gen.cpp +jacobi.cpp +make_prm.cpp +mp_numth.cpp +numthry.cpp +numthry.h +pow_mod.cpp +pow_mod.h +powm_fw.cpp +powm_mnt.cpp +primes.cpp +reducer.cpp +reducer.h +ressol.cpp +</add> diff --git a/src/bigint/jacobi.cpp b/src/math/jacobi.cpp index 57c78508a..57c78508a 100644 --- a/src/bigint/jacobi.cpp +++ b/src/math/jacobi.cpp diff --git a/src/bigint/make_prm.cpp b/src/math/make_prm.cpp index dc26a0400..30ac9a623 100644 --- a/src/bigint/make_prm.cpp +++ b/src/math/make_prm.cpp @@ -76,4 +76,20 @@ BigInt random_prime(RandomNumberGenerator& rng, } } +/************************************************* +* Generate a random safe prime * +*************************************************/ +BigInt random_safe_prime(RandomNumberGenerator& rng, u32bit bits) + { + if(bits <= 64) + throw Invalid_Argument("random_safe_prime: Can't make a prime of " + + to_string(bits) + " bits"); + + BigInt p; + do + p = (random_prime(rng, bits - 1) << 1) + 1; + while(!is_prime(p, rng)); + return p; + } + } diff --git a/src/bigint/mp_numth.cpp b/src/math/mp_numth.cpp index b024d2e2d..b024d2e2d 100644 --- a/src/bigint/mp_numth.cpp +++ b/src/math/mp_numth.cpp diff --git a/src/bigint/numthry.cpp b/src/math/numthry.cpp index ffd523e82..ffd523e82 100644 --- a/src/bigint/numthry.cpp +++ b/src/math/numthry.cpp diff --git a/src/bigint/numthry.h b/src/math/numthry.h index 371621c2d..a271a428a 100644 --- a/src/bigint/numthry.h +++ b/src/math/numthry.h @@ -1,15 +1,15 @@ /************************************************* -* Number Theory Header File * +* Number Theory Functions Header File * * (C) 1999-2007 Jack Lloyd * *************************************************/ -#ifndef BOTAN_NUMBTHRY_H__ -#define BOTAN_NUMBTHRY_H__ +#ifndef BOTAN_NUMBER_THEORY_H__ +#define BOTAN_NUMBER_THEORY_H__ -#include <botan/base.h> #include <botan/bigint.h> #include <botan/reducer.h> #include <botan/pow_mod.h> +#include <botan/rng.h> namespace Botan { @@ -64,9 +64,6 @@ bool BOTAN_DLL run_primality_tests(RandomNumberGenerator&, /************************************************* * Random Number Generation * *************************************************/ -BigInt BOTAN_DLL random_integer(RandomNumberGenerator&, - const BigInt&, const BigInt&); - BigInt BOTAN_DLL random_prime(RandomNumberGenerator&, u32bit bits, const BigInt& coprime = 1, u32bit equiv = 1, u32bit equiv_mod = 2); diff --git a/src/bigint/pow_mod.cpp b/src/math/pow_mod.cpp index 17ca7b796..17ca7b796 100644 --- a/src/bigint/pow_mod.cpp +++ b/src/math/pow_mod.cpp diff --git a/src/bigint/pow_mod.h b/src/math/pow_mod.h index 37e0871da..37e0871da 100644 --- a/src/bigint/pow_mod.h +++ b/src/math/pow_mod.h diff --git a/src/bigint/powm_fw.cpp b/src/math/powm_fw.cpp index c29b9f311..c29b9f311 100644 --- a/src/bigint/powm_fw.cpp +++ b/src/math/powm_fw.cpp diff --git a/src/bigint/powm_mnt.cpp b/src/math/powm_mnt.cpp index 6091d467a..6091d467a 100644 --- a/src/bigint/powm_mnt.cpp +++ b/src/math/powm_mnt.cpp diff --git a/src/bigint/primes.cpp b/src/math/primes.cpp index d005167e5..d005167e5 100644 --- a/src/bigint/primes.cpp +++ b/src/math/primes.cpp diff --git a/src/bigint/reducer.cpp b/src/math/reducer.cpp index 47c5c20fc..47c5c20fc 100644 --- a/src/bigint/reducer.cpp +++ b/src/math/reducer.cpp diff --git a/src/bigint/reducer.h b/src/math/reducer.h index 48008e73b..48008e73b 100644 --- a/src/bigint/reducer.h +++ b/src/math/reducer.h diff --git a/src/bigint/ressol.cpp b/src/math/ressol.cpp index 0cd2b988a..0cd2b988a 100644 --- a/src/bigint/ressol.cpp +++ b/src/math/ressol.cpp diff --git a/src/pk/dsa/dsa.cpp b/src/pk/dsa/dsa.cpp index a7eb8e789..ef69a1ee5 100644 --- a/src/pk/dsa/dsa.cpp +++ b/src/pk/dsa/dsa.cpp @@ -64,7 +64,7 @@ DSA_PrivateKey::DSA_PrivateKey(RandomNumberGenerator& rng, if(x == 0) { - x = random_integer(rng, 2, group_q() - 1); + x = BigInt::random_integer(rng, 2, group_q() - 1); PKCS8_load_hook(rng, true); } else diff --git a/src/pk/nr/nr.cpp b/src/pk/nr/nr.cpp index 02919d52e..99eff9726 100644 --- a/src/pk/nr/nr.cpp +++ b/src/pk/nr/nr.cpp @@ -63,7 +63,7 @@ NR_PrivateKey::NR_PrivateKey(RandomNumberGenerator& rng, if(x == 0) { - x = random_integer(rng, 2, group_q() - 1); + x = BigInt::random_integer(rng, 2, group_q() - 1); PKCS8_load_hook(rng, true); } else diff --git a/src/pk/pubkey/info.txt b/src/pk/pubkey/info.txt index 9dea71d72..05ff2bde0 100644 --- a/src/pk/pubkey/info.txt +++ b/src/pk/pubkey/info.txt @@ -4,6 +4,7 @@ define PUBKEY_BASE <requires> bigint +math asn1 </requires> |