aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bigint/asm_amd64/xxxinfo.txt (renamed from src/bigint/asm_amd64/modinfo.txt)0
-rw-r--r--src/bigint/asm_ia32/xxxinfo.txt (renamed from src/bigint/asm_ia32/modinfo.txt)0
-rw-r--r--src/bigint/big_code.cpp (renamed from src/big_code.cpp)0
-rw-r--r--src/bigint/big_io.cpp (renamed from src/big_io.cpp)0
-rw-r--r--src/bigint/big_ops2.cpp (renamed from src/big_ops2.cpp)0
-rw-r--r--src/bigint/big_ops3.cpp (renamed from src/big_ops3.cpp)0
-rw-r--r--src/bigint/big_rand.cpp (renamed from src/big_rand.cpp)0
-rw-r--r--src/bigint/bigint.cpp (renamed from src/bigint.cpp)0
-rw-r--r--src/bigint/bigint.h181
-rw-r--r--src/bigint/blinding.cpp (renamed from src/blinding.cpp)0
-rw-r--r--src/bigint/blinding.h32
-rw-r--r--src/bigint/def_powm.h62
-rw-r--r--src/bigint/divide.cpp (renamed from src/divide.cpp)0
-rw-r--r--src/bigint/dsa_gen.cpp (renamed from src/dsa_gen.cpp)0
-rw-r--r--src/bigint/jacobi.cpp (renamed from src/jacobi.cpp)0
-rw-r--r--src/bigint/make_prm.cpp (renamed from src/make_prm.cpp)0
-rw-r--r--src/bigint/modinfo.txt43
-rw-r--r--src/bigint/mp_amd64/xxxinfo.txt (renamed from src/bigint/mp_amd64/modinfo.txt)0
-rw-r--r--src/bigint/mp_asm.cpp (renamed from src/mp_asm.cpp)0
-rw-r--r--src/bigint/mp_asm.h52
-rw-r--r--src/bigint/mp_asm64/xxxinfo.txt (renamed from src/bigint/mp_asm64/modinfo.txt)0
-rw-r--r--src/bigint/mp_asmi.h189
-rw-r--r--src/bigint/mp_comba.cpp (renamed from src/mp_comba.cpp)0
-rw-r--r--src/bigint/mp_core.h96
-rw-r--r--src/bigint/mp_ia32/xxxinfo.txt (renamed from src/bigint/mp_ia32/modinfo.txt)0
-rw-r--r--src/bigint/mp_ia32_msvc/xxxinfo.txt (renamed from src/bigint/mp_ia32_msvc/modinfo.txt)0
-rw-r--r--src/bigint/mp_karat.cpp (renamed from src/mp_karat.cpp)0
-rw-r--r--src/bigint/mp_misc.cpp (renamed from src/mp_misc.cpp)0
-rw-r--r--src/bigint/mp_monty.cpp (renamed from src/mp_monty.cpp)0
-rw-r--r--src/bigint/mp_mulop.cpp (renamed from src/mp_mulop.cpp)0
-rw-r--r--src/bigint/mp_numth.cpp (renamed from src/mp_numth.cpp)0
-rw-r--r--src/bigint/mp_shift.cpp (renamed from src/mp_shift.cpp)0
-rw-r--r--src/bigint/mp_types.h31
-rw-r--r--src/bigint/numthry.cpp (renamed from src/numthry.cpp)0
-rw-r--r--src/bigint/numthry.h103
-rw-r--r--src/bigint/pow_mod.cpp (renamed from src/pow_mod.cpp)0
-rw-r--r--src/bigint/pow_mod.h91
-rw-r--r--src/bigint/powm_fw.cpp (renamed from src/powm_fw.cpp)0
-rw-r--r--src/bigint/powm_mnt.cpp (renamed from src/powm_mnt.cpp)0
-rw-r--r--src/bigint/reducer.cpp (renamed from src/reducer.cpp)0
-rw-r--r--src/bigint/reducer.h34
-rw-r--r--src/bigint/ressol.cpp (renamed from src/ressol.cpp)0
-rw-r--r--src/charset.cpp74
-rw-r--r--src/codec/base64/b64_char.cpp45
-rw-r--r--src/codec/base64/modinfo.txt1
-rw-r--r--src/codec/hex/hex_char.cpp46
-rw-r--r--src/codec/hex/modinfo.txt1
47 files changed, 1008 insertions, 73 deletions
diff --git a/src/bigint/asm_amd64/modinfo.txt b/src/bigint/asm_amd64/xxxinfo.txt
index 2a8f9fe5b..2a8f9fe5b 100644
--- a/src/bigint/asm_amd64/modinfo.txt
+++ b/src/bigint/asm_amd64/xxxinfo.txt
diff --git a/src/bigint/asm_ia32/modinfo.txt b/src/bigint/asm_ia32/xxxinfo.txt
index 12c8cd96d..12c8cd96d 100644
--- a/src/bigint/asm_ia32/modinfo.txt
+++ b/src/bigint/asm_ia32/xxxinfo.txt
diff --git a/src/big_code.cpp b/src/bigint/big_code.cpp
index 824cbb63e..824cbb63e 100644
--- a/src/big_code.cpp
+++ b/src/bigint/big_code.cpp
diff --git a/src/big_io.cpp b/src/bigint/big_io.cpp
index 3c201e8b2..3c201e8b2 100644
--- a/src/big_io.cpp
+++ b/src/bigint/big_io.cpp
diff --git a/src/big_ops2.cpp b/src/bigint/big_ops2.cpp
index ef083f394..ef083f394 100644
--- a/src/big_ops2.cpp
+++ b/src/bigint/big_ops2.cpp
diff --git a/src/big_ops3.cpp b/src/bigint/big_ops3.cpp
index 7f412f6db..7f412f6db 100644
--- a/src/big_ops3.cpp
+++ b/src/bigint/big_ops3.cpp
diff --git a/src/big_rand.cpp b/src/bigint/big_rand.cpp
index b8cad3a4c..b8cad3a4c 100644
--- a/src/big_rand.cpp
+++ b/src/bigint/big_rand.cpp
diff --git a/src/bigint.cpp b/src/bigint/bigint.cpp
index e3c7931e6..e3c7931e6 100644
--- a/src/bigint.cpp
+++ b/src/bigint/bigint.cpp
diff --git a/src/bigint/bigint.h b/src/bigint/bigint.h
new file mode 100644
index 000000000..b1286551e
--- /dev/null
+++ b/src/bigint/bigint.h
@@ -0,0 +1,181 @@
+/*************************************************
+* BigInt Header File *
+* (C) 1999-2008 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_BIGINT_H__
+#define BOTAN_BIGINT_H__
+
+#include <botan/rng.h>
+#include <botan/secmem.h>
+#include <botan/mp_types.h>
+#include <iosfwd>
+
+namespace Botan {
+
+/*************************************************
+* BigInt *
+*************************************************/
+class BOTAN_DLL BigInt
+ {
+ public:
+ enum Base { Octal = 8, Decimal = 10, Hexadecimal = 16, Binary = 256 };
+ enum Sign { Negative = 0, Positive = 1 };
+ enum NumberType { Power2 };
+
+ struct DivideByZero : public Exception
+ { DivideByZero() : Exception("BigInt divide by zero") {} };
+
+ BigInt& operator+=(const BigInt&);
+ BigInt& operator-=(const BigInt&);
+
+ BigInt& operator*=(const BigInt&);
+ BigInt& operator/=(const BigInt&);
+ BigInt& operator%=(const BigInt&);
+ word operator%=(word);
+ BigInt& operator<<=(u32bit);
+ BigInt& operator>>=(u32bit);
+
+ BigInt& operator++() { return (*this += 1); }
+ BigInt& operator--() { return (*this -= 1); }
+ BigInt operator++(int) { BigInt x = (*this); ++(*this); return x; }
+ BigInt operator--(int) { BigInt x = (*this); --(*this); return x; }
+
+ BigInt operator-() const;
+ bool operator !() const { return (!is_nonzero()); }
+
+ s32bit cmp(const BigInt&, bool = true) const;
+ bool is_even() const { return (get_bit(0) == 0); }
+ bool is_odd() const { return (get_bit(0) == 1); }
+
+ bool is_zero() const
+ {
+ const u32bit sw = sig_words();
+
+ for(u32bit i = 0; i != sw; ++i)
+ if(reg[i])
+ return false;
+ return true;
+ }
+
+ bool is_nonzero() const { return (!is_zero()); }
+
+ void set_bit(u32bit);
+ void clear_bit(u32bit);
+ void mask_bits(u32bit);
+
+ bool get_bit(u32bit) const;
+ u32bit get_substring(u32bit, u32bit) const;
+ byte byte_at(u32bit) const;
+
+ // same as operator[], remove this
+ word word_at(u32bit n) const
+ { return ((n < size()) ? get_reg()[n] : 0); }
+
+ u32bit to_u32bit() const;
+
+ bool is_negative() const { return (sign() == Negative); }
+ bool is_positive() const { return (sign() == Positive); }
+ Sign sign() const { return (signedness); }
+ Sign reverse_sign() const;
+ void flip_sign();
+ void set_sign(Sign);
+ BigInt abs() const;
+
+ u32bit size() const { return get_reg().size(); }
+
+ u32bit sig_words() const
+ {
+ const word* x = reg.begin();
+ u32bit sig = reg.size();
+
+ while(sig && (x[sig-1] == 0))
+ sig--;
+ return sig;
+ }
+
+ u32bit bytes() const;
+ u32bit bits() const;
+
+ const word* data() const { return reg.begin(); }
+ SecureVector<word>& get_reg() { return reg; }
+ const SecureVector<word>& get_reg() const { return reg; }
+
+ void grow_reg(u32bit);
+ void grow_to(u32bit);
+
+ word& operator[](u32bit i) { return reg[i]; }
+ word operator[](u32bit i) const { return reg[i]; }
+ void clear() { get_reg().clear(); }
+
+ void randomize(RandomNumberGenerator& rng, u32bit n);
+
+ void binary_encode(byte[]) const;
+ void binary_decode(const byte[], u32bit);
+ void binary_decode(const MemoryRegion<byte>&);
+ u32bit encoded_size(Base = Binary) const;
+
+ static SecureVector<byte> encode(const BigInt&, Base = Binary);
+ static void encode(byte[], const BigInt&, Base = Binary);
+ static BigInt decode(const byte[], u32bit, Base = Binary);
+ static BigInt decode(const MemoryRegion<byte>&, Base = Binary);
+ static SecureVector<byte> encode_1363(const BigInt&, u32bit);
+
+ void swap(BigInt&);
+
+ BigInt() { signedness = Positive; }
+ BigInt(u64bit);
+ BigInt(const BigInt&);
+ BigInt(const std::string&);
+ BigInt(const byte[], u32bit, Base = Binary);
+ BigInt(RandomNumberGenerator& rng, u32bit bits);
+ BigInt(Sign, u32bit);
+ BigInt(NumberType, u32bit);
+ private:
+ SecureVector<word> reg;
+ Sign signedness;
+ };
+
+/*************************************************
+* Arithmetic Operators *
+*************************************************/
+BigInt BOTAN_DLL operator+(const BigInt&, const BigInt&);
+BigInt BOTAN_DLL operator-(const BigInt&, const BigInt&);
+BigInt BOTAN_DLL operator*(const BigInt&, const BigInt&);
+BigInt BOTAN_DLL operator/(const BigInt&, const BigInt&);
+BigInt BOTAN_DLL operator%(const BigInt&, const BigInt&);
+word BOTAN_DLL operator%(const BigInt&, word);
+BigInt BOTAN_DLL operator<<(const BigInt&, u32bit);
+BigInt BOTAN_DLL operator>>(const BigInt&, u32bit);
+
+/*************************************************
+* Comparison Operators *
+*************************************************/
+inline bool operator==(const BigInt& a, const BigInt& b)
+ { return (a.cmp(b) == 0); }
+inline bool operator!=(const BigInt& a, const BigInt& b)
+ { return (a.cmp(b) != 0); }
+inline bool operator<=(const BigInt& a, const BigInt& b)
+ { return (a.cmp(b) <= 0); }
+inline bool operator>=(const BigInt& a, const BigInt& b)
+ { return (a.cmp(b) >= 0); }
+inline bool operator<(const BigInt& a, const BigInt& b)
+ { return (a.cmp(b) < 0); }
+inline bool operator>(const BigInt& a, const BigInt& b)
+ { return (a.cmp(b) > 0); }
+
+/*************************************************
+* I/O Operators *
+*************************************************/
+BOTAN_DLL std::ostream& operator<<(std::ostream&, const BigInt&);
+BOTAN_DLL std::istream& operator>>(std::istream&, BigInt&);
+
+}
+
+namespace std {
+
+inline void swap(Botan::BigInt& a, Botan::BigInt& b) { a.swap(b); }
+
+}
+
+#endif
diff --git a/src/blinding.cpp b/src/bigint/blinding.cpp
index 740904d10..740904d10 100644
--- a/src/blinding.cpp
+++ b/src/bigint/blinding.cpp
diff --git a/src/bigint/blinding.h b/src/bigint/blinding.h
new file mode 100644
index 000000000..958686fb1
--- /dev/null
+++ b/src/bigint/blinding.h
@@ -0,0 +1,32 @@
+/*************************************************
+* Blinder Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_BLINDER_H__
+#define BOTAN_BLINDER_H__
+
+#include <botan/bigint.h>
+#include <botan/reducer.h>
+
+namespace Botan {
+
+/*************************************************
+* Blinding Function Object *
+*************************************************/
+class BOTAN_DLL Blinder
+ {
+ public:
+ BigInt blind(const BigInt&) const;
+ BigInt unblind(const BigInt&) const;
+
+ Blinder() {}
+ Blinder(const BigInt&, const BigInt&, const BigInt&);
+ private:
+ Modular_Reducer reducer;
+ mutable BigInt e, d;
+ };
+
+}
+
+#endif
diff --git a/src/bigint/def_powm.h b/src/bigint/def_powm.h
new file mode 100644
index 000000000..c91ff002c
--- /dev/null
+++ b/src/bigint/def_powm.h
@@ -0,0 +1,62 @@
+/*************************************************
+* Modular Exponentiation Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_DEFAULT_MODEXP_H__
+#define BOTAN_DEFAULT_MODEXP_H__
+
+#include <botan/pow_mod.h>
+#include <botan/reducer.h>
+#include <vector>
+
+namespace Botan {
+
+/*************************************************
+* Fixed Window Exponentiator *
+*************************************************/
+class BOTAN_DLL Fixed_Window_Exponentiator : public Modular_Exponentiator
+ {
+ public:
+ void set_exponent(const BigInt&);
+ void set_base(const BigInt&);
+ BigInt execute() const;
+
+ Modular_Exponentiator* copy() const
+ { return new Fixed_Window_Exponentiator(*this); }
+
+ Fixed_Window_Exponentiator(const BigInt&, Power_Mod::Usage_Hints);
+ private:
+ Modular_Reducer reducer;
+ BigInt exp;
+ u32bit window_bits;
+ std::vector<BigInt> g;
+ Power_Mod::Usage_Hints hints;
+ };
+
+/*************************************************
+* Montgomery Exponentiator *
+*************************************************/
+class BOTAN_DLL Montgomery_Exponentiator : public Modular_Exponentiator
+ {
+ public:
+ void set_exponent(const BigInt&);
+ void set_base(const BigInt&);
+ BigInt execute() const;
+
+ Modular_Exponentiator* copy() const
+ { return new Montgomery_Exponentiator(*this); }
+
+ Montgomery_Exponentiator(const BigInt&, Power_Mod::Usage_Hints);
+ private:
+ BigInt exp, modulus;
+ BigInt R2, R_mod;
+ std::vector<BigInt> g;
+ word mod_prime;
+ u32bit mod_words, exp_bits, window_bits;
+ Power_Mod::Usage_Hints hints;
+ };
+
+}
+
+#endif
diff --git a/src/divide.cpp b/src/bigint/divide.cpp
index 003a06d83..003a06d83 100644
--- a/src/divide.cpp
+++ b/src/bigint/divide.cpp
diff --git a/src/dsa_gen.cpp b/src/bigint/dsa_gen.cpp
index baaba66ee..baaba66ee 100644
--- a/src/dsa_gen.cpp
+++ b/src/bigint/dsa_gen.cpp
diff --git a/src/jacobi.cpp b/src/bigint/jacobi.cpp
index 57c78508a..57c78508a 100644
--- a/src/jacobi.cpp
+++ b/src/bigint/jacobi.cpp
diff --git a/src/make_prm.cpp b/src/bigint/make_prm.cpp
index dc26a0400..dc26a0400 100644
--- a/src/make_prm.cpp
+++ b/src/bigint/make_prm.cpp
diff --git a/src/bigint/modinfo.txt b/src/bigint/modinfo.txt
new file mode 100644
index 000000000..571c3550f
--- /dev/null
+++ b/src/bigint/modinfo.txt
@@ -0,0 +1,43 @@
+realname "BigInt"
+
+load_on auto
+
+define BIGINT
+
+<add>
+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
+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
+numthry.cpp
+numthry.h
+pow_mod.cpp
+pow_mod.h
+powm_fw.cpp
+powm_mnt.cpp
+reducer.cpp
+reducer.h
+ressol.cpp
+mp_types.h
+mp_asm.h
+mp_asmi.h
+</add>
diff --git a/src/bigint/mp_amd64/modinfo.txt b/src/bigint/mp_amd64/xxxinfo.txt
index a042a3976..a042a3976 100644
--- a/src/bigint/mp_amd64/modinfo.txt
+++ b/src/bigint/mp_amd64/xxxinfo.txt
diff --git a/src/mp_asm.cpp b/src/bigint/mp_asm.cpp
index e5d1fe0d6..e5d1fe0d6 100644
--- a/src/mp_asm.cpp
+++ b/src/bigint/mp_asm.cpp
diff --git a/src/bigint/mp_asm.h b/src/bigint/mp_asm.h
new file mode 100644
index 000000000..e62a57110
--- /dev/null
+++ b/src/bigint/mp_asm.h
@@ -0,0 +1,52 @@
+/*************************************************
+* Lowest Level MPI Algorithms Header File *
+* (C) 1999-2008 Jack Lloyd *
+* 2006 Luca Piccarreta *
+*************************************************/
+
+#ifndef BOTAN_MP_ASM_H__
+#define BOTAN_MP_ASM_H__
+
+#include <botan/mp_types.h>
+
+#if (BOTAN_MP_WORD_BITS == 8)
+ typedef Botan::u16bit dword;
+#elif (BOTAN_MP_WORD_BITS == 16)
+ typedef Botan::u32bit dword;
+#elif (BOTAN_MP_WORD_BITS == 32)
+ typedef Botan::u64bit dword;
+#elif (BOTAN_MP_WORD_BITS == 64)
+ #error BOTAN_MP_WORD_BITS can be 64 only with assembly support
+#else
+ #error BOTAN_MP_WORD_BITS must be 8, 16, 32, or 64
+#endif
+
+namespace Botan {
+
+extern "C" {
+
+/*************************************************
+* Word Multiply/Add *
+*************************************************/
+inline word word_madd2(word a, word b, word* c)
+ {
+ dword z = (dword)a * b + *c;
+ *c = (word)(z >> BOTAN_MP_WORD_BITS);
+ return (word)z;
+ }
+
+/*************************************************
+* Word Multiply/Add *
+*************************************************/
+inline word word_madd3(word a, word b, word c, word* d)
+ {
+ dword z = (dword)a * b + c + *d;
+ *d = (word)(z >> BOTAN_MP_WORD_BITS);
+ return (word)z;
+ }
+
+}
+
+}
+
+#endif
diff --git a/src/bigint/mp_asm64/modinfo.txt b/src/bigint/mp_asm64/xxxinfo.txt
index a9e5d53da..a9e5d53da 100644
--- a/src/bigint/mp_asm64/modinfo.txt
+++ b/src/bigint/mp_asm64/xxxinfo.txt
diff --git a/src/bigint/mp_asmi.h b/src/bigint/mp_asmi.h
new file mode 100644
index 000000000..d15295154
--- /dev/null
+++ b/src/bigint/mp_asmi.h
@@ -0,0 +1,189 @@
+/*************************************************
+* Lowest Level MPI Algorithms Header File *
+* (C) 1999-2008 Jack Lloyd *
+* 2006 Luca Piccarreta *
+*************************************************/
+
+#ifndef BOTAN_MP_ASM_INTERNAL_H__
+#define BOTAN_MP_ASM_INTERNAL_H__
+
+#include <botan/mp_asm.h>
+
+namespace Botan {
+
+extern "C" {
+
+/*************************************************
+* Word Addition *
+*************************************************/
+inline word word_add(word x, word y, word* carry)
+ {
+ word z = x + y;
+ word c1 = (z < x);
+ z += *carry;
+ *carry = c1 | (z < *carry);
+ return z;
+ }
+
+/*************************************************
+* Eight Word Block Addition, Two Argument *
+*************************************************/
+inline word word8_add2(word x[8], const word y[8], word carry)
+ {
+ x[0] = word_add(x[0], y[0], &carry);
+ x[1] = word_add(x[1], y[1], &carry);
+ x[2] = word_add(x[2], y[2], &carry);
+ x[3] = word_add(x[3], y[3], &carry);
+ x[4] = word_add(x[4], y[4], &carry);
+ x[5] = word_add(x[5], y[5], &carry);
+ x[6] = word_add(x[6], y[6], &carry);
+ x[7] = word_add(x[7], y[7], &carry);
+ return carry;
+ }
+
+/*************************************************
+* Eight Word Block Addition, Three Argument *
+*************************************************/
+inline word word8_add3(word z[8], const word x[8],
+ const word y[8], word carry)
+ {
+ z[0] = word_add(x[0], y[0], &carry);
+ z[1] = word_add(x[1], y[1], &carry);
+ z[2] = word_add(x[2], y[2], &carry);
+ z[3] = word_add(x[3], y[3], &carry);
+ z[4] = word_add(x[4], y[4], &carry);
+ z[5] = word_add(x[5], y[5], &carry);
+ z[6] = word_add(x[6], y[6], &carry);
+ z[7] = word_add(x[7], y[7], &carry);
+ return carry;
+ }
+
+/*************************************************
+* Word Subtraction *
+*************************************************/
+inline word word_sub(word x, word y, word* carry)
+ {
+ word t0 = x - y;
+ word c1 = (t0 > x);
+ word z = t0 - *carry;
+ *carry = c1 | (z > t0);
+ return z;
+ }
+
+/*************************************************
+* Eight Word Block Subtraction, Two Argument *
+*************************************************/
+inline word word8_sub2(word x[4], const word y[4], word carry)
+ {
+ x[0] = word_sub(x[0], y[0], &carry);
+ x[1] = word_sub(x[1], y[1], &carry);
+ x[2] = word_sub(x[2], y[2], &carry);
+ x[3] = word_sub(x[3], y[3], &carry);
+ x[4] = word_sub(x[4], y[4], &carry);
+ x[5] = word_sub(x[5], y[5], &carry);
+ x[6] = word_sub(x[6], y[6], &carry);
+ x[7] = word_sub(x[7], y[7], &carry);
+ return carry;
+ }
+
+/*************************************************
+* Eight Word Block Subtraction, Three Argument *
+*************************************************/
+inline word word8_sub3(word z[8], const word x[8],
+ const word y[8], word carry)
+ {
+ z[0] = word_sub(x[0], y[0], &carry);
+ z[1] = word_sub(x[1], y[1], &carry);
+ z[2] = word_sub(x[2], y[2], &carry);
+ z[3] = word_sub(x[3], y[3], &carry);
+ z[4] = word_sub(x[4], y[4], &carry);
+ z[5] = word_sub(x[5], y[5], &carry);
+ z[6] = word_sub(x[6], y[6], &carry);
+ z[7] = word_sub(x[7], y[7], &carry);
+ return carry;
+ }
+
+/*************************************************
+* Eight Word Block Linear Multiplication *
+*************************************************/
+inline word word8_linmul2(word x[4], word y, word carry)
+ {
+ x[0] = word_madd2(x[0], y, &carry);
+ x[1] = word_madd2(x[1], y, &carry);
+ x[2] = word_madd2(x[2], y, &carry);
+ x[3] = word_madd2(x[3], y, &carry);
+ x[4] = word_madd2(x[4], y, &carry);
+ x[5] = word_madd2(x[5], y, &carry);
+ x[6] = word_madd2(x[6], y, &carry);
+ x[7] = word_madd2(x[7], y, &carry);
+ return carry;
+ }
+
+/*************************************************
+* Eight Word Block Linear Multiplication *
+*************************************************/
+inline word word8_linmul3(word z[8], const word x[8], word y, word carry)
+ {
+ z[0] = word_madd2(x[0], y, &carry);
+ z[1] = word_madd2(x[1], y, &carry);
+ z[2] = word_madd2(x[2], y, &carry);
+ z[3] = word_madd2(x[3], y, &carry);
+ z[4] = word_madd2(x[4], y, &carry);
+ z[5] = word_madd2(x[5], y, &carry);
+ z[6] = word_madd2(x[6], y, &carry);
+ z[7] = word_madd2(x[7], y, &carry);
+ return carry;
+ }
+
+/*************************************************
+* Eight Word Block Multiply/Add *
+*************************************************/
+inline word word8_madd3(word z[8], const word x[8], word y, word carry)
+ {
+ z[0] = word_madd3(x[0], y, z[0], &carry);
+ z[1] = word_madd3(x[1], y, z[1], &carry);
+ z[2] = word_madd3(x[2], y, z[2], &carry);
+ z[3] = word_madd3(x[3], y, z[3], &carry);
+ z[4] = word_madd3(x[4], y, z[4], &carry);
+ z[5] = word_madd3(x[5], y, z[5], &carry);
+ z[6] = word_madd3(x[6], y, z[6], &carry);
+ z[7] = word_madd3(x[7], y, z[7], &carry);
+ return carry;
+ }
+
+/*************************************************
+* Multiply-Add Accumulator *
+*************************************************/
+inline void word3_muladd(word* w2, word* w1, word* w0, word a, word b)
+ {
+ word carry = *w0;
+ *w0 = word_madd2(a, b, &carry);
+ *w1 += carry;
+ *w2 += (*w1 < carry) ? 1 : 0;
+ }
+
+/*************************************************
+* Multiply-Add Accumulator *
+*************************************************/
+inline void word3_muladd_2(word* w2, word* w1, word* w0, word a, word b)
+ {
+ word carry = 0;
+ a = word_madd2(a, b, &carry);
+ b = carry;
+
+ word top = (b >> (BOTAN_MP_WORD_BITS-1));
+ b <<= 1;
+ b |= (a >> (BOTAN_MP_WORD_BITS-1));
+ a <<= 1;
+
+ carry = 0;
+ *w0 = word_add(*w0, a, &carry);
+ *w1 = word_add(*w1, b, &carry);
+ *w2 = word_add(*w2, top, &carry);
+ }
+
+}
+
+}
+
+#endif
diff --git a/src/mp_comba.cpp b/src/bigint/mp_comba.cpp
index c7a9c964c..c7a9c964c 100644
--- a/src/mp_comba.cpp
+++ b/src/bigint/mp_comba.cpp
diff --git a/src/bigint/mp_core.h b/src/bigint/mp_core.h
new file mode 100644
index 000000000..92949cd83
--- /dev/null
+++ b/src/bigint/mp_core.h
@@ -0,0 +1,96 @@
+/*************************************************
+* MPI Algorithms Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_MP_CORE_H__
+#define BOTAN_MP_CORE_H__
+
+#include <botan/mp_types.h>
+
+namespace Botan {
+
+/*************************************************
+* The size of the word type, in bits *
+*************************************************/
+const u32bit MP_WORD_BITS = BOTAN_MP_WORD_BITS;
+
+extern "C" {
+
+/*************************************************
+* Addition/Subtraction Operations *
+*************************************************/
+void bigint_add2(word[], u32bit, const word[], u32bit);
+void bigint_add3(word[], const word[], u32bit, const word[], u32bit);
+
+word bigint_add2_nc(word[], u32bit, const word[], u32bit);
+word bigint_add3_nc(word[], const word[], u32bit, const word[], u32bit);
+
+void bigint_sub2(word[], u32bit, const word[], u32bit);
+void bigint_sub3(word[], const word[], u32bit, const word[], u32bit);
+
+/*************************************************
+* Shift Operations *
+*************************************************/
+void bigint_shl1(word[], u32bit, u32bit, u32bit);
+void bigint_shl2(word[], const word[], u32bit, u32bit, u32bit);
+void bigint_shr1(word[], u32bit, u32bit, u32bit);
+void bigint_shr2(word[], const word[], u32bit, u32bit, u32bit);
+
+/*************************************************
+* Simple O(N^2) Multiplication and Squaring *
+*************************************************/
+void bigint_simple_mul(word z[], const word x[], u32bit x_size,
+ const word y[], u32bit y_size);
+void bigint_simple_sqr(word z[], const word x[], u32bit x_size);
+
+/*************************************************
+* Linear Multiply *
+*************************************************/
+void bigint_linmul2(word[], u32bit, word);
+void bigint_linmul3(word[], const word[], u32bit, word);
+void bigint_linmul_add(word[], u32bit, const word[], u32bit, word);
+
+/*************************************************
+* Montgomery Reduction *
+*************************************************/
+void bigint_monty_redc(word[], u32bit, const word[], u32bit, word);
+
+/*************************************************
+* Misc Utility Operations *
+*************************************************/
+u32bit bigint_divcore(word, word, word, word, word, word);
+s32bit bigint_cmp(const word[], u32bit, const word[], u32bit);
+word bigint_divop(word, word, word);
+word bigint_modop(word, word, word);
+void bigint_wordmul(word, word, word*, word*);
+
+/*************************************************
+* Comba Multiplication / Squaring *
+*************************************************/
+void bigint_comba_mul4(word[8], const word[4], const word[4]);
+void bigint_comba_mul6(word[12], const word[6], const word[6]);
+void bigint_comba_mul8(word[16], const word[8], const word[8]);
+void bigint_comba_mul16(word[32], const word[16], const word[16]);
+
+void bigint_comba_sqr4(word[8], const word[4]);
+void bigint_comba_sqr6(word[12], const word[6]);
+void bigint_comba_sqr8(word[16], const word[8]);
+void bigint_comba_sqr8(word[32], const word[16]);
+void bigint_comba_sqr16(word[64], const word[32]);
+
+}
+
+/*************************************************
+* High Level Multiplication/Squaring Interfaces *
+*************************************************/
+void bigint_mul(word[], u32bit, word[],
+ const word[], u32bit, u32bit,
+ const word[], u32bit, u32bit);
+
+void bigint_sqr(word[], u32bit, word[],
+ const word[], u32bit, u32bit);
+
+}
+
+#endif
diff --git a/src/bigint/mp_ia32/modinfo.txt b/src/bigint/mp_ia32/xxxinfo.txt
index cf4959250..cf4959250 100644
--- a/src/bigint/mp_ia32/modinfo.txt
+++ b/src/bigint/mp_ia32/xxxinfo.txt
diff --git a/src/bigint/mp_ia32_msvc/modinfo.txt b/src/bigint/mp_ia32_msvc/xxxinfo.txt
index 36d9d0290..36d9d0290 100644
--- a/src/bigint/mp_ia32_msvc/modinfo.txt
+++ b/src/bigint/mp_ia32_msvc/xxxinfo.txt
diff --git a/src/mp_karat.cpp b/src/bigint/mp_karat.cpp
index 15b0551fd..15b0551fd 100644
--- a/src/mp_karat.cpp
+++ b/src/bigint/mp_karat.cpp
diff --git a/src/mp_misc.cpp b/src/bigint/mp_misc.cpp
index db9c8cda0..db9c8cda0 100644
--- a/src/mp_misc.cpp
+++ b/src/bigint/mp_misc.cpp
diff --git a/src/mp_monty.cpp b/src/bigint/mp_monty.cpp
index c162bfd4f..c162bfd4f 100644
--- a/src/mp_monty.cpp
+++ b/src/bigint/mp_monty.cpp
diff --git a/src/mp_mulop.cpp b/src/bigint/mp_mulop.cpp
index 3ab28d306..3ab28d306 100644
--- a/src/mp_mulop.cpp
+++ b/src/bigint/mp_mulop.cpp
diff --git a/src/mp_numth.cpp b/src/bigint/mp_numth.cpp
index b024d2e2d..b024d2e2d 100644
--- a/src/mp_numth.cpp
+++ b/src/bigint/mp_numth.cpp
diff --git a/src/mp_shift.cpp b/src/bigint/mp_shift.cpp
index 033774e46..033774e46 100644
--- a/src/mp_shift.cpp
+++ b/src/bigint/mp_shift.cpp
diff --git a/src/bigint/mp_types.h b/src/bigint/mp_types.h
new file mode 100644
index 000000000..81b6d7395
--- /dev/null
+++ b/src/bigint/mp_types.h
@@ -0,0 +1,31 @@
+/*************************************************
+* Low Level MPI Types Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_MPI_TYPES_H__
+#define BOTAN_MPI_TYPES_H__
+
+#include <botan/types.h>
+
+namespace Botan {
+
+#if (BOTAN_MP_WORD_BITS == 8)
+ typedef byte word;
+#elif (BOTAN_MP_WORD_BITS == 16)
+ typedef u16bit word;
+#elif (BOTAN_MP_WORD_BITS == 32)
+ typedef u32bit word;
+#elif (BOTAN_MP_WORD_BITS == 64)
+ typedef u64bit word;
+#else
+ #error BOTAN_MP_WORD_BITS must be 8, 16, 32, or 64
+#endif
+
+const word MP_WORD_MASK = ~static_cast<word>(0);
+const word MP_WORD_TOP_BIT = static_cast<word>(1) << (8*sizeof(word) - 1);
+const word MP_WORD_MAX = MP_WORD_MASK;
+
+}
+
+#endif
diff --git a/src/numthry.cpp b/src/bigint/numthry.cpp
index ffd523e82..ffd523e82 100644
--- a/src/numthry.cpp
+++ b/src/bigint/numthry.cpp
diff --git a/src/bigint/numthry.h b/src/bigint/numthry.h
new file mode 100644
index 000000000..371621c2d
--- /dev/null
+++ b/src/bigint/numthry.h
@@ -0,0 +1,103 @@
+/*************************************************
+* Number Theory Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_NUMBTHRY_H__
+#define BOTAN_NUMBTHRY_H__
+
+#include <botan/base.h>
+#include <botan/bigint.h>
+#include <botan/reducer.h>
+#include <botan/pow_mod.h>
+
+namespace Botan {
+
+/*************************************************
+* 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 *
+*************************************************/
+inline BigInt abs(const BigInt& n) { return n.abs(); }
+
+void BOTAN_DLL divide(const BigInt&, const BigInt&, BigInt&, BigInt&);
+
+BigInt BOTAN_DLL gcd(const BigInt&, const BigInt&);
+BigInt BOTAN_DLL lcm(const BigInt&, const BigInt&);
+
+BigInt BOTAN_DLL square(const BigInt&);
+BigInt BOTAN_DLL inverse_mod(const BigInt&, const BigInt&);
+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 *
+*************************************************/
+BigInt ressol(const BigInt& x, const BigInt& p);
+
+/*************************************************
+* Utility Functions *
+*************************************************/
+u32bit BOTAN_DLL low_zero_bits(const BigInt&);
+
+/*************************************************
+* 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&);
+
+s32bit BOTAN_DLL simple_primality_tests(const BigInt&);
+
+bool BOTAN_DLL passes_mr_tests(RandomNumberGenerator&,
+ const BigInt&, u32bit = 1);
+
+bool BOTAN_DLL run_primality_tests(RandomNumberGenerator&,
+ const BigInt&, u32bit = 1);
+
+/*************************************************
+* 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);
+
+BigInt BOTAN_DLL random_safe_prime(RandomNumberGenerator&,
+ u32bit);
+
+/*************************************************
+* 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 *
+*************************************************/
+class BOTAN_DLL MillerRabin_Test
+ {
+ public:
+ bool passes_test(const BigInt&);
+ MillerRabin_Test(const BigInt&);
+ private:
+ BigInt n, r, n_minus_1;
+ u32bit s;
+ Fixed_Exponent_Power_Mod pow_mod;
+ Modular_Reducer reducer;
+ };
+
+}
+
+#endif
diff --git a/src/pow_mod.cpp b/src/bigint/pow_mod.cpp
index 17ca7b796..17ca7b796 100644
--- a/src/pow_mod.cpp
+++ b/src/bigint/pow_mod.cpp
diff --git a/src/bigint/pow_mod.h b/src/bigint/pow_mod.h
new file mode 100644
index 000000000..37e0871da
--- /dev/null
+++ b/src/bigint/pow_mod.h
@@ -0,0 +1,91 @@
+/*************************************************
+* Modular Exponentiator Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_POWER_MOD_H__
+#define BOTAN_POWER_MOD_H__
+
+#include <botan/bigint.h>
+
+namespace Botan {
+
+/*************************************************
+* Modular Exponentiator Interface *
+*************************************************/
+class BOTAN_DLL Modular_Exponentiator
+ {
+ public:
+ virtual void set_base(const BigInt&) = 0;
+ virtual void set_exponent(const BigInt&) = 0;
+ virtual BigInt execute() const = 0;
+ virtual Modular_Exponentiator* copy() const = 0;
+ virtual ~Modular_Exponentiator() {}
+ };
+
+/*************************************************
+* Modular Exponentiator Proxy *
+*************************************************/
+class BOTAN_DLL Power_Mod
+ {
+ public:
+ enum Usage_Hints {
+ NO_HINTS = 0x0000,
+
+ BASE_IS_FIXED = 0x0001,
+ BASE_IS_SMALL = 0x0002,
+ BASE_IS_LARGE = 0x0004,
+ BASE_IS_2 = 0x0008,
+
+ EXP_IS_FIXED = 0x0100,
+ EXP_IS_SMALL = 0x0200,
+ EXP_IS_LARGE = 0x0400
+ };
+
+ void set_modulus(const BigInt&, Usage_Hints = NO_HINTS) const;
+ void set_base(const BigInt&) const;
+ void set_exponent(const BigInt&) const;
+
+ BigInt execute() const;
+
+ Power_Mod& operator=(const Power_Mod&);
+
+ Power_Mod(const BigInt& = 0, Usage_Hints = NO_HINTS);
+ Power_Mod(const Power_Mod&);
+ ~Power_Mod();
+ private:
+ mutable Modular_Exponentiator* core;
+ Usage_Hints hints;
+ };
+
+/*************************************************
+* Fixed Exponent Modular Exponentiator Proxy *
+*************************************************/
+class BOTAN_DLL Fixed_Exponent_Power_Mod : public Power_Mod
+ {
+ public:
+ BigInt operator()(const BigInt& b) const
+ { set_base(b); return execute(); }
+
+ Fixed_Exponent_Power_Mod() {}
+ Fixed_Exponent_Power_Mod(const BigInt&, const BigInt&,
+ Usage_Hints = NO_HINTS);
+ };
+
+/*************************************************
+* Fixed Base Modular Exponentiator Proxy *
+*************************************************/
+class BOTAN_DLL Fixed_Base_Power_Mod : public Power_Mod
+ {
+ public:
+ BigInt operator()(const BigInt& e) const
+ { set_exponent(e); return execute(); }
+
+ Fixed_Base_Power_Mod() {}
+ Fixed_Base_Power_Mod(const BigInt&, const BigInt&,
+ Usage_Hints = NO_HINTS);
+ };
+
+}
+
+#endif
diff --git a/src/powm_fw.cpp b/src/bigint/powm_fw.cpp
index c29b9f311..c29b9f311 100644
--- a/src/powm_fw.cpp
+++ b/src/bigint/powm_fw.cpp
diff --git a/src/powm_mnt.cpp b/src/bigint/powm_mnt.cpp
index 6091d467a..6091d467a 100644
--- a/src/powm_mnt.cpp
+++ b/src/bigint/powm_mnt.cpp
diff --git a/src/reducer.cpp b/src/bigint/reducer.cpp
index 47c5c20fc..47c5c20fc 100644
--- a/src/reducer.cpp
+++ b/src/bigint/reducer.cpp
diff --git a/src/bigint/reducer.h b/src/bigint/reducer.h
new file mode 100644
index 000000000..48008e73b
--- /dev/null
+++ b/src/bigint/reducer.h
@@ -0,0 +1,34 @@
+/*************************************************
+* Modular Reducer Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_MODARITH_H__
+#define BOTAN_MODARITH_H__
+
+#include <botan/bigint.h>
+
+namespace Botan {
+
+/*************************************************
+* Modular Reducer *
+*************************************************/
+class BOTAN_DLL Modular_Reducer
+ {
+ public:
+ BigInt multiply(const BigInt&, const BigInt&) const;
+ BigInt square(const BigInt&) const;
+ BigInt reduce(const BigInt&) const;
+
+ bool initialized() const { return (mod_words != 0); }
+
+ Modular_Reducer() { mod_words = 0; }
+ Modular_Reducer(const BigInt&);
+ private:
+ BigInt modulus, modulus_2, mu;
+ u32bit mod_words, mod2_words, mu_words;
+ };
+
+}
+
+#endif
diff --git a/src/ressol.cpp b/src/bigint/ressol.cpp
index 0cd2b988a..0cd2b988a 100644
--- a/src/ressol.cpp
+++ b/src/bigint/ressol.cpp
diff --git a/src/charset.cpp b/src/charset.cpp
index 4ebf37abf..73c520be1 100644
--- a/src/charset.cpp
+++ b/src/charset.cpp
@@ -4,9 +4,8 @@
*************************************************/
#include <botan/charset.h>
-#include <botan/hex.h>
-#include <botan/base64.h>
#include <botan/parsing.h>
+#include <botan/exceptn.h>
#include <cctype>
namespace Botan {
@@ -197,75 +196,4 @@ bool caseless_cmp(char a, char b)
}
-/*************************************************
-* Hex Encoder Lookup Tables *
-*************************************************/
-const byte Hex_Encoder::BIN_TO_HEX_UPPER[16] = {
-0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43,
-0x44, 0x45, 0x46 };
-
-const byte Hex_Encoder::BIN_TO_HEX_LOWER[16] = {
-0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62, 0x63,
-0x64, 0x65, 0x66 };
-
-/*************************************************
-* Base64 Encoder Lookup Table *
-*************************************************/
-const byte Base64_Encoder::BIN_TO_BASE64[64] = {
-0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D,
-0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A,
-0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D,
-0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A,
-0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F };
-
-/*************************************************
-* Hex Decoder Lookup Table *
-*************************************************/
-const byte Hex_Decoder::HEX_TO_BIN[256] = {
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x01, 0x02, 0x03,
-0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
-
-/*************************************************
-* Base64 Decoder Lookup Table *
-*************************************************/
-const byte Base64_Decoder::BASE64_TO_BIN[256] = {
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x3E, 0x80, 0x80, 0x80, 0x3F, 0x34, 0x35, 0x36, 0x37,
-0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
-0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
-0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D,
-0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
-
}
diff --git a/src/codec/base64/b64_char.cpp b/src/codec/base64/b64_char.cpp
new file mode 100644
index 000000000..3019c4d36
--- /dev/null
+++ b/src/codec/base64/b64_char.cpp
@@ -0,0 +1,45 @@
+/*************************************************
+* Base64 Codec Character Tables *
+* (C) 1999-2008 Jack Lloyd *
+*************************************************/
+
+#include <botan/base64.h>
+
+namespace Botan {
+
+/*************************************************
+* Base64 Encoder Lookup Table *
+*************************************************/
+const byte Base64_Encoder::BIN_TO_BASE64[64] = {
+0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D,
+0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A,
+0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D,
+0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A,
+0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F };
+
+/*************************************************
+* Base64 Decoder Lookup Table *
+*************************************************/
+const byte Base64_Decoder::BASE64_TO_BIN[256] = {
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x3E, 0x80, 0x80, 0x80, 0x3F, 0x34, 0x35, 0x36, 0x37,
+0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
+0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
+0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D,
+0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
+
+}
diff --git a/src/codec/base64/modinfo.txt b/src/codec/base64/modinfo.txt
index 4e7b38584..c9c05a255 100644
--- a/src/codec/base64/modinfo.txt
+++ b/src/codec/base64/modinfo.txt
@@ -6,5 +6,6 @@ load_on auto
<add>
base64.cpp
+b64_char.cpp
base64.h
</add>
diff --git a/src/codec/hex/hex_char.cpp b/src/codec/hex/hex_char.cpp
new file mode 100644
index 000000000..d34614a10
--- /dev/null
+++ b/src/codec/hex/hex_char.cpp
@@ -0,0 +1,46 @@
+/*************************************************
+* Hex Character Table *
+* (C) 1999-2008 Jack Lloyd *
+*************************************************/
+
+#include <botan/hex.h>
+
+namespace Botan {
+
+/*************************************************
+* Hex Encoder Lookup Tables *
+*************************************************/
+const byte Hex_Encoder::BIN_TO_HEX_UPPER[16] = {
+0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43,
+0x44, 0x45, 0x46 };
+
+const byte Hex_Encoder::BIN_TO_HEX_LOWER[16] = {
+0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62, 0x63,
+0x64, 0x65, 0x66 };
+
+/*************************************************
+* Hex Decoder Lookup Table *
+*************************************************/
+const byte Hex_Decoder::HEX_TO_BIN[256] = {
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x01, 0x02, 0x03,
+0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
+
+}
diff --git a/src/codec/hex/modinfo.txt b/src/codec/hex/modinfo.txt
index e0b07a552..4977742d0 100644
--- a/src/codec/hex/modinfo.txt
+++ b/src/codec/hex/modinfo.txt
@@ -6,5 +6,6 @@ load_on auto
<add>
hex.cpp
+hex_char.cpp
hex.h
</add>