aboutsummaryrefslogtreecommitdiffstats
path: root/src/math/numbertheory
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-03-30 18:27:18 +0000
committerlloyd <[email protected]>2009-03-30 18:27:18 +0000
commit96d6eb6f29c55e16a37cf11899547886f735b065 (patch)
tree9f13901e9b44c98d58b2589c9b09c6a7443eb7cd /src/math/numbertheory
parent3cc3dd72c5f87b76852a55c1f2d1821dba967d8c (diff)
Thomas Moschny passed along a request from the Fedora packagers which came
up during the Fedora submission review, that each source file include some text about the license. One handy Perl script later and each file now has the line Distributed under the terms of the Botan license after the copyright notices. While I was in there modifying every file anyway, I also stripped out the remainder of the block comments (lots of astericks before and after the text); this is stylistic thing I picked up when I was first learning C++ but in retrospect it is not a good style as the structure makes it harder to modify comments (with the result that comments become fewer, shorter and are less likely to be updated, which are not good things).
Diffstat (limited to 'src/math/numbertheory')
-rw-r--r--src/math/numbertheory/blinding.cpp28
-rw-r--r--src/math/numbertheory/blinding.h16
-rw-r--r--src/math/numbertheory/def_powm.h22
-rw-r--r--src/math/numbertheory/dsa_gen.cpp28
-rw-r--r--src/math/numbertheory/jacobi.cpp16
-rw-r--r--src/math/numbertheory/make_prm.cpp22
-rw-r--r--src/math/numbertheory/mp_numth.cpp28
-rw-r--r--src/math/numbertheory/numthry.cpp94
-rw-r--r--src/math/numbertheory/numthry.h66
-rw-r--r--src/math/numbertheory/pow_mod.cpp82
-rw-r--r--src/math/numbertheory/pow_mod.h34
-rw-r--r--src/math/numbertheory/powm_fw.cpp40
-rw-r--r--src/math/numbertheory/powm_mnt.cpp46
-rw-r--r--src/math/numbertheory/primes.cpp10
-rw-r--r--src/math/numbertheory/reducer.cpp34
-rw-r--r--src/math/numbertheory/reducer.h16
-rw-r--r--src/math/numbertheory/ressol.cpp18
17 files changed, 317 insertions, 283 deletions
diff --git a/src/math/numbertheory/blinding.cpp b/src/math/numbertheory/blinding.cpp
index 740904d10..c6a3fd1bd 100644
--- a/src/math/numbertheory/blinding.cpp
+++ b/src/math/numbertheory/blinding.cpp
@@ -1,16 +1,18 @@
-/*************************************************
-* Blinder Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Blinder
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#include <botan/blinding.h>
#include <botan/numthry.h>
namespace Botan {
-/*************************************************
-* Blinder Constructor *
-*************************************************/
+/*
+* Blinder Constructor
+*/
Blinder::Blinder(const BigInt& e, const BigInt& d, const BigInt& n)
{
if(e < 1 || d < 1 || n < 1)
@@ -21,9 +23,9 @@ Blinder::Blinder(const BigInt& e, const BigInt& d, const BigInt& n)
this->d = d;
}
-/*************************************************
-* Blind a number *
-*************************************************/
+/*
+* Blind a number
+*/
BigInt Blinder::blind(const BigInt& i) const
{
if(!reducer.initialized())
@@ -34,9 +36,9 @@ BigInt Blinder::blind(const BigInt& i) const
return reducer.multiply(i, e);
}
-/*************************************************
-* Unblind a number *
-*************************************************/
+/*
+* Unblind a number
+*/
BigInt Blinder::unblind(const BigInt& i) const
{
if(!reducer.initialized())
diff --git a/src/math/numbertheory/blinding.h b/src/math/numbertheory/blinding.h
index 958686fb1..5f7f9e6b7 100644
--- a/src/math/numbertheory/blinding.h
+++ b/src/math/numbertheory/blinding.h
@@ -1,7 +1,9 @@
-/*************************************************
-* Blinder Header File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Blinder
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#ifndef BOTAN_BLINDER_H__
#define BOTAN_BLINDER_H__
@@ -11,9 +13,9 @@
namespace Botan {
-/*************************************************
-* Blinding Function Object *
-*************************************************/
+/*
+* Blinding Function Object
+*/
class BOTAN_DLL Blinder
{
public:
diff --git a/src/math/numbertheory/def_powm.h b/src/math/numbertheory/def_powm.h
index c91ff002c..472c865c3 100644
--- a/src/math/numbertheory/def_powm.h
+++ b/src/math/numbertheory/def_powm.h
@@ -1,7 +1,9 @@
-/*************************************************
-* Modular Exponentiation Header File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Modular Exponentiation
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#ifndef BOTAN_DEFAULT_MODEXP_H__
#define BOTAN_DEFAULT_MODEXP_H__
@@ -12,9 +14,9 @@
namespace Botan {
-/*************************************************
-* Fixed Window Exponentiator *
-*************************************************/
+/*
+* Fixed Window Exponentiator
+*/
class BOTAN_DLL Fixed_Window_Exponentiator : public Modular_Exponentiator
{
public:
@@ -34,9 +36,9 @@ class BOTAN_DLL Fixed_Window_Exponentiator : public Modular_Exponentiator
Power_Mod::Usage_Hints hints;
};
-/*************************************************
-* Montgomery Exponentiator *
-*************************************************/
+/*
+* Montgomery Exponentiator
+*/
class BOTAN_DLL Montgomery_Exponentiator : public Modular_Exponentiator
{
public:
diff --git a/src/math/numbertheory/dsa_gen.cpp b/src/math/numbertheory/dsa_gen.cpp
index 1e44b7148..83646e50e 100644
--- a/src/math/numbertheory/dsa_gen.cpp
+++ b/src/math/numbertheory/dsa_gen.cpp
@@ -1,7 +1,9 @@
-/*************************************************
-* DSA Parameter Generation Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* DSA Parameter Generation
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#include <botan/numthry.h>
#include <botan/algo_factory.h>
@@ -14,9 +16,9 @@ namespace Botan {
namespace {
-/*************************************************
-* Check if this size is allowed by FIPS 186-3 *
-*************************************************/
+/*
+* Check if this size is allowed by FIPS 186-3
+*/
bool fips186_3_valid_size(u32bit pbits, u32bit qbits)
{
if(qbits == 160)
@@ -33,9 +35,9 @@ bool fips186_3_valid_size(u32bit pbits, u32bit qbits)
}
-/*************************************************
-* Attempt DSA prime generation with given seed *
-*************************************************/
+/*
+* Attempt DSA prime generation with given seed
+*/
bool generate_dsa_primes(RandomNumberGenerator& rng,
Algorithm_Factory& af,
BigInt& p, BigInt& q,
@@ -111,9 +113,9 @@ bool generate_dsa_primes(RandomNumberGenerator& rng,
return false;
}
-/*************************************************
-* Generate DSA Primes *
-*************************************************/
+/*
+* Generate DSA Primes
+*/
SecureVector<byte> generate_dsa_primes(RandomNumberGenerator& rng,
Algorithm_Factory& af,
BigInt& p, BigInt& q,
diff --git a/src/math/numbertheory/jacobi.cpp b/src/math/numbertheory/jacobi.cpp
index 57c78508a..2ad05ff71 100644
--- a/src/math/numbertheory/jacobi.cpp
+++ b/src/math/numbertheory/jacobi.cpp
@@ -1,15 +1,17 @@
-/*************************************************
-* Jacobi Function Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Jacobi Function
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#include <botan/numthry.h>
namespace Botan {
-/*************************************************
-* Calculate the Jacobi symbol *
-*************************************************/
+/*
+* Calculate the Jacobi symbol
+*/
s32bit jacobi(const BigInt& a, const BigInt& n)
{
if(a.is_negative())
diff --git a/src/math/numbertheory/make_prm.cpp b/src/math/numbertheory/make_prm.cpp
index 30ac9a623..226f0c38f 100644
--- a/src/math/numbertheory/make_prm.cpp
+++ b/src/math/numbertheory/make_prm.cpp
@@ -1,7 +1,9 @@
-/*************************************************
-* Prime Generation Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Prime Generation
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#include <botan/numthry.h>
#include <botan/parsing.h>
@@ -9,9 +11,9 @@
namespace Botan {
-/*************************************************
-* Generate a random prime *
-*************************************************/
+/*
+* Generate a random prime
+*/
BigInt random_prime(RandomNumberGenerator& rng,
u32bit bits, const BigInt& coprime,
u32bit equiv, u32bit modulo)
@@ -76,9 +78,9 @@ BigInt random_prime(RandomNumberGenerator& rng,
}
}
-/*************************************************
-* Generate a random safe prime *
-*************************************************/
+/*
+* Generate a random safe prime
+*/
BigInt random_safe_prime(RandomNumberGenerator& rng, u32bit bits)
{
if(bits <= 64)
diff --git a/src/math/numbertheory/mp_numth.cpp b/src/math/numbertheory/mp_numth.cpp
index b024d2e2d..45a398440 100644
--- a/src/math/numbertheory/mp_numth.cpp
+++ b/src/math/numbertheory/mp_numth.cpp
@@ -1,7 +1,9 @@
-/*************************************************
-* Fused and Important MP Algorithms Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Fused and Important MP Algorithms
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#include <botan/numthry.h>
#include <botan/mp_core.h>
@@ -10,9 +12,9 @@
namespace Botan {
-/*************************************************
-* Square a BigInt *
-*************************************************/
+/*
+* Square a BigInt
+*/
BigInt square(const BigInt& x)
{
const u32bit x_sw = x.sig_words();
@@ -25,9 +27,9 @@ BigInt square(const BigInt& x)
return z;
}
-/*************************************************
-* Multiply-Add Operation *
-*************************************************/
+/*
+* Multiply-Add Operation
+*/
BigInt mul_add(const BigInt& a, const BigInt& b, const BigInt& c)
{
if(c.is_negative() || c.is_zero())
@@ -52,9 +54,9 @@ BigInt mul_add(const BigInt& a, const BigInt& b, const BigInt& c)
return r;
}
-/*************************************************
-* Subtract-Multiply Operation *
-*************************************************/
+/*
+* Subtract-Multiply Operation
+*/
BigInt sub_mul(const BigInt& a, const BigInt& b, const BigInt& c)
{
if(a.is_negative() || b.is_negative())
diff --git a/src/math/numbertheory/numthry.cpp b/src/math/numbertheory/numthry.cpp
index ffd523e82..d634ca88c 100644
--- a/src/math/numbertheory/numthry.cpp
+++ b/src/math/numbertheory/numthry.cpp
@@ -1,7 +1,9 @@
-/*************************************************
-* Number Theory Source File *
-* (C) 1999-2008 Jack Lloyd *
-*************************************************/
+/*
+* Number Theory
+* (C) 1999-2008 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#include <botan/numthry.h>
#include <botan/bit_ops.h>
@@ -11,9 +13,9 @@ namespace Botan {
namespace {
-/*************************************************
-* Miller-Rabin Iterations *
-*************************************************/
+/*
+* Miller-Rabin Iterations
+*/
u32bit miller_rabin_test_iterations(u32bit bits, bool verify)
{
struct mapping { u32bit bits; u32bit verify_iter; u32bit check_iter; };
@@ -69,9 +71,9 @@ u32bit miller_rabin_test_iterations(u32bit bits, bool verify)
}
-/*************************************************
-* Return the number of 0 bits at the end of n *
-*************************************************/
+/*
+* Return the number of 0 bits at the end of n
+*/
u32bit low_zero_bits(const BigInt& n)
{
if(n.is_negative() || n.is_zero()) return 0;
@@ -97,9 +99,9 @@ u32bit low_zero_bits(const BigInt& n)
return low_zero;
}
-/*************************************************
-* Calculate the GCD *
-*************************************************/
+/*
+* Calculate the GCD
+*/
BigInt gcd(const BigInt& a, const BigInt& b)
{
if(a.is_zero() || b.is_zero()) return 0;
@@ -124,17 +126,17 @@ BigInt gcd(const BigInt& a, const BigInt& b)
return (y << shift);
}
-/*************************************************
-* Calculate the LCM *
-*************************************************/
+/*
+* Calculate the LCM
+*/
BigInt lcm(const BigInt& a, const BigInt& b)
{
return ((a * b) / gcd(a, b));
}
-/*************************************************
-* Find the Modular Inverse *
-*************************************************/
+/*
+* Find the Modular Inverse
+*/
BigInt inverse_mod(const BigInt& n, const BigInt& mod)
{
if(mod.is_zero())
@@ -181,9 +183,9 @@ BigInt inverse_mod(const BigInt& n, const BigInt& mod)
return D;
}
-/*************************************************
-* Modular Exponentiation *
-*************************************************/
+/*
+* Modular Exponentiation
+*/
BigInt power_mod(const BigInt& base, const BigInt& exp, const BigInt& mod)
{
Power_Mod pow_mod(mod);
@@ -192,9 +194,9 @@ BigInt power_mod(const BigInt& base, const BigInt& exp, const BigInt& mod)
return pow_mod.execute();
}
-/*************************************************
-* Do simple tests of primality *
-*************************************************/
+/*
+* Do simple tests of primality
+*/
s32bit simple_primality_tests(const BigInt& n)
{
const s32bit NOT_PRIME = -1, UNKNOWN = 0, PRIME = 1;
@@ -223,33 +225,33 @@ s32bit simple_primality_tests(const BigInt& n)
return UNKNOWN;
}
-/*************************************************
-* Fast check of primality *
-*************************************************/
+/*
+* Fast check of primality
+*/
bool check_prime(const BigInt& n, RandomNumberGenerator& rng)
{
return run_primality_tests(rng, n, 0);
}
-/*************************************************
-* Test for primality *
-*************************************************/
+/*
+* Test for primality
+*/
bool is_prime(const BigInt& n, RandomNumberGenerator& rng)
{
return run_primality_tests(rng, n, 1);
}
-/*************************************************
-* Verify primality *
-*************************************************/
+/*
+* Verify primality
+*/
bool verify_prime(const BigInt& n, RandomNumberGenerator& rng)
{
return run_primality_tests(rng, n, 2);
}
-/*************************************************
-* Verify primality *
-*************************************************/
+/*
+* Verify primality
+*/
bool run_primality_tests(RandomNumberGenerator& rng,
const BigInt& n, u32bit level)
{
@@ -258,9 +260,9 @@ bool run_primality_tests(RandomNumberGenerator& rng,
return passes_mr_tests(rng, n, level);
}
-/*************************************************
-* Test for primaility using Miller-Rabin *
-*************************************************/
+/*
+* Test for primaility using Miller-Rabin
+*/
bool passes_mr_tests(RandomNumberGenerator& rng,
const BigInt& n, u32bit level)
{
@@ -295,9 +297,9 @@ bool passes_mr_tests(RandomNumberGenerator& rng,
return true;
}
-/*************************************************
-* Miller-Rabin Test *
-*************************************************/
+/*
+* Miller-Rabin Test
+*/
bool MillerRabin_Test::passes_test(const BigInt& a)
{
if(a < 2 || a >= n_minus_1)
@@ -319,9 +321,9 @@ bool MillerRabin_Test::passes_test(const BigInt& a)
return false;
}
-/*************************************************
-* Miller-Rabin Constructor *
-*************************************************/
+/*
+* Miller-Rabin Constructor
+*/
MillerRabin_Test::MillerRabin_Test(const BigInt& num)
{
if(num.is_even() || num < 3)
diff --git a/src/math/numbertheory/numthry.h b/src/math/numbertheory/numthry.h
index 78910d063..e4c043799 100644
--- a/src/math/numbertheory/numthry.h
+++ b/src/math/numbertheory/numthry.h
@@ -1,7 +1,9 @@
-/*************************************************
-* Number Theory Functions Header File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Number Theory Functions
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#ifndef BOTAN_NUMBER_THEORY_H__
#define BOTAN_NUMBER_THEORY_H__
@@ -13,15 +15,15 @@
namespace Botan {
-/*************************************************
-* Fused Arithmetic Operations *
-*************************************************/
+/*
+* Fused Arithmetic Operations
+*/
BigInt BOTAN_DLL mul_add(const BigInt&, const BigInt&, const BigInt&);
BigInt BOTAN_DLL sub_mul(const BigInt&, const BigInt&, const BigInt&);
-/*************************************************
-* Number Theory Functions *
-*************************************************/
+/*
+* Number Theory Functions
+*/
inline BigInt abs(const BigInt& n) { return n.abs(); }
void BOTAN_DLL divide(const BigInt&, const BigInt&, BigInt&, BigInt&);
@@ -35,20 +37,20 @@ s32bit BOTAN_DLL jacobi(const BigInt&, const BigInt&);
BigInt BOTAN_DLL power_mod(const BigInt&, const BigInt&, const BigInt&);
-/*************************************************
-* Compute the square root of x modulo a prime *
-* using the Shanks-Tonnelli algorithm *
-*************************************************/
+/*
+* Compute the square root of x modulo a prime
+* using the Shanks-Tonnelli algorithm
+*/
BigInt ressol(const BigInt& x, const BigInt& p);
-/*************************************************
-* Utility Functions *
-*************************************************/
+/*
+* Utility Functions
+*/
u32bit BOTAN_DLL low_zero_bits(const BigInt&);
-/*************************************************
-* Primality Testing *
-*************************************************/
+/*
+* Primality Testing
+*/
bool BOTAN_DLL check_prime(const BigInt&, RandomNumberGenerator&);
bool BOTAN_DLL is_prime(const BigInt&, RandomNumberGenerator&);
bool BOTAN_DLL verify_prime(const BigInt&, RandomNumberGenerator&);
@@ -61,9 +63,9 @@ bool BOTAN_DLL passes_mr_tests(RandomNumberGenerator&,
bool BOTAN_DLL run_primality_tests(RandomNumberGenerator&,
const BigInt&, u32bit = 1);
-/*************************************************
-* Random Number Generation *
-*************************************************/
+/*
+* Random Number Generation
+*/
BigInt BOTAN_DLL random_prime(RandomNumberGenerator&,
u32bit bits, const BigInt& coprime = 1,
u32bit equiv = 1, u32bit equiv_mod = 2);
@@ -71,9 +73,9 @@ BigInt BOTAN_DLL random_prime(RandomNumberGenerator&,
BigInt BOTAN_DLL random_safe_prime(RandomNumberGenerator&,
u32bit);
-/*************************************************
-* DSA Parameter Generation *
-*************************************************/
+/*
+* DSA Parameter Generation
+*/
class Algorithm_Factory;
SecureVector<byte> BOTAN_DLL
@@ -89,18 +91,18 @@ generate_dsa_primes(RandomNumberGenerator& rng,
u32bit p_bits, u32bit q_bits,
const MemoryRegion<byte>& seed);
-/*************************************************
-* Prime Numbers *
-*************************************************/
+/*
+* Prime Numbers
+*/
const u32bit PRIME_TABLE_SIZE = 6541;
const u32bit PRIME_PRODUCTS_TABLE_SIZE = 256;
extern const u16bit BOTAN_DLL PRIMES[];
extern const u64bit PRIME_PRODUCTS[];
-/*************************************************
-* Miller-Rabin Primality Tester *
-*************************************************/
+/*
+* Miller-Rabin Primality Tester
+*/
class BOTAN_DLL MillerRabin_Test
{
public:
diff --git a/src/math/numbertheory/pow_mod.cpp b/src/math/numbertheory/pow_mod.cpp
index 17ca7b796..4801a945c 100644
--- a/src/math/numbertheory/pow_mod.cpp
+++ b/src/math/numbertheory/pow_mod.cpp
@@ -1,25 +1,27 @@
-/*************************************************
-* Modular Exponentiation Proxy Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Modular Exponentiation Proxy
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#include <botan/pow_mod.h>
#include <botan/engine.h>
namespace Botan {
-/*************************************************
-* Power_Mod Constructor *
-*************************************************/
+/*
+* Power_Mod Constructor
+*/
Power_Mod::Power_Mod(const BigInt& n, Usage_Hints hints)
{
core = 0;
set_modulus(n, hints);
}
-/*************************************************
-* Power_Mod Copy Constructor *
-*************************************************/
+/*
+* Power_Mod Copy Constructor
+*/
Power_Mod::Power_Mod(const Power_Mod& other)
{
core = 0;
@@ -27,9 +29,9 @@ Power_Mod::Power_Mod(const Power_Mod& other)
core = other.core->copy();
}
-/*************************************************
-* Power_Mod Assignment Operator *
-*************************************************/
+/*
+* Power_Mod Assignment Operator
+*/
Power_Mod& Power_Mod::operator=(const Power_Mod& other)
{
delete core;
@@ -39,26 +41,26 @@ Power_Mod& Power_Mod::operator=(const Power_Mod& other)
return (*this);
}
-/*************************************************
-* Power_Mod Destructor *
-*************************************************/
+/*
+* Power_Mod Destructor
+*/
Power_Mod::~Power_Mod()
{
delete core;
}
-/*************************************************
-* Set the modulus *
-*************************************************/
+/*
+* Set the modulus
+*/
void Power_Mod::set_modulus(const BigInt& n, Usage_Hints hints) const
{
delete core;
core = ((n == 0) ? 0 : Engine_Core::mod_exp(n, hints));
}
-/*************************************************
-* Set the base *
-*************************************************/
+/*
+* Set the base
+*/
void Power_Mod::set_base(const BigInt& b) const
{
if(b.is_zero() || b.is_negative())
@@ -69,9 +71,9 @@ void Power_Mod::set_base(const BigInt& b) const
core->set_base(b);
}
-/*************************************************
-* Set the exponent *
-*************************************************/
+/*
+* Set the exponent
+*/
void Power_Mod::set_exponent(const BigInt& e) const
{
if(e.is_negative())
@@ -82,9 +84,9 @@ void Power_Mod::set_exponent(const BigInt& e) const
core->set_exponent(e);
}
-/*************************************************
-* Compute the result *
-*************************************************/
+/*
+* Compute the result
+*/
BigInt Power_Mod::execute() const
{
if(!core)
@@ -94,9 +96,9 @@ BigInt Power_Mod::execute() const
namespace {
-/*************************************************
-* Choose potentially useful hints *
-*************************************************/
+/*
+* Choose potentially useful hints
+*/
Power_Mod::Usage_Hints choose_base_hints(const BigInt& b, const BigInt& n)
{
if(b == 2)
@@ -114,9 +116,9 @@ Power_Mod::Usage_Hints choose_base_hints(const BigInt& b, const BigInt& n)
return Power_Mod::NO_HINTS;
}
-/*************************************************
-* Choose potentially useful hints *
-*************************************************/
+/*
+* Choose potentially useful hints
+*/
Power_Mod::Usage_Hints choose_exp_hints(const BigInt& e, const BigInt& n)
{
const u32bit e_bits = e.bits();
@@ -131,9 +133,9 @@ Power_Mod::Usage_Hints choose_exp_hints(const BigInt& e, const BigInt& n)
}
-/*************************************************
-* Fixed_Exponent_Power_Mod Constructor *
-*************************************************/
+/*
+* Fixed_Exponent_Power_Mod Constructor
+*/
Fixed_Exponent_Power_Mod::Fixed_Exponent_Power_Mod(const BigInt& e,
const BigInt& n,
Usage_Hints hints) :
@@ -142,9 +144,9 @@ Fixed_Exponent_Power_Mod::Fixed_Exponent_Power_Mod(const BigInt& e,
set_exponent(e);
}
-/*************************************************
-* Fixed_Base_Power_Mod Constructor *
-*************************************************/
+/*
+* Fixed_Base_Power_Mod Constructor
+*/
Fixed_Base_Power_Mod::Fixed_Base_Power_Mod(const BigInt& b, const BigInt& n,
Usage_Hints hints) :
Power_Mod(n, Usage_Hints(hints | BASE_IS_FIXED | choose_base_hints(b, n)))
diff --git a/src/math/numbertheory/pow_mod.h b/src/math/numbertheory/pow_mod.h
index 37e0871da..6952dcd1b 100644
--- a/src/math/numbertheory/pow_mod.h
+++ b/src/math/numbertheory/pow_mod.h
@@ -1,7 +1,9 @@
-/*************************************************
-* Modular Exponentiator Header File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Modular Exponentiator
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#ifndef BOTAN_POWER_MOD_H__
#define BOTAN_POWER_MOD_H__
@@ -10,9 +12,9 @@
namespace Botan {
-/*************************************************
-* Modular Exponentiator Interface *
-*************************************************/
+/*
+* Modular Exponentiator Interface
+*/
class BOTAN_DLL Modular_Exponentiator
{
public:
@@ -23,9 +25,9 @@ class BOTAN_DLL Modular_Exponentiator
virtual ~Modular_Exponentiator() {}
};
-/*************************************************
-* Modular Exponentiator Proxy *
-*************************************************/
+/*
+* Modular Exponentiator Proxy
+*/
class BOTAN_DLL Power_Mod
{
public:
@@ -58,9 +60,9 @@ class BOTAN_DLL Power_Mod
Usage_Hints hints;
};
-/*************************************************
-* Fixed Exponent Modular Exponentiator Proxy *
-*************************************************/
+/*
+* Fixed Exponent Modular Exponentiator Proxy
+*/
class BOTAN_DLL Fixed_Exponent_Power_Mod : public Power_Mod
{
public:
@@ -72,9 +74,9 @@ class BOTAN_DLL Fixed_Exponent_Power_Mod : public Power_Mod
Usage_Hints = NO_HINTS);
};
-/*************************************************
-* Fixed Base Modular Exponentiator Proxy *
-*************************************************/
+/*
+* Fixed Base Modular Exponentiator Proxy
+*/
class BOTAN_DLL Fixed_Base_Power_Mod : public Power_Mod
{
public:
diff --git a/src/math/numbertheory/powm_fw.cpp b/src/math/numbertheory/powm_fw.cpp
index c29b9f311..b764ee7aa 100644
--- a/src/math/numbertheory/powm_fw.cpp
+++ b/src/math/numbertheory/powm_fw.cpp
@@ -1,7 +1,9 @@
-/*************************************************
-* Fixed Window Exponentiation Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Fixed Window Exponentiation
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#include <botan/def_powm.h>
#include <botan/numthry.h>
@@ -11,9 +13,9 @@ namespace Botan {
namespace {
-/*************************************************
-* Try to choose a good window size *
-*************************************************/
+/*
+* Try to choose a good window size
+*/
u32bit choose_window_bits(u32bit exp_bits, u32bit,
Power_Mod::Usage_Hints hints)
{
@@ -47,17 +49,17 @@ u32bit choose_window_bits(u32bit exp_bits, u32bit,
}
-/*************************************************
-* Set the exponent *
-*************************************************/
+/*
+* Set the exponent
+*/
void Fixed_Window_Exponentiator::set_exponent(const BigInt& e)
{
exp = e;
}
-/*************************************************
-* Set the base *
-*************************************************/
+/*
+* Set the base
+*/
void Fixed_Window_Exponentiator::set_base(const BigInt& base)
{
window_bits = choose_window_bits(exp.bits(), base.bits(), hints);
@@ -68,9 +70,9 @@ void Fixed_Window_Exponentiator::set_base(const BigInt& base)
g[j] = reducer.multiply(g[j-1], g[0]);
}
-/*************************************************
-* Compute the result *
-*************************************************/
+/*
+* Compute the result
+*/
BigInt Fixed_Window_Exponentiator::execute() const
{
const u32bit exp_nibbles = (exp.bits() + window_bits - 1) / window_bits;
@@ -88,9 +90,9 @@ BigInt Fixed_Window_Exponentiator::execute() const
return x;
}
-/*************************************************
-* Fixed_Window_Exponentiator Constructor *
-*************************************************/
+/*
+* Fixed_Window_Exponentiator Constructor
+*/
Fixed_Window_Exponentiator::Fixed_Window_Exponentiator(const BigInt& n,
Power_Mod::Usage_Hints hints)
{
diff --git a/src/math/numbertheory/powm_mnt.cpp b/src/math/numbertheory/powm_mnt.cpp
index 6091d467a..e6d8cc3f0 100644
--- a/src/math/numbertheory/powm_mnt.cpp
+++ b/src/math/numbertheory/powm_mnt.cpp
@@ -1,7 +1,9 @@
-/*************************************************
-* Montgomery Exponentiation Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Montgomery Exponentiation
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#include <botan/def_powm.h>
#include <botan/numthry.h>
@@ -11,9 +13,9 @@ namespace Botan {
namespace {
-/*************************************************
-* Try to choose a good window size *
-*************************************************/
+/*
+* Try to choose a good window size
+*/
u32bit choose_window_bits(u32bit exp_bits, u32bit,
Power_Mod::Usage_Hints hints)
{
@@ -43,9 +45,9 @@ u32bit choose_window_bits(u32bit exp_bits, u32bit,
return window_bits;
}
-/*************************************************
-* Montgomery Reduction *
-*************************************************/
+/*
+* Montgomery Reduction
+*/
inline void montgomery_reduce(BigInt& out, MemoryRegion<word>& z_buf,
const BigInt& x_bn, u32bit x_size, word u)
{
@@ -60,18 +62,18 @@ inline void montgomery_reduce(BigInt& out, MemoryRegion<word>& z_buf,
}
-/*************************************************
-* Set the exponent *
-*************************************************/
+/*
+* Set the exponent
+*/
void Montgomery_Exponentiator::set_exponent(const BigInt& exp)
{
this->exp = exp;
exp_bits = exp.bits();
}
-/*************************************************
-* Set the base *
-*************************************************/
+/*
+* Set the base
+*/
void Montgomery_Exponentiator::set_base(const BigInt& base)
{
window_bits = choose_window_bits(exp.bits(), base.bits(), hints);
@@ -105,9 +107,9 @@ void Montgomery_Exponentiator::set_base(const BigInt& base)
}
}
-/*************************************************
-* Compute the result *
-*************************************************/
+/*
+* Compute the result
+*/
BigInt Montgomery_Exponentiator::execute() const
{
const u32bit exp_nibbles = (exp_bits + window_bits - 1) / window_bits;
@@ -148,9 +150,9 @@ BigInt Montgomery_Exponentiator::execute() const
return x;
}
-/*************************************************
-* Montgomery_Exponentiator Constructor *
-*************************************************/
+/*
+* Montgomery_Exponentiator Constructor
+*/
Montgomery_Exponentiator::Montgomery_Exponentiator(const BigInt& mod,
Power_Mod::Usage_Hints hints)
{
diff --git a/src/math/numbertheory/primes.cpp b/src/math/numbertheory/primes.cpp
index d005167e5..26ff098a5 100644
--- a/src/math/numbertheory/primes.cpp
+++ b/src/math/numbertheory/primes.cpp
@@ -1,7 +1,9 @@
-/*************************************************
-* Small Primes Table *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Small Primes Table
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#include <botan/numthry.h>
diff --git a/src/math/numbertheory/reducer.cpp b/src/math/numbertheory/reducer.cpp
index 47c5c20fc..fbd675ea6 100644
--- a/src/math/numbertheory/reducer.cpp
+++ b/src/math/numbertheory/reducer.cpp
@@ -1,7 +1,9 @@
-/*************************************************
-* Modular Reducer Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Modular Reducer
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#include <botan/reducer.h>
#include <botan/numthry.h>
@@ -9,9 +11,9 @@
namespace Botan {
-/*************************************************
-* Modular_Reducer Constructor *
-*************************************************/
+/*
+* Modular_Reducer Constructor
+*/
Modular_Reducer::Modular_Reducer(const BigInt& mod)
{
if(mod <= 0)
@@ -27,9 +29,9 @@ Modular_Reducer::Modular_Reducer(const BigInt& mod)
mu_words = mu.sig_words();
}
-/*************************************************
-* Barrett Reduction *
-*************************************************/
+/*
+* Barrett Reduction
+*/
BigInt Modular_Reducer::reduce(const BigInt& x) const
{
if(mod_words == 0)
@@ -76,17 +78,17 @@ BigInt Modular_Reducer::reduce(const BigInt& x) const
return t1;
}
-/*************************************************
-* Multiply, followed by a reduction *
-*************************************************/
+/*
+* Multiply, followed by a reduction
+*/
BigInt Modular_Reducer::multiply(const BigInt& x, const BigInt& y) const
{
return reduce(x * y);
}
-/*************************************************
-* Square, followed by a reduction *
-*************************************************/
+/*
+* Square, followed by a reduction
+*/
BigInt Modular_Reducer::square(const BigInt& x) const
{
return reduce(Botan::square(x));
diff --git a/src/math/numbertheory/reducer.h b/src/math/numbertheory/reducer.h
index 48008e73b..d234e0735 100644
--- a/src/math/numbertheory/reducer.h
+++ b/src/math/numbertheory/reducer.h
@@ -1,7 +1,9 @@
-/*************************************************
-* Modular Reducer Header File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Modular Reducer
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#ifndef BOTAN_MODARITH_H__
#define BOTAN_MODARITH_H__
@@ -10,9 +12,9 @@
namespace Botan {
-/*************************************************
-* Modular Reducer *
-*************************************************/
+/*
+* Modular Reducer
+*/
class BOTAN_DLL Modular_Reducer
{
public:
diff --git a/src/math/numbertheory/ressol.cpp b/src/math/numbertheory/ressol.cpp
index 0cd2b988a..6a078726d 100644
--- a/src/math/numbertheory/ressol.cpp
+++ b/src/math/numbertheory/ressol.cpp
@@ -1,8 +1,10 @@
-/*************************************************
-* Shanks-Tonnelli (RESSOL) Source File *
-* (C) 2007-2008 Falko Strenzke, FlexSecure GmbH *
-* (C) 2008 Jack Lloyd *
-*************************************************/
+/*
+* Shanks-Tonnelli (RESSOL)
+* (C) 2007-2008 Falko Strenzke, FlexSecure GmbH
+* (C) 2008 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#include <botan/numthry.h>
#include <botan/reducer.h>
@@ -11,9 +13,9 @@
namespace Botan {
-/*************************************************
-* Shanks-Tonnelli algorithm *
-*************************************************/
+/*
+* Shanks-Tonnelli algorithm
+*/
BigInt ressol(const BigInt& a, const BigInt& p)
{
if(a < 0)