aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-04-10 05:52:37 +0000
committerlloyd <[email protected]>2008-04-10 05:52:37 +0000
commitf15ca39257de8983babb95f7f5d589a4e555a864 (patch)
tree3f41f5e38cc5d07e3241db716d582fa146a4ac3d /src
parent59e71322cad61ff2f09664fc3e59b5446af4566a (diff)
parent9ec64ce60cad6c825b7cf40306a359d019e2c13c (diff)
propagate from branch 'net.randombit.botan' (head 6afe2db1f710f75bc27e189bb8bdb23613ce1ca3)
to branch 'net.randombit.botan.remove-libstate' (head e40f0dbdfd847024c30fa0092c2acefc19a550b8)
Diffstat (limited to 'src')
-rw-r--r--src/big_rand.cpp4
-rw-r--r--src/buf_es.cpp8
-rw-r--r--src/charset.cpp103
-rw-r--r--src/def_char.cpp121
-rw-r--r--src/dsa_gen.cpp13
-rw-r--r--src/eme1.cpp4
-rw-r--r--src/eme_pkcs.cpp4
-rw-r--r--src/emsa4.cpp4
-rw-r--r--src/filter.cpp2
-rw-r--r--src/keypair.cpp6
-rw-r--r--src/libstate.cpp104
-rw-r--r--src/make_prm.cpp12
-rw-r--r--src/modules.cpp39
-rw-r--r--src/numthry.cpp3
-rw-r--r--src/pbes1.cpp4
-rw-r--r--src/pbes2.cpp6
-rw-r--r--src/randpool.cpp2
-rw-r--r--src/rng.cpp65
-rw-r--r--src/s2k.cpp4
-rw-r--r--src/symkey.cpp4
-rw-r--r--src/timers.cpp24
-rw-r--r--src/x509_ext.cpp27
-rw-r--r--src/x509stat.cpp76
23 files changed, 185 insertions, 454 deletions
diff --git a/src/big_rand.cpp b/src/big_rand.cpp
index c18aadfeb..264f5dcb3 100644
--- a/src/big_rand.cpp
+++ b/src/big_rand.cpp
@@ -6,7 +6,7 @@
#include <botan/bigint.h>
#include <botan/parsing.h>
#include <botan/numthry.h>
-#include <botan/rng.h>
+#include <botan/libstate.h>
namespace Botan {
@@ -36,7 +36,7 @@ void BigInt::randomize(u32bit bitsize)
else
{
SecureVector<byte> array((bitsize + 7) / 8);
- Global_RNG::randomize(array, array.size());
+ global_state().randomize(array, array.size());
if(bitsize % 8)
array[0] &= 0xFF >> (8 - (bitsize % 8));
array[0] |= 0x80 >> ((bitsize % 8) ? (8 - bitsize % 8) : 0);
diff --git a/src/buf_es.cpp b/src/buf_es.cpp
index bf5a9732e..9f7be3e9b 100644
--- a/src/buf_es.cpp
+++ b/src/buf_es.cpp
@@ -74,14 +74,6 @@ void Buffered_EntropySource::add_bytes(u64bit entropy)
}
/*************************************************
-* Add entropy to the internal buffer *
-*************************************************/
-void Buffered_EntropySource::add_timestamp()
- {
- add_bytes(system_clock());
- }
-
-/*************************************************
* Take entropy from the internal buffer *
*************************************************/
u32bit Buffered_EntropySource::copy_out(byte out[], u32bit length,
diff --git a/src/charset.cpp b/src/charset.cpp
index 3025794ff..4ebf37abf 100644
--- a/src/charset.cpp
+++ b/src/charset.cpp
@@ -6,20 +6,119 @@
#include <botan/charset.h>
#include <botan/hex.h>
#include <botan/base64.h>
-#include <botan/libstate.h>
+#include <botan/parsing.h>
#include <cctype>
namespace Botan {
namespace Charset {
+namespace {
+
+/*************************************************
+* Convert from UCS-2 to ISO 8859-1 *
+*************************************************/
+std::string ucs2_to_latin1(const std::string& ucs2)
+ {
+ if(ucs2.size() % 2 == 1)
+ throw Decoding_Error("UCS-2 string has an odd number of bytes");
+
+ std::string latin1;
+
+ for(u32bit j = 0; j != ucs2.size(); j += 2)
+ {
+ const byte c1 = ucs2[j];
+ const byte c2 = ucs2[j+1];
+
+ if(c1 != 0)
+ throw Decoding_Error("UCS-2 has non-Latin1 characters");
+
+ latin1 += static_cast<char>(c2);
+ }
+
+ return latin1;
+ }
+
+/*************************************************
+* Convert from UTF-8 to ISO 8859-1 *
+*************************************************/
+std::string utf8_to_latin1(const std::string& utf8)
+ {
+ std::string iso8859;
+
+ u32bit position = 0;
+ while(position != utf8.size())
+ {
+ const byte c1 = static_cast<byte>(utf8[position++]);
+
+ if(c1 <= 0x7F)
+ iso8859 += static_cast<char>(c1);
+ else if(c1 >= 0xC0 && c1 <= 0xC7)
+ {
+ if(position == utf8.size())
+ throw Decoding_Error("UTF-8: sequence truncated");
+
+ const byte c2 = static_cast<byte>(utf8[position++]);
+ const byte iso_char = ((c1 & 0x07) << 6) | (c2 & 0x3F);
+
+ if(iso_char <= 0x7F)
+ throw Decoding_Error("UTF-8: sequence longer than needed");
+
+ iso8859 += static_cast<char>(iso_char);
+ }
+ else
+ throw Decoding_Error("UTF-8: Unicode chars not in Latin1 used");
+ }
+
+ return iso8859;
+ }
+
+/*************************************************
+* Convert from ISO 8859-1 to UTF-8 *
+*************************************************/
+std::string latin1_to_utf8(const std::string& iso8859)
+ {
+ std::string utf8;
+ for(u32bit j = 0; j != iso8859.size(); ++j)
+ {
+ const byte c = static_cast<byte>(iso8859[j]);
+
+ if(c <= 0x7F)
+ utf8 += static_cast<char>(c);
+ else
+ {
+ utf8 += static_cast<char>((0xC0 | (c >> 6)));
+ utf8 += static_cast<char>((0x80 | (c & 0x3F)));
+ }
+ }
+ return utf8;
+ }
+
+}
+
/*************************************************
* Perform character set transcoding *
*************************************************/
std::string transcode(const std::string& str,
Character_Set to, Character_Set from)
{
- return global_state().transcode(str, to, from);
+ if(to == LOCAL_CHARSET)
+ to = LATIN1_CHARSET;
+ if(from == LOCAL_CHARSET)
+ from = LATIN1_CHARSET;
+
+ if(to == from)
+ return str;
+
+ if(from == LATIN1_CHARSET && to == UTF8_CHARSET)
+ return latin1_to_utf8(str);
+ if(from == UTF8_CHARSET && to == LATIN1_CHARSET)
+ return utf8_to_latin1(str);
+ if(from == UCS2_CHARSET && to == LATIN1_CHARSET)
+ return ucs2_to_latin1(str);
+
+ throw Invalid_Argument("Unknown transcoding operation from " +
+ to_string(from) + " to " + to_string(to));
}
/*************************************************
diff --git a/src/def_char.cpp b/src/def_char.cpp
deleted file mode 100644
index 512647eb2..000000000
--- a/src/def_char.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/*************************************************
-* Default Character Set Handling Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
-
-#include <botan/def_char.h>
-#include <botan/exceptn.h>
-#include <botan/parsing.h>
-
-namespace Botan {
-
-namespace {
-
-/*************************************************
-* Convert from UCS-2 to ISO 8859-1 *
-*************************************************/
-std::string ucs2_to_latin1(const std::string& ucs2)
- {
- if(ucs2.size() % 2 == 1)
- throw Decoding_Error("UCS-2 string has an odd number of bytes");
-
- std::string latin1;
-
- for(u32bit j = 0; j != ucs2.size(); j += 2)
- {
- const byte c1 = ucs2[j];
- const byte c2 = ucs2[j+1];
-
- if(c1 != 0)
- throw Decoding_Error("UCS-2 has non-Latin1 characters");
-
- latin1 += static_cast<char>(c2);
- }
-
- return latin1;
- }
-
-/*************************************************
-* Convert from UTF-8 to ISO 8859-1 *
-*************************************************/
-std::string utf8_to_latin1(const std::string& utf8)
- {
- std::string iso8859;
-
- u32bit position = 0;
- while(position != utf8.size())
- {
- const byte c1 = static_cast<byte>(utf8[position++]);
-
- if(c1 <= 0x7F)
- iso8859 += static_cast<char>(c1);
- else if(c1 >= 0xC0 && c1 <= 0xC7)
- {
- if(position == utf8.size())
- throw Decoding_Error("UTF-8: sequence truncated");
-
- const byte c2 = static_cast<byte>(utf8[position++]);
- const byte iso_char = ((c1 & 0x07) << 6) | (c2 & 0x3F);
-
- if(iso_char <= 0x7F)
- throw Decoding_Error("UTF-8: sequence longer than needed");
-
- iso8859 += static_cast<char>(iso_char);
- }
- else
- throw Decoding_Error("UTF-8: Unicode chars not in Latin1 used");
- }
-
- return iso8859;
- }
-
-/*************************************************
-* Convert from ISO 8859-1 to UTF-8 *
-*************************************************/
-std::string latin1_to_utf8(const std::string& iso8859)
- {
- std::string utf8;
- for(u32bit j = 0; j != iso8859.size(); ++j)
- {
- const byte c = static_cast<byte>(iso8859[j]);
-
- if(c <= 0x7F)
- utf8 += static_cast<char>(c);
- else
- {
- utf8 += static_cast<char>((0xC0 | (c >> 6)));
- utf8 += static_cast<char>((0x80 | (c & 0x3F)));
- }
- }
- return utf8;
- }
-
-}
-
-/*************************************************
-* Transcode between character sets *
-*************************************************/
-std::string Default_Charset_Transcoder::transcode(const std::string& str,
- Character_Set to,
- Character_Set from) const
- {
- if(to == LOCAL_CHARSET)
- to = LATIN1_CHARSET;
- if(from == LOCAL_CHARSET)
- from = LATIN1_CHARSET;
-
- if(to == from)
- return str;
-
- if(from == LATIN1_CHARSET && to == UTF8_CHARSET)
- return latin1_to_utf8(str);
- if(from == UTF8_CHARSET && to == LATIN1_CHARSET)
- return utf8_to_latin1(str);
- if(from == UCS2_CHARSET && to == LATIN1_CHARSET)
- return ucs2_to_latin1(str);
-
- throw Invalid_Argument("Unknown transcoding operation from " +
- to_string(from) + " to " + to_string(to));
- }
-
-}
diff --git a/src/dsa_gen.cpp b/src/dsa_gen.cpp
index 576c9a938..002af7d96 100644
--- a/src/dsa_gen.cpp
+++ b/src/dsa_gen.cpp
@@ -5,10 +5,9 @@
#include <botan/dl_group.h>
#include <botan/numthry.h>
-#include <botan/libstate.h>
#include <botan/lookup.h>
#include <botan/parsing.h>
-#include <botan/rng.h>
+#include <botan/libstate.h>
#include <algorithm>
#include <memory>
@@ -84,8 +83,6 @@ bool DL_Group::generate_dsa_primes(BigInt& p, BigInt& q,
if(!is_prime(q))
return false;
- global_state().pulse(PRIME_FOUND);
-
const u32bit n = (pbits-1) / (HASH_SIZE * 8),
b = (pbits-1) % (HASH_SIZE * 8);
@@ -94,8 +91,6 @@ bool DL_Group::generate_dsa_primes(BigInt& p, BigInt& q,
for(u32bit j = 0; j != 4096; ++j)
{
- global_state().pulse(PRIME_SEARCHING);
-
for(u32bit k = 0; k <= n; ++k)
{
++seed;
@@ -110,10 +105,7 @@ bool DL_Group::generate_dsa_primes(BigInt& p, BigInt& q,
p = X - (X % (2*q) - 1);
if(p.bits() == pbits && is_prime(p))
- {
- global_state().pulse(PRIME_FOUND);
return true;
- }
}
return false;
}
@@ -128,8 +120,7 @@ SecureVector<byte> DL_Group::generate_dsa_primes(BigInt& p, BigInt& q,
while(true)
{
- Global_RNG::randomize(seed, seed.size());
- global_state().pulse(PRIME_SEARCHING);
+ global_state().randomize(seed, seed.size());
if(generate_dsa_primes(p, q, pbits, qbits, seed))
return seed;
diff --git a/src/eme1.cpp b/src/eme1.cpp
index 62c5e81bd..43b5a0027 100644
--- a/src/eme1.cpp
+++ b/src/eme1.cpp
@@ -4,7 +4,7 @@
*************************************************/
#include <botan/eme.h>
-#include <botan/rng.h>
+#include <botan/libstate.h>
#include <botan/lookup.h>
#include <botan/look_pk.h>
#include <memory>
@@ -26,7 +26,7 @@ SecureVector<byte> EME1::pad(const byte in[], u32bit in_length,
out.clear();
- Global_RNG::randomize(out, HASH_LENGTH);
+ global_state().randomize(out, HASH_LENGTH);
out.copy(HASH_LENGTH, Phash, Phash.size());
out[out.size() - in_length - 1] = 0x01;
diff --git a/src/eme_pkcs.cpp b/src/eme_pkcs.cpp
index a9bf30625..8296681d8 100644
--- a/src/eme_pkcs.cpp
+++ b/src/eme_pkcs.cpp
@@ -4,7 +4,7 @@
*************************************************/
#include <botan/eme.h>
-#include <botan/rng.h>
+#include <botan/libstate.h>
namespace Botan {
@@ -26,7 +26,7 @@ SecureVector<byte> EME_PKCS1v15::pad(const byte in[], u32bit inlen,
out[0] = 0x02;
for(u32bit j = 1; j != olen - inlen - 1; ++j)
while(out[j] == 0)
- out[j] = Global_RNG::random();
+ out[j] = global_state().random();
out.copy(olen - inlen, in, inlen);
return out;
diff --git a/src/emsa4.cpp b/src/emsa4.cpp
index 3465d63d7..831afd590 100644
--- a/src/emsa4.cpp
+++ b/src/emsa4.cpp
@@ -7,7 +7,7 @@
#include <botan/lookup.h>
#include <botan/look_pk.h>
#include <botan/bit_ops.h>
-#include <botan/rng.h>
+#include <botan/libstate.h>
namespace Botan {
@@ -43,7 +43,7 @@ SecureVector<byte> EMSA4::encoding_of(const MemoryRegion<byte>& msg,
const u32bit output_length = (output_bits + 7) / 8;
SecureVector<byte> salt(SALT_SIZE);
- Global_RNG::randomize(salt, SALT_SIZE);
+ global_state().randomize(salt, SALT_SIZE);
for(u32bit j = 0; j != 8; ++j)
hash->update(0);
diff --git a/src/filter.cpp b/src/filter.cpp
index b58b60332..a5bc2dea1 100644
--- a/src/filter.cpp
+++ b/src/filter.cpp
@@ -25,8 +25,6 @@ Filter::Filter()
*************************************************/
void Filter::send(const byte input[], u32bit length)
{
- global_state().pulse(PIPE_WRITE);
-
bool nothing_attached = true;
for(u32bit j = 0; j != total_ports(); ++j)
if(next[j])
diff --git a/src/keypair.cpp b/src/keypair.cpp
index 54d117293..edec0b572 100644
--- a/src/keypair.cpp
+++ b/src/keypair.cpp
@@ -5,7 +5,7 @@
#include <botan/keypair.h>
#include <botan/look_pk.h>
-#include <botan/rng.h>
+#include <botan/libstate.h>
#include <memory>
namespace Botan {
@@ -24,7 +24,7 @@ void check_key(PK_Encryptor* encryptor, PK_Decryptor* decryptor)
std::auto_ptr<PK_Decryptor> dec(decryptor);
SecureVector<byte> message(enc->maximum_input_size() - 1);
- Global_RNG::randomize(message, message.size());
+ global_state().randomize(message, message.size());
SecureVector<byte> ciphertext = enc->encrypt(message);
if(ciphertext == message)
@@ -44,7 +44,7 @@ void check_key(PK_Signer* signer, PK_Verifier* verifier)
std::auto_ptr<PK_Verifier> ver(verifier);
SecureVector<byte> message(16);
- Global_RNG::randomize(message, message.size());
+ global_state().randomize(message, message.size());
SecureVector<byte> signature;
diff --git a/src/libstate.cpp b/src/libstate.cpp
index 8221d09bd..260d37bf5 100644
--- a/src/libstate.cpp
+++ b/src/libstate.cpp
@@ -7,10 +7,8 @@
#include <botan/config.h>
#include <botan/modules.h>
#include <botan/engine.h>
-#include <botan/x509stat.h>
#include <botan/stl_util.h>
#include <botan/mutex.h>
-#include <botan/timers.h>
#include <botan/charset.h>
#include <botan/x931_rng.h>
#include <botan/fips140.h>
@@ -123,23 +121,6 @@ void Library_State::set_default_allocator(const std::string& type) const
}
/*************************************************
-* Set the high resolution clock implementation *
-*************************************************/
-void Library_State::set_timer(Timer* new_timer)
- {
- delete timer;
- timer = new_timer;
- }
-
-/*************************************************
-* Read a high resolution clock *
-*************************************************/
-u64bit Library_State::system_clock() const
- {
- return (timer) ? timer->clock() : 0;
- }
-
-/*************************************************
* Set the global PRNG *
*************************************************/
void Library_State::set_prng(RandomNumberGenerator* new_rng)
@@ -161,6 +142,16 @@ void Library_State::randomize(byte out[], u32bit length)
}
/*************************************************
+* Get a byte from the global PRNG *
+*************************************************/
+byte Library_State::random()
+ {
+ byte out;
+ rng->randomize(&out, 1);
+ return out;
+ }
+
+/*************************************************
* Add a new entropy source to use *
*************************************************/
void Library_State::add_entropy_source(EntropySource* src, bool last_in_list)
@@ -234,67 +225,6 @@ void Library_State::add_engine(Engine* engine)
}
/*************************************************
-* Set the character set transcoder object *
-*************************************************/
-void Library_State::set_transcoder(class Charset_Transcoder* transcoder)
- {
- if(this->transcoder)
- delete this->transcoder;
- this->transcoder = transcoder;
- }
-
-/*************************************************
-* Transcode a string from one charset to another *
-*************************************************/
-std::string Library_State::transcode(const std::string str,
- Character_Set to,
- Character_Set from) const
- {
- if(!transcoder)
- throw Invalid_State("Library_State::transcode: No transcoder set");
-
- return transcoder->transcode(str, to, from);
- }
-
-/*************************************************
-* Set the X509 global state class *
-*************************************************/
-void Library_State::set_x509_state(X509_GlobalState* new_x509_state_obj)
- {
- delete x509_state_obj;
- x509_state_obj = new_x509_state_obj;
- }
-
-/*************************************************
-* Get the X509 global state class *
-*************************************************/
-X509_GlobalState& Library_State::x509_state()
- {
- if(!x509_state_obj)
- x509_state_obj = new X509_GlobalState();
-
- return (*x509_state_obj);
- }
-
-/*************************************************
-* Set the UI object state *
-*************************************************/
-void Library_State::set_ui(UI* new_ui)
- {
- delete ui;
- ui = new_ui;
- }
-
-/*************************************************
-* Send a pulse to the UI object *
-*************************************************/
-void Library_State::pulse(Pulse_Type pulse_type) const
- {
- if(ui)
- ui->pulse(pulse_type);
- }
-
-/*************************************************
* Set the configuration object *
*************************************************/
Config& Library_State::config() const
@@ -327,11 +257,6 @@ void Library_State::initialize(const InitializerOptions& args,
rng_lock = get_mutex();
cached_default_allocator = 0;
- x509_state_obj = 0;
- ui = 0;
-
- timer = modules.timer();
- transcoder = modules.transcoder();
std::vector<Allocator*> mod_allocs = modules.allocators();
for(u32bit j = 0; j != mod_allocs.size(); ++j)
@@ -378,15 +303,10 @@ Library_State::Library_State()
allocator_lock = engine_lock = rng_lock = 0;
- timer = 0;
config_obj = 0;
- x509_state_obj = 0;
- ui = 0;
- transcoder = 0;
rng = 0;
cached_default_allocator = 0;
- ui = 0;
}
/*************************************************
@@ -394,12 +314,8 @@ Library_State::Library_State()
*************************************************/
Library_State::~Library_State()
{
- delete x509_state_obj;
- delete transcoder;
delete rng;
- delete timer;
delete config_obj;
- delete ui;
std::for_each(entropy_sources.begin(), entropy_sources.end(),
del_fun<EntropySource>());
diff --git a/src/make_prm.cpp b/src/make_prm.cpp
index 01f524865..d5f9961af 100644
--- a/src/make_prm.cpp
+++ b/src/make_prm.cpp
@@ -29,8 +29,6 @@ BigInt random_prime(u32bit bits, const BigInt& coprime,
while(true)
{
- global_state().pulse(PRIME_SEARCHING);
-
BigInt p = random_integer(bits);
p.set_bit(bits - 2);
p.set_bit(0);
@@ -42,10 +40,7 @@ BigInt random_prime(u32bit bits, const BigInt& coprime,
SecureVector<u32bit> sieve(sieve_size);
for(u32bit j = 0; j != sieve.size(); ++j)
- {
sieve[j] = p % PRIMES[j];
- global_state().pulse(PRIME_SIEVING);
- }
u32bit counter = 0;
while(true)
@@ -53,8 +48,6 @@ BigInt random_prime(u32bit bits, const BigInt& coprime,
if(counter == 4096 || p.bits() > bits)
break;
- global_state().pulse(PRIME_SEARCHING);
-
bool passes_sieve = true;
++counter;
p += modulo;
@@ -62,19 +55,14 @@ BigInt random_prime(u32bit bits, const BigInt& coprime,
for(u32bit j = 0; j != sieve.size(); ++j)
{
sieve[j] = (sieve[j] + modulo) % PRIMES[j];
- global_state().pulse(PRIME_SIEVING);
if(sieve[j] == 0)
passes_sieve = false;
}
if(!passes_sieve || gcd(p - 1, coprime) != 1)
continue;
- global_state().pulse(PRIME_PASSED_SIEVE);
if(passes_mr_tests(p))
- {
- global_state().pulse(PRIME_FOUND);
return p;
- }
}
}
}
diff --git a/src/modules.cpp b/src/modules.cpp
index dc7dc917f..ffce244d1 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -5,7 +5,6 @@
#include <botan/modules.h>
#include <botan/defalloc.h>
-#include <botan/def_char.h>
#include <botan/eng_def.h>
#include <botan/timers.h>
#include <botan/parsing.h>
@@ -95,24 +94,6 @@ Mutex_Factory* Builtin_Modules::mutex_factory() const
}
/*************************************************
-* Find a high resolution timer, if possible *
-*************************************************/
-Timer* Builtin_Modules::timer() const
- {
-#if defined(BOTAN_EXT_TIMER_HARDWARE)
- return new Hardware_Timer;
-#elif defined(BOTAN_EXT_TIMER_POSIX)
- return new POSIX_Timer;
-#elif defined(BOTAN_EXT_TIMER_UNIX)
- return new Unix_Timer;
-#elif defined(BOTAN_EXT_TIMER_WIN32)
- return new Win32_Timer;
-#else
- return new Timer;
-#endif
- }
-
-/*************************************************
* Find any usable allocators *
*************************************************/
std::vector<Allocator*> Builtin_Modules::allocators() const
@@ -153,6 +134,18 @@ std::vector<EntropySource*> Builtin_Modules::entropy_sources() const
{
std::vector<EntropySource*> sources;
+#if defined(BOTAN_EXT_TIMER_HARDWARE)
+ sources.push_back(new Hardware_Timer);
+#elif defined(BOTAN_EXT_TIMER_POSIX)
+ sources.push_back(new POSIX_Timer);
+#elif defined(BOTAN_EXT_TIMER_UNIX)
+ sources.push_back(new Unix_Timer);
+#elif defined(BOTAN_EXT_TIMER_WIN32)
+ sources.push_back(new Win32_Timer);
+#else
+ sources.push_back(new Timer);
+#endif
+
#if defined(BOTAN_EXT_ENTROPY_SRC_AEP)
sources.push_back(new AEP_EntropySource);
#endif
@@ -217,14 +210,6 @@ std::vector<Engine*> Builtin_Modules::engines() const
}
/*************************************************
-* Find the best transcoder option *
-*************************************************/
-Charset_Transcoder* Builtin_Modules::transcoder() const
- {
- return new Default_Charset_Transcoder;
- }
-
-/*************************************************
* Builtin_Modules Constructor *
*************************************************/
Builtin_Modules::Builtin_Modules(const InitializerOptions& args) :
diff --git a/src/numthry.cpp b/src/numthry.cpp
index 233702138..01b46c982 100644
--- a/src/numthry.cpp
+++ b/src/numthry.cpp
@@ -284,15 +284,12 @@ bool MillerRabin_Test::passes_test(const BigInt& a)
if(a < 2 || a >= n_minus_1)
throw Invalid_Argument("Bad size for nonce in Miller-Rabin test");
- global_state().pulse(PRIME_TESTING);
-
BigInt y = pow_mod(a);
if(y == 1 || y == n_minus_1)
return true;
for(u32bit j = 1; j != s; ++j)
{
- global_state().pulse(PRIME_TESTING);
y = reducer.square(y);
if(y == 1)
diff --git a/src/pbes1.cpp b/src/pbes1.cpp
index fb8889fdc..8e548f6b4 100644
--- a/src/pbes1.cpp
+++ b/src/pbes1.cpp
@@ -8,7 +8,7 @@
#include <botan/ber_dec.h>
#include <botan/parsing.h>
#include <botan/lookup.h>
-#include <botan/rng.h>
+#include <botan/libstate.h>
#include <algorithm>
#include <memory>
@@ -86,7 +86,7 @@ void PBE_PKCS5v15::new_params()
{
iterations = 2048;
salt.create(8);
- Global_RNG::randomize(salt, salt.size());
+ global_state().randomize(salt, salt.size());
}
/*************************************************
diff --git a/src/pbes2.cpp b/src/pbes2.cpp
index f2c46b556..ea51597a3 100644
--- a/src/pbes2.cpp
+++ b/src/pbes2.cpp
@@ -8,7 +8,7 @@
#include <botan/ber_dec.h>
#include <botan/parsing.h>
#include <botan/lookup.h>
-#include <botan/rng.h>
+#include <botan/libstate.h>
#include <botan/asn1_obj.h>
#include <botan/oids.h>
#include <algorithm>
@@ -87,8 +87,8 @@ void PBE_PKCS5v20::new_params()
key_length = max_keylength_of(cipher_algo);
salt.create(8);
iv.create(block_size_of(cipher_algo));
- Global_RNG::randomize(salt, salt.size());
- Global_RNG::randomize(iv, iv.size());
+ global_state().randomize(salt, salt.size());
+ global_state().randomize(iv, iv.size());
}
/*************************************************
diff --git a/src/randpool.cpp b/src/randpool.cpp
index e935efe35..46968eee1 100644
--- a/src/randpool.cpp
+++ b/src/randpool.cpp
@@ -59,7 +59,7 @@ void Randpool::randomize(byte out[], u32bit length) throw(PRNG_Unseeded)
*************************************************/
void Randpool::update_buffer()
{
- const u64bit timestamp = system_clock();
+ const u64bit timestamp = system_time();
for(u32bit j = 0; j != counter.size(); ++j)
if(++counter[j])
diff --git a/src/rng.cpp b/src/rng.cpp
deleted file mode 100644
index dc93b56f6..000000000
--- a/src/rng.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/*************************************************
-* Global RNG Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
-
-#include <botan/rng.h>
-#include <botan/libstate.h>
-
-namespace Botan {
-
-namespace Global_RNG {
-
-/*************************************************
-* Get random bits from the global RNG *
-*************************************************/
-void randomize(byte output[], u32bit size)
- {
- global_state().randomize(output, size);
- }
-
-/*************************************************
-* Get random bits from the global RNG *
-*************************************************/
-byte random()
- {
- byte ret = 0;
- randomize(&ret, 1);
- return ret;
- }
-
-/*************************************************
-* Add entropy to the global RNG *
-*************************************************/
-void add_entropy(const byte entropy[], u32bit size)
- {
- global_state().add_entropy(entropy, size);
- }
-
-/*************************************************
-* Add entropy to the global RNG *
-*************************************************/
-void add_entropy(EntropySource& src, bool slow_poll)
- {
- global_state().add_entropy(src, slow_poll);
- }
-
-/*************************************************
-* Add an EntropySource to the RNG seed list *
-*************************************************/
-void add_es(EntropySource* src, bool last)
- {
- global_state().add_entropy_source(src, last);
- }
-
-/*************************************************
-* Seed the global RNG *
-*************************************************/
-u32bit seed(bool slow_poll, u32bit bits_to_get)
- {
- return global_state().seed_prng(slow_poll, bits_to_get);
- }
-
-}
-
-}
diff --git a/src/s2k.cpp b/src/s2k.cpp
index d20b6738c..e5668f32f 100644
--- a/src/s2k.cpp
+++ b/src/s2k.cpp
@@ -4,7 +4,7 @@
*************************************************/
#include <botan/s2k.h>
-#include <botan/rng.h>
+#include <botan/libstate.h>
namespace Botan {
@@ -47,7 +47,7 @@ void S2K::change_salt(const MemoryRegion<byte>& new_salt)
void S2K::new_random_salt(u32bit length)
{
salt.create(length);
- Global_RNG::randomize(salt, length);
+ global_state().randomize(salt, length);
}
}
diff --git a/src/symkey.cpp b/src/symkey.cpp
index 58c050aac..db70810fb 100644
--- a/src/symkey.cpp
+++ b/src/symkey.cpp
@@ -7,7 +7,7 @@
#include <botan/bit_ops.h>
#include <botan/pipe.h>
#include <botan/hex.h>
-#include <botan/rng.h>
+#include <botan/libstate.h>
#include <algorithm>
namespace Botan {
@@ -18,7 +18,7 @@ namespace Botan {
void OctetString::change(u32bit length)
{
bits.create(length);
- Global_RNG::randomize(bits, length);
+ global_state().randomize(bits, length);
}
/*************************************************
diff --git a/src/timers.cpp b/src/timers.cpp
index 86839ad85..55ee12236 100644
--- a/src/timers.cpp
+++ b/src/timers.cpp
@@ -4,24 +4,19 @@
*************************************************/
#include <botan/timers.h>
-#include <botan/libstate.h>
+#include <botan/loadstor.h>
#include <ctime>
namespace Botan {
/*************************************************
-* Timer Access Functions *
+* Get the system clock *
*************************************************/
u64bit system_time()
{
return static_cast<u64bit>(std::time(0));
}
-u64bit system_clock()
- {
- return global_state().system_clock();
- }
-
/*************************************************
* Default Timer clock reading *
*************************************************/
@@ -31,11 +26,24 @@ u64bit Timer::clock() const
}
/*************************************************
+* Read the clock and return the output *
+*************************************************/
+u32bit Timer::slow_poll(byte out[], u32bit length)
+ {
+ const u64bit clock_value = this->clock();
+
+ for(u32bit j = 0; j != sizeof(clock_value); ++j)
+ out[j % length] ^= get_byte(j, clock_value);
+
+ return (length < 8) ? length : 8;
+ }
+
+/*************************************************
* Combine a two time values into a single one *
*************************************************/
u64bit Timer::combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz)
{
- const u64bit NANOSECONDS_UNITS = 1000000000;
+ static const u64bit NANOSECONDS_UNITS = 1000000000;
parts *= (NANOSECONDS_UNITS / parts_hz);
return ((seconds * NANOSECONDS_UNITS) + parts);
}
diff --git a/src/x509_ext.cpp b/src/x509_ext.cpp
index f692c5ac2..42a5bad01 100644
--- a/src/x509_ext.cpp
+++ b/src/x509_ext.cpp
@@ -4,8 +4,6 @@
*************************************************/
#include <botan/x509_ext.h>
-#include <botan/x509stat.h>
-#include <botan/libstate.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/lookup.h>
@@ -18,6 +16,28 @@
namespace Botan {
/*************************************************
+* List of X.509 Certificate Extensions *
+*************************************************/
+Certificate_Extension* Extensions::get_extension(const OID& oid)
+ {
+#define X509_EXTENSION(NAME, TYPE) \
+ if(OIDS::name_of(oid, NAME)) \
+ return new Cert_Extension::TYPE();
+
+ X509_EXTENSION("X509v3.KeyUsage", Key_Usage);
+ X509_EXTENSION("X509v3.BasicConstraints", Basic_Constraints);
+ X509_EXTENSION("X509v3.SubjectKeyIdentifier", Subject_Key_ID);
+ X509_EXTENSION("X509v3.AuthorityKeyIdentifier", Authority_Key_ID);
+ X509_EXTENSION("X509v3.ExtendedKeyUsage", Extended_Key_Usage);
+ X509_EXTENSION("X509v3.IssuerAlternativeName", Issuer_Alternative_Name);
+ X509_EXTENSION("X509v3.SubjectAlternativeName", Subject_Alternative_Name);
+ X509_EXTENSION("X509v3.CRLNumber", CRL_Number);
+ X509_EXTENSION("X509v3.CertificatePolicies", Certificate_Policies);
+
+ return 0;
+ }
+
+/*************************************************
* Extensions Copy Constructor *
*************************************************/
Extensions::Extensions(const Extensions& extensions) : ASN1_Object()
@@ -107,8 +127,7 @@ void Extensions::decode_from(BER_Decoder& from_source)
.verify_end()
.end_cons();
- Certificate_Extension* ext =
- global_state().x509_state().get_extension(oid);
+ Certificate_Extension* ext = get_extension(oid);
if(!ext)
{
diff --git a/src/x509stat.cpp b/src/x509stat.cpp
deleted file mode 100644
index fd45c00b3..000000000
--- a/src/x509stat.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-/*************************************************
-* Globally Saved X.509 State Source *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
-
-#include <botan/x509stat.h>
-#include <botan/x509_ext.h>
-#include <botan/oids.h>
-
-namespace Botan {
-
-/*************************************************
-* Add a new prototype *
-*************************************************/
-void X509_GlobalState::add(Extension_Prototype* proto)
- {
- if(proto)
- prototypes.push_back(proto);
- }
-
-/*************************************************
-* Get an extension object *
-*************************************************/
-Certificate_Extension* X509_GlobalState::get_extension(const OID& oid) const
- {
- Certificate_Extension* extension = 0;
- for(u32bit j = 0; j != prototypes.size() && !extension; ++j)
- extension = prototypes[j]->make(oid);
- return extension;
- }
-
-/*************************************************
-* Set up a new global state for X.509 *
-*************************************************/
-X509_GlobalState::X509_GlobalState()
- {
-
-#define CREATE_PROTOTYPE(NAME, TYPE) \
- do { \
- struct TYPE ## _Prototype : public Extension_Prototype \
- { \
- Certificate_Extension* make(const OID& oid) \
- { \
- if(Botan::OIDS::name_of(oid, NAME)) \
- return new Botan::Cert_Extension::TYPE(); \
- return 0; \
- } \
- }; \
- \
- add(new TYPE ## _Prototype); \
- } while(0);
-
- CREATE_PROTOTYPE("X509v3.KeyUsage", Key_Usage);
- CREATE_PROTOTYPE("X509v3.BasicConstraints", Basic_Constraints);
- CREATE_PROTOTYPE("X509v3.SubjectKeyIdentifier", Subject_Key_ID);
- CREATE_PROTOTYPE("X509v3.AuthorityKeyIdentifier", Authority_Key_ID);
- CREATE_PROTOTYPE("X509v3.ExtendedKeyUsage", Extended_Key_Usage);
- CREATE_PROTOTYPE("X509v3.IssuerAlternativeName", Issuer_Alternative_Name);
- CREATE_PROTOTYPE("X509v3.SubjectAlternativeName", Subject_Alternative_Name);
- CREATE_PROTOTYPE("X509v3.CRLNumber", CRL_Number);
- CREATE_PROTOTYPE("X509v3.CertificatePolicies", Certificate_Policies);
-
-#undef CREATE_PROTOTYPE
- }
-
-/*************************************************
-* Destroy this global state object *
-*************************************************/
-X509_GlobalState::~X509_GlobalState()
- {
- for(u32bit j = 0; j != prototypes.size(); ++j)
- delete prototypes[j];
- prototypes.clear();
- }
-
-}