aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/asn1/asn1_alt.cpp2
-rw-r--r--src/asn1/asn1_int.h4
-rw-r--r--src/asn1/asn1_tm.cpp16
-rw-r--r--src/asn1/ber_dec.cpp2
-rw-r--r--src/asn1/der_enc.cpp2
-rw-r--r--src/benchmark/benchmark.cpp17
-rw-r--r--src/block/aes/aes.cpp3
-rw-r--r--src/block/aes_intel/aes_intel.cpp2
-rw-r--r--src/block/blowfish/blowfish.cpp2
-rw-r--r--src/block/cast/cast128.cpp4
-rw-r--r--src/block/cast/cast256.cpp4
-rw-r--r--src/block/des/des.cpp3
-rw-r--r--src/block/gost_28147/gost_28147.cpp3
-rw-r--r--src/block/gost_28147/gost_28147.h4
-rw-r--r--src/block/idea/idea.cpp80
-rw-r--r--src/block/idea/idea.h2
-rw-r--r--src/block/idea_sse2/idea_sse2.cpp227
-rw-r--r--src/block/idea_sse2/idea_sse2.h29
-rw-r--r--src/block/idea_sse2/info.txt7
-rw-r--r--src/block/kasumi/kasumi.cpp4
-rw-r--r--src/block/mars/mars.cpp4
-rw-r--r--src/block/misty1/misty1.cpp2
-rw-r--r--src/block/noekeon/noekeon.cpp4
-rw-r--r--src/block/rc2/rc2.cpp4
-rw-r--r--src/block/rc5/rc5.cpp4
-rw-r--r--src/block/rc6/rc6.cpp4
-rw-r--r--src/block/safer/safer_sk.cpp4
-rw-r--r--src/block/seed/seed.cpp2
-rw-r--r--src/block/serpent/serpent.cpp4
-rw-r--r--src/block/serpent_ia32/serp_ia32.cpp2
-rw-r--r--src/block/serpent_simd/serp_simd.cpp2
-rw-r--r--src/block/skipjack/skipjack.cpp2
-rw-r--r--src/block/square/square.cpp4
-rw-r--r--src/block/tea/tea.cpp2
-rw-r--r--src/block/twofish/twofish.cpp4
-rw-r--r--src/block/xtea/xtea.cpp2
-rw-r--r--src/block/xtea_simd/xtea_simd.cpp2
-rw-r--r--src/build-data/buildh.in16
-rw-r--r--src/build-data/cc/msvc.txt2
-rw-r--r--src/build-data/innosetup.in2
-rw-r--r--src/build-data/os/linux.txt1
-rw-r--r--src/build-data/os/mingw.txt5
-rw-r--r--src/build-data/os/windows.txt2
-rw-r--r--src/cert/cvc/asn1_eac_tm.cpp11
-rw-r--r--src/cert/cvc/eac_obj.h1
-rw-r--r--src/cert/cvc/signed_obj.h1
-rw-r--r--src/cert/x509/pkcs10.cpp2
-rw-r--r--src/cert/x509/x509_ext.cpp5
-rw-r--r--src/cert/x509/x509opt.cpp2
-rw-r--r--src/checksum/adler32/adler32.cpp2
-rw-r--r--src/checksum/crc24/crc24.cpp2
-rw-r--r--src/checksum/crc32/crc32.cpp2
-rw-r--r--src/constructs/aont/package.cpp2
-rw-r--r--src/constructs/aont/package.h14
-rw-r--r--src/constructs/cryptobox/cryptobox.cpp2
-rw-r--r--src/constructs/fpe/fpe.cpp2
-rw-r--r--src/constructs/fpe/fpe.h12
-rw-r--r--src/constructs/tss/tss.cpp2
-rw-r--r--src/constructs/tss/tss.h4
-rw-r--r--src/engine/aes_isa_eng/aes_isa_engine.h2
-rw-r--r--src/engine/aes_isa_eng/info.txt8
-rw-r--r--src/engine/amd64_eng/amd64_engine.cpp (renamed from src/engine/amd64_eng/eng_amd64.cpp)2
-rw-r--r--src/engine/amd64_eng/amd64_engine.h (renamed from src/engine/amd64_eng/eng_amd64.h)2
-rw-r--r--src/engine/amd64_eng/info.txt8
-rw-r--r--src/engine/def_engine/def_mode.cpp2
-rw-r--r--src/engine/def_engine/def_pk_ops.cpp2
-rw-r--r--src/engine/def_engine/def_powm.cpp4
-rw-r--r--src/engine/def_engine/default_engine.h (renamed from src/engine/def_engine/def_eng.h)2
-rw-r--r--src/engine/def_engine/info.txt6
-rw-r--r--src/engine/def_engine/lookup_block.cpp2
-rw-r--r--src/engine/def_engine/lookup_hash.cpp2
-rw-r--r--src/engine/def_engine/lookup_mac.cpp2
-rw-r--r--src/engine/def_engine/lookup_stream.cpp2
-rw-r--r--src/engine/gnump/gmp_dh.cpp4
-rw-r--r--src/engine/gnump/gmp_dsa.cpp4
-rw-r--r--src/engine/gnump/gmp_elg.cpp4
-rw-r--r--src/engine/gnump/gmp_if.cpp4
-rw-r--r--src/engine/gnump/gmp_mem.cpp2
-rw-r--r--src/engine/gnump/gmp_nr.cpp4
-rw-r--r--src/engine/gnump/gmp_powm.cpp4
-rw-r--r--src/engine/gnump/gmp_wrap.cpp2
-rw-r--r--src/engine/gnump/gmp_wrap.h2
-rw-r--r--src/engine/gnump/gnump_engine.h (renamed from src/engine/gnump/eng_gmp.h)2
-rw-r--r--src/engine/gnump/info.txt5
-rw-r--r--src/engine/ia32_eng/ia32_engine.cpp (renamed from src/engine/ia32_eng/eng_ia32.cpp)2
-rw-r--r--src/engine/ia32_eng/ia32_engine.h (renamed from src/engine/ia32_eng/eng_ia32.h)2
-rw-r--r--src/engine/ia32_eng/info.txt8
-rw-r--r--src/engine/openssl/arc4_openssl.cpp2
-rw-r--r--src/engine/openssl/bn_powm.cpp4
-rw-r--r--src/engine/openssl/bn_wrap.cpp2
-rw-r--r--src/engine/openssl/bn_wrap.h4
-rw-r--r--src/engine/openssl/info.txt5
-rw-r--r--src/engine/openssl/openssl_engine.h (renamed from src/engine/openssl/eng_ossl.h)2
-rw-r--r--src/engine/openssl/ossl_bc.cpp2
-rw-r--r--src/engine/openssl/ossl_dh.cpp4
-rw-r--r--src/engine/openssl/ossl_dsa.cpp4
-rw-r--r--src/engine/openssl/ossl_elg.cpp4
-rw-r--r--src/engine/openssl/ossl_if.cpp4
-rw-r--r--src/engine/openssl/ossl_md.cpp2
-rw-r--r--src/engine/openssl/ossl_nr.cpp4
-rw-r--r--src/engine/simd_engine/info.txt8
-rw-r--r--src/engine/simd_engine/simd_engine.cpp16
-rw-r--r--src/engine/simd_engine/simd_engine.h2
-rw-r--r--src/entropy/beos_stats/es_beos.cpp2
-rw-r--r--src/entropy/cryptoapi_rng/es_capi.cpp2
-rw-r--r--src/entropy/entropy_src.h4
-rw-r--r--src/entropy/hres_timer/hres_timer.cpp2
-rw-r--r--src/entropy/win32_stats/es_win32.cpp2
-rw-r--r--src/filters/basefilt.h2
-rw-r--r--src/filters/fd_unix/fd_unix.h4
-rw-r--r--src/filters/modes/cbc/cbc.cpp97
-rw-r--r--src/filters/modes/cbc/cbc.h56
-rw-r--r--src/filters/modes/cbc/info.txt1
-rw-r--r--src/filters/modes/cfb/cfb.cpp148
-rw-r--r--src/filters/modes/cfb/cfb.h55
-rw-r--r--src/filters/modes/cfb/info.txt4
-rw-r--r--src/filters/modes/cts/cts.cpp148
-rw-r--r--src/filters/modes/cts/cts.h52
-rw-r--r--src/filters/modes/cts/info.txt4
-rw-r--r--src/filters/modes/eax/eax.cpp99
-rw-r--r--src/filters/modes/eax/eax.h18
-rw-r--r--src/filters/modes/eax/eax_dec.cpp41
-rw-r--r--src/filters/modes/eax/info.txt2
-rw-r--r--src/filters/modes/ecb/ecb.h4
-rw-r--r--src/filters/modes/ecb/info.txt1
-rw-r--r--src/filters/modes/info.txt6
-rw-r--r--src/filters/modes/mode_pad/mode_pad.cpp3
-rw-r--r--src/filters/modes/modebase.cpp54
-rw-r--r--src/filters/modes/modebase.h44
-rw-r--r--src/filters/modes/xts/info.txt4
-rw-r--r--src/filters/pipe.h2
-rw-r--r--src/hash/bmw/bmw_512.cpp4
-rw-r--r--src/hash/bmw/bmw_512.h2
-rw-r--r--src/hash/fork256/fork256.cpp4
-rw-r--r--src/hash/gost_3411/gost_3411.cpp4
-rw-r--r--src/hash/has160/has160.cpp4
-rw-r--r--src/hash/md4/md4.cpp4
-rw-r--r--src/hash/md4_ia32/md4_ia32.cpp2
-rw-r--r--src/hash/md5/md5.cpp4
-rw-r--r--src/hash/md5_ia32/md5_ia32.cpp2
-rw-r--r--src/hash/mdx_hash/mdx_hash.cpp2
-rw-r--r--src/hash/rmd128/rmd128.cpp4
-rw-r--r--src/hash/rmd160/rmd160.cpp4
-rw-r--r--src/hash/sha1/sha160.cpp4
-rw-r--r--src/hash/sha1_ia32/sha1_ia32.cpp2
-rw-r--r--src/hash/sha1_sse2/sha1_sse2.cpp2
-rw-r--r--src/hash/sha2/sha2_32.cpp4
-rw-r--r--src/hash/sha2/sha2_64.cpp4
-rw-r--r--src/hash/skein/skein_512.cpp7
-rw-r--r--src/hash/tiger/tiger.cpp2
-rw-r--r--src/hash/whirlpool/whrlpool.cpp2
-rw-r--r--src/kdf/kdf2/kdf2.cpp2
-rw-r--r--src/kdf/mgf1/mgf1.cpp2
-rw-r--r--src/kdf/x942_prf/prf_x942.cpp2
-rw-r--r--src/libstate/info.txt5
-rw-r--r--src/libstate/libstate.cpp23
-rw-r--r--src/libstate/lookup.cpp4
-rw-r--r--src/libstate/pk_engine.cpp2
-rw-r--r--src/math/bigint/bigint.cpp2
-rw-r--r--src/math/gfpmath/gfp_element.cpp2
-rw-r--r--src/math/numbertheory/def_powm.h4
-rw-r--r--src/math/numbertheory/info.txt5
-rw-r--r--src/math/numbertheory/numthry.cpp2
-rw-r--r--src/math/numbertheory/numthry.h2
-rw-r--r--src/math/numbertheory/pow_mod.cpp2
-rw-r--r--src/math/numbertheory/powm_fw.cpp2
-rw-r--r--src/math/numbertheory/powm_mnt.cpp2
-rw-r--r--src/pubkey/dh/dh.cpp2
-rw-r--r--src/pubkey/dh/dh_core.cpp2
-rw-r--r--src/pubkey/dl_group/dl_group.cpp2
-rw-r--r--src/pubkey/dsa/dsa_core.cpp2
-rw-r--r--src/pubkey/ecdsa/ecdsa_core.cpp2
-rw-r--r--src/pubkey/ecdsa/ecdsa_op.cpp3
-rw-r--r--src/pubkey/eckaeg/eckaeg_core.cpp2
-rw-r--r--src/pubkey/elgamal/elg_core.cpp2
-rw-r--r--src/pubkey/elgamal/elgamal.cpp2
-rw-r--r--src/pubkey/if_algo/if_core.cpp2
-rw-r--r--src/pubkey/info.txt19
-rw-r--r--src/pubkey/nr/nr_core.cpp2
-rw-r--r--src/pubkey/pk_algs.cpp2
-rw-r--r--src/pubkey/pk_codecs/pkcs8.cpp2
-rw-r--r--src/pubkey/pk_codecs/x509_key.cpp2
-rw-r--r--src/pubkey/workfactor.cpp2
-rw-r--r--src/rng/hmac_rng/hmac_rng.cpp2
-rw-r--r--src/rng/randpool/randpool.cpp2
-rw-r--r--src/s2k/pbkdf2/pbkdf2.cpp2
-rw-r--r--src/selftest/selftest.cpp8
-rw-r--r--src/stream/salsa20/salsa20.cpp3
-rw-r--r--src/stream/turing/turing.cpp3
-rw-r--r--src/stream/wid_wake/wid_wake.cpp2
-rw-r--r--src/utils/bswap.h83
-rw-r--r--src/utils/charset.h14
-rw-r--r--src/utils/cpuid.cpp2
-rw-r--r--src/utils/cpuid.h2
-rw-r--r--src/utils/info.txt6
-rw-r--r--src/utils/loadstor.h48
-rw-r--r--src/utils/parsing.cpp2
-rw-r--r--src/utils/simd_32/simd_altivec.h2
-rw-r--r--src/utils/simd_32/simd_scalar.h4
-rw-r--r--src/utils/time.cpp64
-rw-r--r--src/utils/time.h30
-rw-r--r--src/utils/xor_buf.h4
202 files changed, 1288 insertions, 763 deletions
diff --git a/src/asn1/asn1_alt.cpp b/src/asn1/asn1_alt.cpp
index 6e9adf47b..9fe159356 100644
--- a/src/asn1/asn1_alt.cpp
+++ b/src/asn1/asn1_alt.cpp
@@ -13,7 +13,7 @@
#include <botan/internal/stl_util.h>
#include <botan/charset.h>
#include <botan/parsing.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/asn1/asn1_int.h b/src/asn1/asn1_int.h
index 619f45b53..e6fb09398 100644
--- a/src/asn1/asn1_int.h
+++ b/src/asn1/asn1_int.h
@@ -89,7 +89,7 @@ bool maybe_BER(DataSource&);
/*
* General BER Decoding Error Exception
*/
-struct BER_Decoding_Error : public Decoding_Error
+struct BOTAN_DLL BER_Decoding_Error : public Decoding_Error
{
BER_Decoding_Error(const std::string&);
};
@@ -97,7 +97,7 @@ struct BER_Decoding_Error : public Decoding_Error
/*
* Exception For Incorrect BER Taggings
*/
-struct BER_Bad_Tag : public BER_Decoding_Error
+struct BOTAN_DLL BER_Bad_Tag : public BER_Decoding_Error
{
BER_Bad_Tag(const std::string&, ASN1_Tag);
BER_Bad_Tag(const std::string&, ASN1_Tag, ASN1_Tag);
diff --git a/src/asn1/asn1_tm.cpp b/src/asn1/asn1_tm.cpp
index c57d1bc73..01d31cfbd 100644
--- a/src/asn1/asn1_tm.cpp
+++ b/src/asn1/asn1_tm.cpp
@@ -27,14 +27,14 @@ X509_Time::X509_Time(const std::string& time_str)
*/
X509_Time::X509_Time(u64bit timer)
{
- std::tm time_info = time_t_to_tm(timer);
-
- year = time_info.tm_year + 1900;
- month = time_info.tm_mon + 1;
- day = time_info.tm_mday;
- hour = time_info.tm_hour;
- minute = time_info.tm_min;
- second = time_info.tm_sec;
+ calendar_point cal = calendar_value(timer);
+
+ year = cal.year;
+ month = cal.month;
+ day = cal.day;
+ hour = cal.hour;
+ minute = cal.minutes;
+ second = cal.seconds;
if(year >= 2050)
tag = GENERALIZED_TIME;
diff --git a/src/asn1/ber_dec.cpp b/src/asn1/ber_dec.cpp
index a61bbf00a..b34bf8ca2 100644
--- a/src/asn1/ber_dec.cpp
+++ b/src/asn1/ber_dec.cpp
@@ -7,7 +7,7 @@
#include <botan/ber_dec.h>
#include <botan/bigint.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/asn1/der_enc.cpp b/src/asn1/der_enc.cpp
index 37ba79802..3c318c291 100644
--- a/src/asn1/der_enc.cpp
+++ b/src/asn1/der_enc.cpp
@@ -8,7 +8,7 @@
#include <botan/der_enc.h>
#include <botan/asn1_int.h>
#include <botan/bigint.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/internal/bit_ops.h>
#include <botan/parsing.h>
#include <algorithm>
diff --git a/src/benchmark/benchmark.cpp b/src/benchmark/benchmark.cpp
index 69d3a40ec..01f6b99da 100644
--- a/src/benchmark/benchmark.cpp
+++ b/src/benchmark/benchmark.cpp
@@ -26,15 +26,15 @@ std::pair<u64bit, u64bit> bench_buf_comp(BufferedComputation* buf_comp,
const byte buf[], u32bit buf_len)
{
u64bit reps = 0;
-
- const u64bit start = get_nanoseconds_clock();
u64bit nanoseconds_used = 0;
while(nanoseconds_used < nanoseconds_max)
{
+ const u64bit start = get_nanoseconds_clock();
buf_comp->update(buf, buf_len);
+ nanoseconds_used += get_nanoseconds_clock() - start;
+
++reps;
- nanoseconds_used = get_nanoseconds_clock() - start;
}
return std::make_pair(reps * buf_len, nanoseconds_used);
@@ -51,18 +51,17 @@ bench_block_cipher(BlockCipher* block_cipher,
const u32bit in_blocks = buf_len / block_cipher->BLOCK_SIZE;
u64bit reps = 0;
-
- const u64bit start = get_nanoseconds_clock();
u64bit nanoseconds_used = 0;
block_cipher->set_key(buf, block_cipher->MAXIMUM_KEYLENGTH);
while(nanoseconds_used < nanoseconds_max)
{
+ const u64bit start = get_nanoseconds_clock();
block_cipher->encrypt_n(buf, buf, in_blocks);
+ nanoseconds_used += get_nanoseconds_clock() - start;
++reps;
- nanoseconds_used = get_nanoseconds_clock() - start;
}
return std::make_pair(reps * in_blocks * block_cipher->BLOCK_SIZE,
@@ -78,17 +77,17 @@ bench_stream_cipher(StreamCipher* stream_cipher,
byte buf[], u32bit buf_len)
{
u64bit reps = 0;
-
- const u64bit start = get_nanoseconds_clock();
u64bit nanoseconds_used = 0;
stream_cipher->set_key(buf, stream_cipher->MAXIMUM_KEYLENGTH);
while(nanoseconds_used < nanoseconds_max)
{
+ const u64bit start = get_nanoseconds_clock();
stream_cipher->cipher1(buf, buf_len);
+ nanoseconds_used += get_nanoseconds_clock() - start;
+
++reps;
- nanoseconds_used = get_nanoseconds_clock() - start;
}
return std::make_pair(reps * buf_len, nanoseconds_used);
diff --git a/src/block/aes/aes.cpp b/src/block/aes/aes.cpp
index d972d921a..721c4ac75 100644
--- a/src/block/aes/aes.cpp
+++ b/src/block/aes/aes.cpp
@@ -6,7 +6,8 @@
*/
#include <botan/aes.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/block/aes_intel/aes_intel.cpp b/src/block/aes_intel/aes_intel.cpp
index 5ccf3fc5d..3d3683d7d 100644
--- a/src/block/aes_intel/aes_intel.cpp
+++ b/src/block/aes_intel/aes_intel.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/aes_intel.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <wmmintrin.h>
namespace Botan {
diff --git a/src/block/blowfish/blowfish.cpp b/src/block/blowfish/blowfish.cpp
index 6a00caa90..d0b182a84 100644
--- a/src/block/blowfish/blowfish.cpp
+++ b/src/block/blowfish/blowfish.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/blowfish.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/block/cast/cast128.cpp b/src/block/cast/cast128.cpp
index 2d876d31e..887dcf994 100644
--- a/src/block/cast/cast128.cpp
+++ b/src/block/cast/cast128.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/cast128.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/block/cast/cast256.cpp b/src/block/cast/cast256.cpp
index 832c170aa..7a4a4e805 100644
--- a/src/block/cast/cast256.cpp
+++ b/src/block/cast/cast256.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/cast256.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/block/des/des.cpp b/src/block/des/des.cpp
index 3bc970735..bbe564827 100644
--- a/src/block/des/des.cpp
+++ b/src/block/des/des.cpp
@@ -6,7 +6,8 @@
*/
#include <botan/des.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/block/gost_28147/gost_28147.cpp b/src/block/gost_28147/gost_28147.cpp
index 8340b8ccc..2dfce0473 100644
--- a/src/block/gost_28147/gost_28147.cpp
+++ b/src/block/gost_28147/gost_28147.cpp
@@ -6,7 +6,8 @@
*/
#include <botan/gost_28147.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/block/gost_28147/gost_28147.h b/src/block/gost_28147/gost_28147.h
index bf6f8178b..2b7daaf6a 100644
--- a/src/block/gost_28147/gost_28147.h
+++ b/src/block/gost_28147/gost_28147.h
@@ -12,15 +12,13 @@
namespace Botan {
-class GOST_28147_89_Params;
-
/**
* The GOST 28147-89 block cipher uses a set of 4 bit Sboxes, however
* the standard does not actually define these Sboxes; they are
* considered a local configuration issue. Several different sets are
* used.
*/
-class GOST_28147_89_Params
+class BOTAN_DLL GOST_28147_89_Params
{
public:
byte sbox_entry(u32bit row, u32bit col) const;
diff --git a/src/block/idea/idea.cpp b/src/block/idea/idea.cpp
index 84c401475..15ff7c0ec 100644
--- a/src/block/idea/idea.cpp
+++ b/src/block/idea/idea.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/idea.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
@@ -55,13 +55,13 @@ u16bit mul_inv(u16bit x)
return (1 - t0);
}
-}
-
-/*
-* IDEA Encryption
+/**
+* IDEA is involutional, depending only on the key schedule
*/
-void IDEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const
+void idea_op(const byte in[], byte out[], u32bit blocks, const u16bit K[52])
{
+ const u32bit BLOCK_SIZE = 8;
+
for(u32bit i = 0; i != blocks; ++i)
{
u16bit X1 = load_be<u16bit>(in, 0);
@@ -71,16 +71,16 @@ void IDEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const
for(u32bit j = 0; j != 8; ++j)
{
- X1 = mul(X1, EK[6*j+0]);
- X2 += EK[6*j+1];
- X3 += EK[6*j+2];
- X4 = mul(X4, EK[6*j+3]);
+ X1 = mul(X1, K[6*j+0]);
+ X2 += K[6*j+1];
+ X3 += K[6*j+2];
+ X4 = mul(X4, K[6*j+3]);
u16bit T0 = X3;
- X3 = mul(X3 ^ X1, EK[6*j+4]);
+ X3 = mul(X3 ^ X1, K[6*j+4]);
u16bit T1 = X2;
- X2 = mul((X2 ^ X4) + X3, EK[6*j+5]);
+ X2 = mul((X2 ^ X4) + X3, K[6*j+5]);
X3 += X2;
X1 ^= X2;
@@ -89,10 +89,10 @@ void IDEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const
X3 ^= T1;
}
- X1 = mul(X1, EK[48]);
- X2 += EK[50];
- X3 += EK[49];
- X4 = mul(X4, EK[51]);
+ X1 = mul(X1, K[48]);
+ X2 += K[50];
+ X3 += K[49];
+ X4 = mul(X4, K[51]);
store_be(out, X1, X3, X2, X4);
@@ -101,48 +101,22 @@ void IDEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const
}
}
+}
+
+/*
+* IDEA Encryption
+*/
+void IDEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const
+ {
+ idea_op(in, out, blocks, EK);
+ }
+
/*
* IDEA Decryption
*/
void IDEA::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
- for(u32bit i = 0; i != blocks; ++i)
- {
- u16bit X1 = load_be<u16bit>(in, 0);
- u16bit X2 = load_be<u16bit>(in, 1);
- u16bit X3 = load_be<u16bit>(in, 2);
- u16bit X4 = load_be<u16bit>(in, 3);
-
- for(u32bit j = 0; j != 8; ++j)
- {
- X1 = mul(X1, DK[6*j+0]);
- X2 += DK[6*j+1];
- X3 += DK[6*j+2];
- X4 = mul(X4, DK[6*j+3]);
-
- u16bit T0 = X3;
- X3 = mul(X3 ^ X1, DK[6*j+4]);
-
- u16bit T1 = X2;
- X2 = mul((X2 ^ X4) + X3, DK[6*j+5]);
- X3 += X2;
-
- X1 ^= X2;
- X4 ^= X3;
- X2 ^= T0;
- X3 ^= T1;
- }
-
- X1 = mul(X1, DK[48]);
- X2 += DK[50];
- X3 += DK[49];
- X4 = mul(X4, DK[51]);
-
- store_be(out, X1, X3, X2, X4);
-
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
- }
+ idea_op(in, out, blocks, DK);
}
/*
diff --git a/src/block/idea/idea.h b/src/block/idea/idea.h
index c1a79f423..89ec117e3 100644
--- a/src/block/idea/idea.h
+++ b/src/block/idea/idea.h
@@ -26,7 +26,7 @@ class BOTAN_DLL IDEA : public BlockCipher
BlockCipher* clone() const { return new IDEA; }
IDEA() : BlockCipher(8, 16) {}
- private:
+ protected:
void key_schedule(const byte[], u32bit);
SecureBuffer<u16bit, 52> EK, DK;
};
diff --git a/src/block/idea_sse2/idea_sse2.cpp b/src/block/idea_sse2/idea_sse2.cpp
new file mode 100644
index 000000000..c00d13ee9
--- /dev/null
+++ b/src/block/idea_sse2/idea_sse2.cpp
@@ -0,0 +1,227 @@
+/*
+* IDEA in SSE2
+* (C) 2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/idea_sse2.h>
+#include <botan/loadstor.h>
+#include <emmintrin.h>
+
+namespace Botan {
+
+namespace {
+
+inline __m128i mul(__m128i X, u16bit K_16)
+ {
+ const __m128i zeros = _mm_set1_epi16(0);
+ const __m128i ones = _mm_set1_epi16(1);
+ const __m128i high_bit = _mm_set1_epi16(0x8000);
+
+ const __m128i K = _mm_set1_epi16(K_16);
+
+ const __m128i X_is_zero = _mm_cmpeq_epi16(X, zeros);
+ const __m128i K_is_zero = _mm_cmpeq_epi16(K, zeros);
+
+ const __m128i mul_lo = _mm_mullo_epi16(X, K);
+ const __m128i mul_hi = _mm_mulhi_epu16(X, K);
+
+ __m128i T = _mm_sub_epi16(mul_lo, mul_hi);
+
+ // Unsigned compare; cmp = 1 if mul_lo < mul_hi else 0
+ const __m128i cmp = _mm_srli_epi16(_mm_cmpgt_epi16(
+ _mm_add_epi16(mul_hi, high_bit),
+ _mm_add_epi16(mul_lo, high_bit)),
+ 15);
+
+ T = _mm_add_epi16(T, cmp);
+
+ /* Selection: if X[i] is zero then assign 1-K
+ if K is zero then assign 1-X[i]
+
+ Could if() off value of K_16 for the second, but this gives a
+ constant time implementation which is a nice bonus.
+ */
+
+ T = _mm_or_si128(
+ _mm_andnot_si128(X_is_zero, T),
+ _mm_and_si128(_mm_sub_epi16(ones, K), X_is_zero));
+
+ T = _mm_or_si128(
+ _mm_andnot_si128(K_is_zero, T),
+ _mm_and_si128(_mm_sub_epi16(ones, X), K_is_zero));
+
+ return T;
+ }
+
+/*
+* 4x8 matrix transpose
+*
+* FIXME: why do I need the extra set of unpack_epi32 here? Inverse in
+* transpose_out doesn't need it. Something with the shuffle? Removing
+* that extra unpack could easily save 3-4 cycles per block, and would
+* also help a lot with register pressure on 32-bit x86
+*/
+void transpose_in(__m128i& B0, __m128i& B1, __m128i& B2, __m128i& B3)
+ {
+ __m128i T0 = _mm_unpackhi_epi32(B0, B1);
+ __m128i T1 = _mm_unpacklo_epi32(B0, B1);
+ __m128i T2 = _mm_unpackhi_epi32(B2, B3);
+ __m128i T3 = _mm_unpacklo_epi32(B2, B3);
+
+ __m128i T4 = _mm_unpacklo_epi32(T0, T1);
+ __m128i T5 = _mm_unpackhi_epi32(T0, T1);
+ __m128i T6 = _mm_unpacklo_epi32(T2, T3);
+ __m128i T7 = _mm_unpackhi_epi32(T2, T3);
+
+ T0 = _mm_shufflehi_epi16(T4, _MM_SHUFFLE(1, 3, 0, 2));
+ T1 = _mm_shufflehi_epi16(T5, _MM_SHUFFLE(1, 3, 0, 2));
+ T2 = _mm_shufflehi_epi16(T6, _MM_SHUFFLE(1, 3, 0, 2));
+ T3 = _mm_shufflehi_epi16(T7, _MM_SHUFFLE(1, 3, 0, 2));
+
+ T0 = _mm_shufflelo_epi16(T0, _MM_SHUFFLE(1, 3, 0, 2));
+ T1 = _mm_shufflelo_epi16(T1, _MM_SHUFFLE(1, 3, 0, 2));
+ T2 = _mm_shufflelo_epi16(T2, _MM_SHUFFLE(1, 3, 0, 2));
+ T3 = _mm_shufflelo_epi16(T3, _MM_SHUFFLE(1, 3, 0, 2));
+
+ T0 = _mm_shuffle_epi32(T0, _MM_SHUFFLE(3, 1, 2, 0));
+ T1 = _mm_shuffle_epi32(T1, _MM_SHUFFLE(3, 1, 2, 0));
+ T2 = _mm_shuffle_epi32(T2, _MM_SHUFFLE(3, 1, 2, 0));
+ T3 = _mm_shuffle_epi32(T3, _MM_SHUFFLE(3, 1, 2, 0));
+
+ B0 = _mm_unpacklo_epi64(T0, T2);
+ B1 = _mm_unpackhi_epi64(T0, T2);
+ B2 = _mm_unpacklo_epi64(T1, T3);
+ B3 = _mm_unpackhi_epi64(T1, T3);
+ }
+
+/*
+* 4x8 matrix transpose (reverse)
+*/
+void transpose_out(__m128i& B0, __m128i& B1, __m128i& B2, __m128i& B3)
+ {
+ __m128i T0 = _mm_unpacklo_epi64(B0, B1);
+ __m128i T1 = _mm_unpacklo_epi64(B2, B3);
+ __m128i T2 = _mm_unpackhi_epi64(B0, B1);
+ __m128i T3 = _mm_unpackhi_epi64(B2, B3);
+
+ T0 = _mm_shuffle_epi32(T0, _MM_SHUFFLE(3, 1, 2, 0));
+ T1 = _mm_shuffle_epi32(T1, _MM_SHUFFLE(3, 1, 2, 0));
+ T2 = _mm_shuffle_epi32(T2, _MM_SHUFFLE(3, 1, 2, 0));
+ T3 = _mm_shuffle_epi32(T3, _MM_SHUFFLE(3, 1, 2, 0));
+
+ T0 = _mm_shufflehi_epi16(T0, _MM_SHUFFLE(3, 1, 2, 0));
+ T1 = _mm_shufflehi_epi16(T1, _MM_SHUFFLE(3, 1, 2, 0));
+ T2 = _mm_shufflehi_epi16(T2, _MM_SHUFFLE(3, 1, 2, 0));
+ T3 = _mm_shufflehi_epi16(T3, _MM_SHUFFLE(3, 1, 2, 0));
+
+ T0 = _mm_shufflelo_epi16(T0, _MM_SHUFFLE(3, 1, 2, 0));
+ T1 = _mm_shufflelo_epi16(T1, _MM_SHUFFLE(3, 1, 2, 0));
+ T2 = _mm_shufflelo_epi16(T2, _MM_SHUFFLE(3, 1, 2, 0));
+ T3 = _mm_shufflelo_epi16(T3, _MM_SHUFFLE(3, 1, 2, 0));
+
+ B0 = _mm_unpacklo_epi32(T0, T1);
+ B1 = _mm_unpackhi_epi32(T0, T1);
+ B2 = _mm_unpacklo_epi32(T2, T3);
+ B3 = _mm_unpackhi_epi32(T2, T3);
+ }
+
+/*
+* IDEA encryption/decryption in SSE2
+*/
+void idea_op_8(const byte in[64], byte out[64], const u16bit EK[52])
+ {
+ __m128i B0 = _mm_loadu_si128((const __m128i*)in);
+ __m128i B1 = _mm_loadu_si128((const __m128i*)in + 1);
+ __m128i B2 = _mm_loadu_si128((const __m128i*)in + 2);
+ __m128i B3 = _mm_loadu_si128((const __m128i*)in + 3);
+
+ transpose_in(B0, B1, B2, B3);
+
+ // byte swap
+ B0 = _mm_or_si128(_mm_slli_epi16(B0, 8), _mm_srli_epi16(B0, 8));
+ B1 = _mm_or_si128(_mm_slli_epi16(B1, 8), _mm_srli_epi16(B1, 8));
+ B2 = _mm_or_si128(_mm_slli_epi16(B2, 8), _mm_srli_epi16(B2, 8));
+ B3 = _mm_or_si128(_mm_slli_epi16(B3, 8), _mm_srli_epi16(B3, 8));
+
+ for(u32bit i = 0; i != 8; ++i)
+ {
+ B0 = mul(B0, EK[6*i+0]);
+ B1 = _mm_add_epi16(B1, _mm_set1_epi16(EK[6*i+1]));
+ B2 = _mm_add_epi16(B2, _mm_set1_epi16(EK[6*i+2]));
+ B3 = mul(B3, EK[6*i+3]);
+
+ __m128i T0 = B2;
+
+ B2 = _mm_xor_si128(B2, B0);
+ B2 = mul(B2, EK[6*i+4]);
+
+ __m128i T1 = B1;
+
+ B1 = _mm_xor_si128(B1, B3);
+ B1 = _mm_add_epi16(B1, B2);
+ B1 = mul(B1, EK[6*i+5]);
+
+ B2 = _mm_add_epi16(B2, B1);
+
+ B0 = _mm_xor_si128(B0, B1);
+ B1 = _mm_xor_si128(B1, T0);
+ B3 = _mm_xor_si128(B3, B2);
+ B2 = _mm_xor_si128(B2, T1);
+ }
+
+ B0 = mul(B0, EK[48]);
+ B1 = _mm_add_epi16(B1, _mm_set1_epi16(EK[50]));
+ B2 = _mm_add_epi16(B2, _mm_set1_epi16(EK[49]));
+ B3 = mul(B3, EK[51]);
+
+ // byte swap
+ B0 = _mm_or_si128(_mm_slli_epi16(B0, 8), _mm_srli_epi16(B0, 8));
+ B1 = _mm_or_si128(_mm_slli_epi16(B1, 8), _mm_srli_epi16(B1, 8));
+ B2 = _mm_or_si128(_mm_slli_epi16(B2, 8), _mm_srli_epi16(B2, 8));
+ B3 = _mm_or_si128(_mm_slli_epi16(B3, 8), _mm_srli_epi16(B3, 8));
+
+ transpose_out(B0, B2, B1, B3);
+
+ _mm_storeu_si128((__m128i*)out, B0);
+ _mm_storeu_si128((__m128i*)out + 1, B2);
+ _mm_storeu_si128((__m128i*)out + 2, B1);
+ _mm_storeu_si128((__m128i*)out + 3, B3);
+ }
+
+}
+
+/*
+* IDEA Encryption
+*/
+void IDEA_SSE2::encrypt_n(const byte in[], byte out[], u32bit blocks) const
+ {
+ while(blocks >= 8)
+ {
+ idea_op_8(in, out, this->EK);
+ in += 8 * BLOCK_SIZE;
+ out += 8 * BLOCK_SIZE;
+ blocks -= 8;
+ }
+
+ IDEA::encrypt_n(in, out, blocks);
+ }
+
+/*
+* IDEA Decryption
+*/
+void IDEA_SSE2::decrypt_n(const byte in[], byte out[], u32bit blocks) const
+ {
+ while(blocks >= 8)
+ {
+ idea_op_8(in, out, this->DK);
+ in += 8 * BLOCK_SIZE;
+ out += 8 * BLOCK_SIZE;
+ blocks -= 8;
+ }
+
+ IDEA::decrypt_n(in, out, blocks);
+ }
+
+}
diff --git a/src/block/idea_sse2/idea_sse2.h b/src/block/idea_sse2/idea_sse2.h
new file mode 100644
index 000000000..167c981f8
--- /dev/null
+++ b/src/block/idea_sse2/idea_sse2.h
@@ -0,0 +1,29 @@
+/*
+* IDEA in SSE2
+* (C) 2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_IDEA_SSE2_H__
+#define BOTAN_IDEA_SSE2_H__
+
+#include <botan/idea.h>
+
+namespace Botan {
+
+/*
+* IDEA in SSE2
+*/
+class BOTAN_DLL IDEA_SSE2 : public IDEA
+ {
+ public:
+ void encrypt_n(const byte in[], byte out[], u32bit blocks) const;
+ void decrypt_n(const byte in[], byte out[], u32bit blocks) const;
+
+ BlockCipher* clone() const { return new IDEA_SSE2; }
+ };
+
+}
+
+#endif
diff --git a/src/block/idea_sse2/info.txt b/src/block/idea_sse2/info.txt
new file mode 100644
index 000000000..fe09d3ee5
--- /dev/null
+++ b/src/block/idea_sse2/info.txt
@@ -0,0 +1,7 @@
+define IDEA_SSE2
+
+need_isa sse2
+
+<requires>
+idea
+</requires>
diff --git a/src/block/kasumi/kasumi.cpp b/src/block/kasumi/kasumi.cpp
index e22948293..dff6db13c 100644
--- a/src/block/kasumi/kasumi.cpp
+++ b/src/block/kasumi/kasumi.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/kasumi.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/block/mars/mars.cpp b/src/block/mars/mars.cpp
index 526073cef..6b73ea054 100644
--- a/src/block/mars/mars.cpp
+++ b/src/block/mars/mars.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/mars.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/block/misty1/misty1.cpp b/src/block/misty1/misty1.cpp
index fcd647a76..8a92824cc 100644
--- a/src/block/misty1/misty1.cpp
+++ b/src/block/misty1/misty1.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/misty1.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/parsing.h>
namespace Botan {
diff --git a/src/block/noekeon/noekeon.cpp b/src/block/noekeon/noekeon.cpp
index 74a485773..0bfce1882 100644
--- a/src/block/noekeon/noekeon.cpp
+++ b/src/block/noekeon/noekeon.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/noekeon.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/block/rc2/rc2.cpp b/src/block/rc2/rc2.cpp
index 7fd1ed80e..b5e4a7d50 100644
--- a/src/block/rc2/rc2.cpp
+++ b/src/block/rc2/rc2.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/rc2.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/block/rc5/rc5.cpp b/src/block/rc5/rc5.cpp
index c0f555103..0bd596b10 100644
--- a/src/block/rc5/rc5.cpp
+++ b/src/block/rc5/rc5.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/rc5.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
#include <botan/parsing.h>
#include <algorithm>
diff --git a/src/block/rc6/rc6.cpp b/src/block/rc6/rc6.cpp
index 5c2aba60a..8bda62259 100644
--- a/src/block/rc6/rc6.cpp
+++ b/src/block/rc6/rc6.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/rc6.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
#include <algorithm>
namespace Botan {
diff --git a/src/block/safer/safer_sk.cpp b/src/block/safer/safer_sk.cpp
index 540efde79..eb5c22fc9 100644
--- a/src/block/safer/safer_sk.cpp
+++ b/src/block/safer/safer_sk.cpp
@@ -6,9 +6,9 @@
*/
#include <botan/safer_sk.h>
-#include <botan/internal/rotate.h>
+#include <botan/rotate.h>
#include <botan/parsing.h>
-#include <botan/internal/rotate.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/block/seed/seed.cpp b/src/block/seed/seed.cpp
index b674fce95..378be16e4 100644
--- a/src/block/seed/seed.cpp
+++ b/src/block/seed/seed.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/seed.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/block/serpent/serpent.cpp b/src/block/serpent/serpent.cpp
index d08e0c384..e16afc89c 100644
--- a/src/block/serpent/serpent.cpp
+++ b/src/block/serpent/serpent.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/serpent.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/block/serpent_ia32/serp_ia32.cpp b/src/block/serpent_ia32/serp_ia32.cpp
index 3b90f4950..721584b18 100644
--- a/src/block/serpent_ia32/serp_ia32.cpp
+++ b/src/block/serpent_ia32/serp_ia32.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/serp_ia32.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/block/serpent_simd/serp_simd.cpp b/src/block/serpent_simd/serp_simd.cpp
index 3a42db55f..0a535c9a0 100644
--- a/src/block/serpent_simd/serp_simd.cpp
+++ b/src/block/serpent_simd/serp_simd.cpp
@@ -8,7 +8,7 @@
#include <botan/serp_simd.h>
#include <botan/internal/serp_simd_sbox.h>
#include <botan/internal/simd_32.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/block/skipjack/skipjack.cpp b/src/block/skipjack/skipjack.cpp
index b1765d67a..b23d1e160 100644
--- a/src/block/skipjack/skipjack.cpp
+++ b/src/block/skipjack/skipjack.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/skipjack.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/block/square/square.cpp b/src/block/square/square.cpp
index a64e2538e..892568655 100644
--- a/src/block/square/square.cpp
+++ b/src/block/square/square.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/square.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/block/tea/tea.cpp b/src/block/tea/tea.cpp
index 617c9505a..de30858da 100644
--- a/src/block/tea/tea.cpp
+++ b/src/block/tea/tea.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/tea.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/block/twofish/twofish.cpp b/src/block/twofish/twofish.cpp
index 1969b615b..3136837aa 100644
--- a/src/block/twofish/twofish.cpp
+++ b/src/block/twofish/twofish.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/twofish.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/block/xtea/xtea.cpp b/src/block/xtea/xtea.cpp
index 2172d63b8..fc14c0a57 100644
--- a/src/block/xtea/xtea.cpp
+++ b/src/block/xtea/xtea.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/xtea.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/block/xtea_simd/xtea_simd.cpp b/src/block/xtea_simd/xtea_simd.cpp
index a8d1fe810..264d4f949 100644
--- a/src/block/xtea_simd/xtea_simd.cpp
+++ b/src/block/xtea_simd/xtea_simd.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/xtea_simd.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/internal/simd_32.h>
namespace Botan {
diff --git a/src/build-data/buildh.in b/src/build-data/buildh.in
index 37ff06f9d..7588dc99b 100644
--- a/src/build-data/buildh.in
+++ b/src/build-data/buildh.in
@@ -30,8 +30,7 @@
#define BOTAN_PARALLEL_BLOCKS_ECB 8
#define BOTAN_PARALLEL_BLOCKS_CBC 8
#define BOTAN_PARALLEL_BLOCKS_CFB 8
-#define BOTAN_PARALLEL_BLOCKS_CTR 8
-#define BOTAN_PARALLEL_BLOCKS_EAX 8
+#define BOTAN_PARALLEL_BLOCKS_CTR 16
#define BOTAN_PARALLEL_BLOCKS_XTS 8
/* PK key consistency checking toggles */
@@ -44,7 +43,7 @@
#define BOTAN_USE_GCC_INLINE_ASM 1
#endif
-#ifndef BOTAN_USE_GCC_INLINE_ASM
+#if !defined(BOTAN_USE_GCC_INLINE_ASM)
#define BOTAN_USE_GCC_INLINE_ASM 0
#endif
@@ -53,8 +52,19 @@
%{target_cpu_defines}
+#if defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN) || \
+ defined(BOTAN_TARGET_CPU_IS_BIG_ENDIAN)
+ #define BOTAN_TARGET_CPU_HAS_KNOWN_ENDIANNESS
+#endif
+
%{target_compiler_defines}
+#if defined(BOTAN_BUILD_COMPILER_IS_MSVC)
+ // 4250: inherits via dominance (diamond inheritence issue)
+ // 4251: needs DLL interface (STL DLL exports)
+ #pragma warning(disable: 4250 4251)
+#endif
+
/* Module definitions */
%{module_defines}
diff --git a/src/build-data/cc/msvc.txt b/src/build-data/cc/msvc.txt
index 892e80c4b..36437e6a2 100644
--- a/src/build-data/cc/msvc.txt
+++ b/src/build-data/cc/msvc.txt
@@ -12,7 +12,7 @@ no_debug_flags "/O2"
debug_flags "/Od /Zi /DDEBUG"
check_opt_flags "/O2 /D_CONSOLE"
lang_flags "/EHsc /GR"
-warning_flags ""
+warning_flags "/W3"
shared_flags "/DBOTAN_DLL=__declspec(dllexport)"
dll_import_flags "__declspec(dllimport)"
diff --git a/src/build-data/innosetup.in b/src/build-data/innosetup.in
index 228ab4e97..c3e0f1ebd 100644
--- a/src/build-data/innosetup.in
+++ b/src/build-data/innosetup.in
@@ -9,7 +9,7 @@ AppPublisherURL=http://botan.randombit.net/
AppVersion=%{version}
VersionInfoCopyright=Copyright (C) 1999-2009 Jack Lloyd and others
-VersionInfoVersion=%{version}.0
+VersionInfoVersion=%{version_major}.%{version_minor}.%{version_patch}.0
; Require at least Windows 98 or 2000
MinVersion=4.1,5.0
diff --git a/src/build-data/os/linux.txt b/src/build-data/os/linux.txt
index b3c227533..2f59fb9d1 100644
--- a/src/build-data/os/linux.txt
+++ b/src/build-data/os/linux.txt
@@ -4,6 +4,7 @@ os_type unix
clock_gettime
gettimeofday
posix_mlock
+gmtime_r
</target_features>
# Is this correct?
diff --git a/src/build-data/os/mingw.txt b/src/build-data/os/mingw.txt
index 2b7a16cf7..1b30e0b3a 100644
--- a/src/build-data/os/mingw.txt
+++ b/src/build-data/os/mingw.txt
@@ -19,3 +19,8 @@ install_cmd_exec "install -m 755"
msys
mingw32
</aliases>
+
+<target_features>
+win32_virtual_lock
+win32_get_systemtime
+</target_features>
diff --git a/src/build-data/os/windows.txt b/src/build-data/os/windows.txt
index e72931c98..4d8879dd8 100644
--- a/src/build-data/os/windows.txt
+++ b/src/build-data/os/windows.txt
@@ -12,6 +12,8 @@ install_cmd_exec "copy"
<target_features>
win32_virtual_lock
+win32_get_systemtime
+gmtime_s
</target_features>
<supports_shared>
diff --git a/src/cert/cvc/asn1_eac_tm.cpp b/src/cert/cvc/asn1_eac_tm.cpp
index ee2ed2ddf..dc38e3296 100644
--- a/src/cert/cvc/asn1_eac_tm.cpp
+++ b/src/cert/cvc/asn1_eac_tm.cpp
@@ -50,14 +50,13 @@ u32bit dec_two_digit(byte b1, byte b2)
/*
* Create an EAC_Time
*/
-EAC_Time::EAC_Time(u64bit timer, ASN1_Tag t)
- :tag(t)
+EAC_Time::EAC_Time(u64bit timer, ASN1_Tag t) : tag(t)
{
- std::tm time_info = time_t_to_tm(timer);
+ calendar_point cal = calendar_value(timer);
- year = time_info.tm_year + 1900;
- month = time_info.tm_mon + 1;
- day = time_info.tm_mday;
+ year = cal.year;
+ month = cal.month;
+ day = cal.day;
}
/*
diff --git a/src/cert/cvc/eac_obj.h b/src/cert/cvc/eac_obj.h
index 2c1250a9a..d357adb7d 100644
--- a/src/cert/cvc/eac_obj.h
+++ b/src/cert/cvc/eac_obj.h
@@ -18,6 +18,7 @@
#include <botan/oids.h>
#include <botan/look_pk.h>
#include <botan/ecdsa_sig.h>
+#include <botan/freestore.h>
#include <string>
namespace Botan {
diff --git a/src/cert/cvc/signed_obj.h b/src/cert/cvc/signed_obj.h
index 3c233d21b..17b75a08a 100644
--- a/src/cert/cvc/signed_obj.h
+++ b/src/cert/cvc/signed_obj.h
@@ -11,7 +11,6 @@
#include <botan/asn1_obj.h>
#include <botan/pubkey_enums.h>
-#include <botan/freestore.h>
#include <botan/pipe.h>
#include <vector>
diff --git a/src/cert/x509/pkcs10.cpp b/src/cert/x509/pkcs10.cpp
index 5617cece4..81bb58555 100644
--- a/src/cert/x509/pkcs10.cpp
+++ b/src/cert/x509/pkcs10.cpp
@@ -186,7 +186,7 @@ std::vector<OID> PKCS10_Request::ex_constraints() const
*/
bool PKCS10_Request::is_CA() const
{
- return info.get1_u32bit("X509v3.BasicConstraints.is_ca");
+ return (info.get1_u32bit("X509v3.BasicConstraints.is_ca") > 0);
}
/*
diff --git a/src/cert/x509/x509_ext.cpp b/src/cert/x509/x509_ext.cpp
index e88b5a268..9a03c9d23 100644
--- a/src/cert/x509/x509_ext.cpp
+++ b/src/cert/x509/x509_ext.cpp
@@ -471,8 +471,10 @@ class Policy_Information : public ASN1_Object
*/
MemoryVector<byte> Certificate_Policies::encode_inner() const
{
+ // FIXME
+#if 1
throw Exception("Certificate_Policies::encode_inner: Bugged");
-
+#else
std::vector<Policy_Information> policies;
return DER_Encoder()
@@ -480,6 +482,7 @@ MemoryVector<byte> Certificate_Policies::encode_inner() const
.encode_list(policies)
.end_cons()
.get_contents();
+#endif
}
/*
diff --git a/src/cert/x509/x509opt.cpp b/src/cert/x509/x509opt.cpp
index c6421d9ca..0702ebf19 100644
--- a/src/cert/x509/x509opt.cpp
+++ b/src/cert/x509/x509opt.cpp
@@ -84,7 +84,7 @@ X509_Cert_Options::X509_Cert_Options(const std::string& initial_opts,
path_limit = 0;
constraints = NO_CONSTRAINTS;
- const u32bit now = system_time();
+ const u64bit now = system_time();
start = X509_Time(now);
end = X509_Time(now + expiration_time_in_seconds);
diff --git a/src/checksum/adler32/adler32.cpp b/src/checksum/adler32/adler32.cpp
index 2af1f22ce..c66943b88 100644
--- a/src/checksum/adler32/adler32.cpp
+++ b/src/checksum/adler32/adler32.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/adler32.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/checksum/crc24/crc24.cpp b/src/checksum/crc24/crc24.cpp
index 6023ace73..e50b4d33e 100644
--- a/src/checksum/crc24/crc24.cpp
+++ b/src/checksum/crc24/crc24.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/crc24.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/checksum/crc32/crc32.cpp b/src/checksum/crc32/crc32.cpp
index 1f118c023..42462096f 100644
--- a/src/checksum/crc32/crc32.cpp
+++ b/src/checksum/crc32/crc32.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/crc32.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/constructs/aont/package.cpp b/src/constructs/aont/package.cpp
index 23b020e8a..8d2d7257d 100644
--- a/src/constructs/aont/package.cpp
+++ b/src/constructs/aont/package.cpp
@@ -9,7 +9,7 @@
#include <botan/package.h>
#include <botan/filters.h>
#include <botan/ctr.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/internal/xor_buf.h>
namespace Botan {
diff --git a/src/constructs/aont/package.h b/src/constructs/aont/package.h
index 5024c0421..9c23d1836 100644
--- a/src/constructs/aont/package.h
+++ b/src/constructs/aont/package.h
@@ -25,10 +25,10 @@ namespace AllOrNothingTransform {
* @arg output the output data buffer (must be at least
* input_len + cipher->BLOCK_SIZE bytes long)
*/
-void package(RandomNumberGenerator& rng,
- BlockCipher* cipher,
- const byte input[], u32bit input_len,
- byte output[]);
+void BOTAN_DLL package(RandomNumberGenerator& rng,
+ BlockCipher* cipher,
+ const byte input[], u32bit input_len,
+ byte output[]);
/**
* Rivest's Package Tranform (Inversion)
@@ -39,9 +39,9 @@ void package(RandomNumberGenerator& rng,
* @arg output the output data buffer (must be at least
* input_len - cipher->BLOCK_SIZE bytes long)
*/
-void unpackage(BlockCipher* cipher,
- const byte input[], u32bit input_len,
- byte output[]);
+void BOTAN_DLL unpackage(BlockCipher* cipher,
+ const byte input[], u32bit input_len,
+ byte output[]);
}
diff --git a/src/constructs/cryptobox/cryptobox.cpp b/src/constructs/cryptobox/cryptobox.cpp
index 1c7975a7d..ba7553c55 100644
--- a/src/constructs/cryptobox/cryptobox.cpp
+++ b/src/constructs/cryptobox/cryptobox.cpp
@@ -13,7 +13,7 @@
#include <botan/hmac.h>
#include <botan/pbkdf2.h>
#include <botan/pem.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/mem_ops.h>
namespace Botan {
diff --git a/src/constructs/fpe/fpe.cpp b/src/constructs/fpe/fpe.cpp
index 17f9a1406..86e56625d 100644
--- a/src/constructs/fpe/fpe.cpp
+++ b/src/constructs/fpe/fpe.cpp
@@ -12,7 +12,7 @@
#include <botan/numthry.h>
#include <botan/hmac.h>
#include <botan/sha2_32.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <stdexcept>
namespace Botan {
diff --git a/src/constructs/fpe/fpe.h b/src/constructs/fpe/fpe.h
index fba1652d3..75f90247f 100644
--- a/src/constructs/fpe/fpe.h
+++ b/src/constructs/fpe/fpe.h
@@ -16,16 +16,16 @@ namespace Botan {
/*
* Encrypt X from and onto the group Z_n using key and tweak
*/
-BigInt fpe_encrypt(const BigInt& n, const BigInt& X,
- const SymmetricKey& key,
- const MemoryRegion<byte>& tweak);
+BigInt BOTAN_DLL fpe_encrypt(const BigInt& n, const BigInt& X,
+ const SymmetricKey& key,
+ const MemoryRegion<byte>& tweak);
/*
* Decrypt X from and onto the group Z_n using key and tweak
*/
-BigInt fpe_decrypt(const BigInt& n, const BigInt& X,
- const SymmetricKey& key,
- const MemoryRegion<byte>& tweak);
+BigInt BOTAN_DLL fpe_decrypt(const BigInt& n, const BigInt& X,
+ const SymmetricKey& key,
+ const MemoryRegion<byte>& tweak);
}
diff --git a/src/constructs/tss/tss.cpp b/src/constructs/tss/tss.cpp
index d38741235..0782a27d1 100644
--- a/src/constructs/tss/tss.cpp
+++ b/src/constructs/tss/tss.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/tss.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/pipe.h>
#include <botan/hex.h>
#include <botan/sha2_32.h>
diff --git a/src/constructs/tss/tss.h b/src/constructs/tss/tss.h
index 6e623c193..c8b0242d8 100644
--- a/src/constructs/tss/tss.h
+++ b/src/constructs/tss/tss.h
@@ -15,7 +15,7 @@
namespace Botan {
-class RTSS_Share
+class BOTAN_DLL RTSS_Share
{
public:
/**
@@ -45,7 +45,7 @@ class RTSS_Share
byte share_id() const;
u32bit size() const { return contents.size(); }
- bool initialized() const { return contents.size(); }
+ bool initialized() const { return (contents.size() > 0); }
private:
SecureVector<byte> contents;
};
diff --git a/src/engine/aes_isa_eng/aes_isa_engine.h b/src/engine/aes_isa_eng/aes_isa_engine.h
index 602a114a9..5f22e4105 100644
--- a/src/engine/aes_isa_eng/aes_isa_engine.h
+++ b/src/engine/aes_isa_eng/aes_isa_engine.h
@@ -12,7 +12,7 @@
namespace Botan {
-class BOTAN_DLL AES_ISA_Engine : public Engine
+class AES_ISA_Engine : public Engine
{
public:
std::string provider_name() const { return "aes_isa"; }
diff --git a/src/engine/aes_isa_eng/info.txt b/src/engine/aes_isa_eng/info.txt
index c0695aaf3..10159f7ec 100644
--- a/src/engine/aes_isa_eng/info.txt
+++ b/src/engine/aes_isa_eng/info.txt
@@ -1,3 +1,11 @@
define ENGINE_AES_ISA
load_on dep
+
+<source>
+aes_isa_engine.cpp
+</source>
+
+<header:internal>
+aes_isa_engine.h
+</header:internal>
diff --git a/src/engine/amd64_eng/eng_amd64.cpp b/src/engine/amd64_eng/amd64_engine.cpp
index eed2cf303..6de1484fb 100644
--- a/src/engine/amd64_eng/eng_amd64.cpp
+++ b/src/engine/amd64_eng/amd64_engine.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_amd64.h>
+#include <botan/internal/amd64_engine.h>
#if defined(BOTAN_HAS_SHA1_AMD64)
#include <botan/sha1_amd64.h>
diff --git a/src/engine/amd64_eng/eng_amd64.h b/src/engine/amd64_eng/amd64_engine.h
index 528291fed..dc6f3e993 100644
--- a/src/engine/amd64_eng/eng_amd64.h
+++ b/src/engine/amd64_eng/amd64_engine.h
@@ -12,7 +12,7 @@
namespace Botan {
-class BOTAN_DLL AMD64_Assembler_Engine : public Engine
+class AMD64_Assembler_Engine : public Engine
{
public:
std::string provider_name() const { return "amd64"; }
diff --git a/src/engine/amd64_eng/info.txt b/src/engine/amd64_eng/info.txt
index 2ae2aaad0..089abd7ad 100644
--- a/src/engine/amd64_eng/info.txt
+++ b/src/engine/amd64_eng/info.txt
@@ -1,3 +1,11 @@
define ENGINE_AMD64_ASSEMBLER
load_on dep
+
+<header:internal>
+amd64_engine.h
+</header:internal>
+
+<source>
+amd64_engine.cpp
+</source>
diff --git a/src/engine/def_engine/def_mode.cpp b/src/engine/def_engine/def_mode.cpp
index b7373ef84..233385eda 100644
--- a/src/engine/def_engine/def_mode.cpp
+++ b/src/engine/def_engine/def_mode.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/def_eng.h>
+#include <botan/internal/default_engine.h>
#include <botan/parsing.h>
#include <botan/filters.h>
#include <botan/algo_factory.h>
diff --git a/src/engine/def_engine/def_pk_ops.cpp b/src/engine/def_engine/def_pk_ops.cpp
index 31dce7a74..3ac608819 100644
--- a/src/engine/def_engine/def_pk_ops.cpp
+++ b/src/engine/def_engine/def_pk_ops.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/def_eng.h>
+#include <botan/internal/default_engine.h>
#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY)
#include <botan/if_op.h>
diff --git a/src/engine/def_engine/def_powm.cpp b/src/engine/def_engine/def_powm.cpp
index 9e7a88a1a..9767e51ef 100644
--- a/src/engine/def_engine/def_powm.cpp
+++ b/src/engine/def_engine/def_powm.cpp
@@ -5,8 +5,8 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/def_eng.h>
-#include <botan/def_powm.h>
+#include <botan/internal/default_engine.h>
+#include <botan/internal/def_powm.h>
namespace Botan {
diff --git a/src/engine/def_engine/def_eng.h b/src/engine/def_engine/default_engine.h
index ba5bee8ef..6846d3497 100644
--- a/src/engine/def_engine/def_eng.h
+++ b/src/engine/def_engine/default_engine.h
@@ -15,7 +15,7 @@ namespace Botan {
/*
* Default Engine
*/
-class BOTAN_DLL Default_Engine : public Engine
+class Default_Engine : public Engine
{
public:
std::string provider_name() const { return "core"; }
diff --git a/src/engine/def_engine/info.txt b/src/engine/def_engine/info.txt
index 74b4d3f9b..faa591696 100644
--- a/src/engine/def_engine/info.txt
+++ b/src/engine/def_engine/info.txt
@@ -1,8 +1,8 @@
define DEFAULT_ENGINE
-<header:public>
-def_eng.h
-</header:public>
+<header:internal>
+default_engine.h
+</header:internal>
<source>
def_mode.cpp
diff --git a/src/engine/def_engine/lookup_block.cpp b/src/engine/def_engine/lookup_block.cpp
index 7ee5f5810..cdad76c46 100644
--- a/src/engine/def_engine/lookup_block.cpp
+++ b/src/engine/def_engine/lookup_block.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/def_eng.h>
+#include <botan/internal/default_engine.h>
#include <botan/scan_name.h>
#include <botan/algo_factory.h>
diff --git a/src/engine/def_engine/lookup_hash.cpp b/src/engine/def_engine/lookup_hash.cpp
index 9b2018736..4ce7915d4 100644
--- a/src/engine/def_engine/lookup_hash.cpp
+++ b/src/engine/def_engine/lookup_hash.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/def_eng.h>
+#include <botan/internal/default_engine.h>
#include <botan/scan_name.h>
#include <botan/algo_factory.h>
#include <memory>
diff --git a/src/engine/def_engine/lookup_mac.cpp b/src/engine/def_engine/lookup_mac.cpp
index 3fef12b59..adeec881b 100644
--- a/src/engine/def_engine/lookup_mac.cpp
+++ b/src/engine/def_engine/lookup_mac.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/def_eng.h>
+#include <botan/internal/default_engine.h>
#include <botan/scan_name.h>
#include <botan/algo_factory.h>
diff --git a/src/engine/def_engine/lookup_stream.cpp b/src/engine/def_engine/lookup_stream.cpp
index e2f1b32b8..0ec9620e6 100644
--- a/src/engine/def_engine/lookup_stream.cpp
+++ b/src/engine/def_engine/lookup_stream.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/def_eng.h>
+#include <botan/internal/default_engine.h>
#include <botan/scan_name.h>
#if defined(BOTAN_HAS_ARC4)
diff --git a/src/engine/gnump/gmp_dh.cpp b/src/engine/gnump/gmp_dh.cpp
index b33240268..430530dd3 100644
--- a/src/engine/gnump/gmp_dh.cpp
+++ b/src/engine/gnump/gmp_dh.cpp
@@ -5,8 +5,8 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_gmp.h>
-#include <botan/gmp_wrap.h>
+#include <botan/internal/gnump_engine.h>
+#include <botan/internal/gmp_wrap.h>
#include <gmp.h>
namespace Botan {
diff --git a/src/engine/gnump/gmp_dsa.cpp b/src/engine/gnump/gmp_dsa.cpp
index 69a9c3e9c..b350a2075 100644
--- a/src/engine/gnump/gmp_dsa.cpp
+++ b/src/engine/gnump/gmp_dsa.cpp
@@ -5,8 +5,8 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_gmp.h>
-#include <botan/gmp_wrap.h>
+#include <botan/internal/gnump_engine.h>
+#include <botan/internal/gmp_wrap.h>
#include <gmp.h>
namespace Botan {
diff --git a/src/engine/gnump/gmp_elg.cpp b/src/engine/gnump/gmp_elg.cpp
index ee109f1d6..539804a23 100644
--- a/src/engine/gnump/gmp_elg.cpp
+++ b/src/engine/gnump/gmp_elg.cpp
@@ -5,8 +5,8 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_gmp.h>
-#include <botan/gmp_wrap.h>
+#include <botan/internal/gnump_engine.h>
+#include <botan/internal/gmp_wrap.h>
#include <gmp.h>
namespace Botan {
diff --git a/src/engine/gnump/gmp_if.cpp b/src/engine/gnump/gmp_if.cpp
index b96f2ddac..64fbe386a 100644
--- a/src/engine/gnump/gmp_if.cpp
+++ b/src/engine/gnump/gmp_if.cpp
@@ -5,8 +5,8 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_gmp.h>
-#include <botan/gmp_wrap.h>
+#include <botan/internal/gnump_engine.h>
+#include <botan/internal/gmp_wrap.h>
#include <gmp.h>
namespace Botan {
diff --git a/src/engine/gnump/gmp_mem.cpp b/src/engine/gnump/gmp_mem.cpp
index 89a1ed2d4..59e0cc4c5 100644
--- a/src/engine/gnump/gmp_mem.cpp
+++ b/src/engine/gnump/gmp_mem.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_gmp.h>
+#include <botan/internal/gnump_engine.h>
#include <cstring>
#include <gmp.h>
diff --git a/src/engine/gnump/gmp_nr.cpp b/src/engine/gnump/gmp_nr.cpp
index 4aeb09fe2..7d6fe536d 100644
--- a/src/engine/gnump/gmp_nr.cpp
+++ b/src/engine/gnump/gmp_nr.cpp
@@ -5,8 +5,8 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_gmp.h>
-#include <botan/gmp_wrap.h>
+#include <botan/internal/gnump_engine.h>
+#include <botan/internal/gmp_wrap.h>
#include <gmp.h>
namespace Botan {
diff --git a/src/engine/gnump/gmp_powm.cpp b/src/engine/gnump/gmp_powm.cpp
index 687aed88a..70c2b2f5e 100644
--- a/src/engine/gnump/gmp_powm.cpp
+++ b/src/engine/gnump/gmp_powm.cpp
@@ -5,8 +5,8 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_gmp.h>
-#include <botan/gmp_wrap.h>
+#include <botan/internal/gnump_engine.h>
+#include <botan/internal/gmp_wrap.h>
namespace Botan {
diff --git a/src/engine/gnump/gmp_wrap.cpp b/src/engine/gnump/gmp_wrap.cpp
index 735fc7070..39d107a78 100644
--- a/src/engine/gnump/gmp_wrap.cpp
+++ b/src/engine/gnump/gmp_wrap.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/gmp_wrap.h>
+#include <botan/internal/gmp_wrap.h>
#define GNU_MP_VERSION_CODE_FOR(a,b,c) ((a << 16) | (b << 8) | (c))
diff --git a/src/engine/gnump/gmp_wrap.h b/src/engine/gnump/gmp_wrap.h
index 11a51c87d..f8d9cf365 100644
--- a/src/engine/gnump/gmp_wrap.h
+++ b/src/engine/gnump/gmp_wrap.h
@@ -16,7 +16,7 @@ namespace Botan {
/*
* Lightweight GMP mpz_t Wrapper
*/
-class BOTAN_DLL GMP_MPZ
+class GMP_MPZ
{
public:
mpz_t value;
diff --git a/src/engine/gnump/eng_gmp.h b/src/engine/gnump/gnump_engine.h
index 6a52b7e51..ec4a7e721 100644
--- a/src/engine/gnump/eng_gmp.h
+++ b/src/engine/gnump/gnump_engine.h
@@ -15,7 +15,7 @@ namespace Botan {
/*
* GMP Engine
*/
-class BOTAN_DLL GMP_Engine : public Engine
+class GMP_Engine : public Engine
{
public:
std::string provider_name() const { return "gmp"; }
diff --git a/src/engine/gnump/info.txt b/src/engine/gnump/info.txt
index 9566bded2..bd5c15f7f 100644
--- a/src/engine/gnump/info.txt
+++ b/src/engine/gnump/info.txt
@@ -6,11 +6,8 @@ load_on request
all -> gmp
</libs>
-<header:public>
-eng_gmp.h
-</header:public>
-
<header:internal>
+gnump_engine.h
gmp_wrap.h
</header:internal>
diff --git a/src/engine/ia32_eng/eng_ia32.cpp b/src/engine/ia32_eng/ia32_engine.cpp
index 6ff2a4be4..eb7795888 100644
--- a/src/engine/ia32_eng/eng_ia32.cpp
+++ b/src/engine/ia32_eng/ia32_engine.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_ia32.h>
+#include <botan/internal/ia32_engine.h>
#if defined(BOTAN_HAS_SERPENT_IA32)
#include <botan/serp_ia32.h>
diff --git a/src/engine/ia32_eng/eng_ia32.h b/src/engine/ia32_eng/ia32_engine.h
index b7cb4824a..517b88aa8 100644
--- a/src/engine/ia32_eng/eng_ia32.h
+++ b/src/engine/ia32_eng/ia32_engine.h
@@ -12,7 +12,7 @@
namespace Botan {
-class BOTAN_DLL IA32_Assembler_Engine : public Engine
+class IA32_Assembler_Engine : public Engine
{
public:
std::string provider_name() const { return "ia32"; }
diff --git a/src/engine/ia32_eng/info.txt b/src/engine/ia32_eng/info.txt
index d2106c555..258c64d1d 100644
--- a/src/engine/ia32_eng/info.txt
+++ b/src/engine/ia32_eng/info.txt
@@ -1,3 +1,11 @@
define ENGINE_IA32_ASSEMBLER
load_on dep
+
+<source>
+ia32_engine.cpp
+</source>
+
+<header:internal>
+ia32_engine.h
+</header:internal>
diff --git a/src/engine/openssl/arc4_openssl.cpp b/src/engine/openssl/arc4_openssl.cpp
index 793e1faff..d76bce349 100644
--- a/src/engine/openssl/arc4_openssl.cpp
+++ b/src/engine/openssl/arc4_openssl.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_ossl.h>
+#include <botan/internal/openssl_engine.h>
#include <botan/parsing.h>
#include <openssl/rc4.h>
diff --git a/src/engine/openssl/bn_powm.cpp b/src/engine/openssl/bn_powm.cpp
index 7b836d170..abf4f47c9 100644
--- a/src/engine/openssl/bn_powm.cpp
+++ b/src/engine/openssl/bn_powm.cpp
@@ -5,8 +5,8 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_ossl.h>
-#include <botan/bn_wrap.h>
+#include <botan/internal/openssl_engine.h>
+#include <botan/internal/bn_wrap.h>
namespace Botan {
diff --git a/src/engine/openssl/bn_wrap.cpp b/src/engine/openssl/bn_wrap.cpp
index e1cfe3f95..6f1b5ef25 100644
--- a/src/engine/openssl/bn_wrap.cpp
+++ b/src/engine/openssl/bn_wrap.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/bn_wrap.h>
+#include <botan/internal/bn_wrap.h>
namespace Botan {
diff --git a/src/engine/openssl/bn_wrap.h b/src/engine/openssl/bn_wrap.h
index 4d18be1b5..0307189a9 100644
--- a/src/engine/openssl/bn_wrap.h
+++ b/src/engine/openssl/bn_wrap.h
@@ -16,7 +16,7 @@ namespace Botan {
/*
* Lightweight OpenSSL BN Wrapper
*/
-class BOTAN_DLL OSSL_BN
+class OSSL_BN
{
public:
BIGNUM* value;
@@ -36,7 +36,7 @@ class BOTAN_DLL OSSL_BN
/*
* Lightweight OpenSSL BN_CTX Wrapper
*/
-class BOTAN_DLL OSSL_BN_CTX
+class OSSL_BN_CTX
{
public:
BN_CTX* value;
diff --git a/src/engine/openssl/info.txt b/src/engine/openssl/info.txt
index d30e76293..c65f80a29 100644
--- a/src/engine/openssl/info.txt
+++ b/src/engine/openssl/info.txt
@@ -6,11 +6,8 @@ load_on request
all -> crypto
</libs>
-<header:public>
-eng_ossl.h
-</header:public>
-
<header:internal>
+openssl_engine.h
bn_wrap.h
</header:internal>
diff --git a/src/engine/openssl/eng_ossl.h b/src/engine/openssl/openssl_engine.h
index 7105546dd..4ee2be2c0 100644
--- a/src/engine/openssl/eng_ossl.h
+++ b/src/engine/openssl/openssl_engine.h
@@ -15,7 +15,7 @@ namespace Botan {
/*
* OpenSSL Engine
*/
-class BOTAN_DLL OpenSSL_Engine : public Engine
+class OpenSSL_Engine : public Engine
{
public:
/**
diff --git a/src/engine/openssl/ossl_bc.cpp b/src/engine/openssl/ossl_bc.cpp
index 7fdf54e42..98a5b6963 100644
--- a/src/engine/openssl/ossl_bc.cpp
+++ b/src/engine/openssl/ossl_bc.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_ossl.h>
+#include <botan/internal/openssl_engine.h>
#include <openssl/evp.h>
namespace Botan {
diff --git a/src/engine/openssl/ossl_dh.cpp b/src/engine/openssl/ossl_dh.cpp
index 72eab8a48..7cbe6477d 100644
--- a/src/engine/openssl/ossl_dh.cpp
+++ b/src/engine/openssl/ossl_dh.cpp
@@ -5,8 +5,8 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_ossl.h>
-#include <botan/bn_wrap.h>
+#include <botan/internal/openssl_engine.h>
+#include <botan/internal/bn_wrap.h>
#include <openssl/opensslv.h>
#if OPENSSL_VERSION_NUMBER < 0x0090700F
diff --git a/src/engine/openssl/ossl_dsa.cpp b/src/engine/openssl/ossl_dsa.cpp
index bfffb8796..66529bcec 100644
--- a/src/engine/openssl/ossl_dsa.cpp
+++ b/src/engine/openssl/ossl_dsa.cpp
@@ -5,8 +5,8 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_ossl.h>
-#include <botan/bn_wrap.h>
+#include <botan/internal/openssl_engine.h>
+#include <botan/internal/bn_wrap.h>
#include <openssl/opensslv.h>
#if OPENSSL_VERSION_NUMBER < 0x0090700F
diff --git a/src/engine/openssl/ossl_elg.cpp b/src/engine/openssl/ossl_elg.cpp
index aefda9a1e..35c59a7ff 100644
--- a/src/engine/openssl/ossl_elg.cpp
+++ b/src/engine/openssl/ossl_elg.cpp
@@ -5,8 +5,8 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_ossl.h>
-#include <botan/bn_wrap.h>
+#include <botan/internal/openssl_engine.h>
+#include <botan/internal/bn_wrap.h>
#include <openssl/opensslv.h>
#if OPENSSL_VERSION_NUMBER < 0x0090700F
diff --git a/src/engine/openssl/ossl_if.cpp b/src/engine/openssl/ossl_if.cpp
index bbc10d549..a30a4d8b4 100644
--- a/src/engine/openssl/ossl_if.cpp
+++ b/src/engine/openssl/ossl_if.cpp
@@ -5,8 +5,8 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_ossl.h>
-#include <botan/bn_wrap.h>
+#include <botan/internal/openssl_engine.h>
+#include <botan/internal/bn_wrap.h>
#include <openssl/opensslv.h>
#if OPENSSL_VERSION_NUMBER < 0x0090700F
diff --git a/src/engine/openssl/ossl_md.cpp b/src/engine/openssl/ossl_md.cpp
index 1e01a6f25..f41e0f950 100644
--- a/src/engine/openssl/ossl_md.cpp
+++ b/src/engine/openssl/ossl_md.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_ossl.h>
+#include <botan/internal/openssl_engine.h>
#include <openssl/evp.h>
namespace Botan {
diff --git a/src/engine/openssl/ossl_nr.cpp b/src/engine/openssl/ossl_nr.cpp
index 532e4b8be..b14ec7f8c 100644
--- a/src/engine/openssl/ossl_nr.cpp
+++ b/src/engine/openssl/ossl_nr.cpp
@@ -5,8 +5,8 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/eng_ossl.h>
-#include <botan/bn_wrap.h>
+#include <botan/internal/openssl_engine.h>
+#include <botan/internal/bn_wrap.h>
#include <openssl/opensslv.h>
#if OPENSSL_VERSION_NUMBER < 0x0090700F
diff --git a/src/engine/simd_engine/info.txt b/src/engine/simd_engine/info.txt
index b0523285f..cddb7524a 100644
--- a/src/engine/simd_engine/info.txt
+++ b/src/engine/simd_engine/info.txt
@@ -1,3 +1,11 @@
define ENGINE_SIMD
load_on dep
+
+<source>
+simd_engine.cpp
+</source>
+
+<header:internal>
+simd_engine.h
+</header:internal>
diff --git a/src/engine/simd_engine/simd_engine.cpp b/src/engine/simd_engine/simd_engine.cpp
index 60ff8ba1d..b8ebd6a80 100644
--- a/src/engine/simd_engine/simd_engine.cpp
+++ b/src/engine/simd_engine/simd_engine.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/simd_engine.h>
+#include <botan/internal/simd_engine.h>
#include <botan/internal/simd_32.h>
#include <botan/cpuid.h>
@@ -17,6 +17,10 @@
#include <botan/xtea_simd.h>
#endif
+#if defined(BOTAN_HAS_IDEA_SSE2)
+ #include <botan/idea_sse2.h>
+#endif
+
#if defined(BOTAN_HAS_SHA1_SSE2)
#include <botan/sha1_sse2.h>
#endif
@@ -27,16 +31,18 @@ BlockCipher*
SIMD_Engine::find_block_cipher(const SCAN_Name& request,
Algorithm_Factory&) const
{
- if(!SIMD_32::enabled())
- return 0;
+#if defined(BOTAN_HAS_IDEA_SSE2)
+ if(request.algo_name() == "IDEA" && CPUID::has_sse2())
+ return new IDEA_SSE2;
+#endif
#if defined(BOTAN_HAS_SERPENT_SIMD)
- if(request.algo_name() == "Serpent")
+ if(request.algo_name() == "Serpent" && SIMD_32::enabled())
return new Serpent_SIMD;
#endif
#if defined(BOTAN_HAS_XTEA_SIMD)
- if(request.algo_name() == "XTEA")
+ if(request.algo_name() == "XTEA" && SIMD_32::enabled())
return new XTEA_SIMD;
#endif
diff --git a/src/engine/simd_engine/simd_engine.h b/src/engine/simd_engine/simd_engine.h
index 22a58e203..722b5529b 100644
--- a/src/engine/simd_engine/simd_engine.h
+++ b/src/engine/simd_engine/simd_engine.h
@@ -12,7 +12,7 @@
namespace Botan {
-class BOTAN_DLL SIMD_Engine : public Engine
+class SIMD_Engine : public Engine
{
public:
std::string provider_name() const { return "simd"; }
diff --git a/src/entropy/beos_stats/es_beos.cpp b/src/entropy/beos_stats/es_beos.cpp
index 18eca5511..148d38b9b 100644
--- a/src/entropy/beos_stats/es_beos.cpp
+++ b/src/entropy/beos_stats/es_beos.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/es_beos.h>
+#include <botan/internal/es_beos.h>
#include <kernel/OS.h>
#include <kernel/image.h>
diff --git a/src/entropy/cryptoapi_rng/es_capi.cpp b/src/entropy/cryptoapi_rng/es_capi.cpp
index a70b52044..367166c62 100644
--- a/src/entropy/cryptoapi_rng/es_capi.cpp
+++ b/src/entropy/cryptoapi_rng/es_capi.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/es_capi.h>
+#include <botan/internal/es_capi.h>
#include <botan/parsing.h>
#include <windows.h>
#include <wincrypt.h>
diff --git a/src/entropy/entropy_src.h b/src/entropy/entropy_src.h
index be1a16636..4d01bce7c 100644
--- a/src/entropy/entropy_src.h
+++ b/src/entropy/entropy_src.h
@@ -17,7 +17,7 @@ namespace Botan {
/**
* Class used to accumulate the poll results of EntropySources
*/
-class Entropy_Accumulator
+class BOTAN_DLL Entropy_Accumulator
{
public:
Entropy_Accumulator(u32bit goal) :
@@ -63,7 +63,7 @@ class Entropy_Accumulator
double collected_bits;
};
-class Entropy_Accumulator_BufferedComputation : public Entropy_Accumulator
+class BOTAN_DLL Entropy_Accumulator_BufferedComputation : public Entropy_Accumulator
{
public:
Entropy_Accumulator_BufferedComputation(BufferedComputation& sink,
diff --git a/src/entropy/hres_timer/hres_timer.cpp b/src/entropy/hres_timer/hres_timer.cpp
index 73282d8d2..d06ca7a9d 100644
--- a/src/entropy/hres_timer/hres_timer.cpp
+++ b/src/entropy/hres_timer/hres_timer.cpp
@@ -27,7 +27,7 @@ void High_Resolution_Timestamp::poll(Entropy_Accumulator& accum)
accum.add(tv.QuadPart, 0);
#endif
-#if defined(BOTAN_USE_GCC_INLINE_ASM)
+#if BOTAN_USE_GCC_INLINE_ASM
u64bit rtc = 0;
diff --git a/src/entropy/win32_stats/es_win32.cpp b/src/entropy/win32_stats/es_win32.cpp
index a8e9e40f5..e9f564fee 100644
--- a/src/entropy/win32_stats/es_win32.cpp
+++ b/src/entropy/win32_stats/es_win32.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/es_win32.h>
+#include <botan/internal/es_win32.h>
#include <windows.h>
#include <tlhelp32.h>
diff --git a/src/filters/basefilt.h b/src/filters/basefilt.h
index b1bcb1a00..81e897bc4 100644
--- a/src/filters/basefilt.h
+++ b/src/filters/basefilt.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* BitBucket is a filter which simply discards all inputs
*/
-struct BitBucket : public Filter
+struct BOTAN_DLL BitBucket : public Filter
{
void write(const byte[], u32bit) {}
};
diff --git a/src/filters/fd_unix/fd_unix.h b/src/filters/fd_unix/fd_unix.h
index 0aed0092c..0ff220e50 100644
--- a/src/filters/fd_unix/fd_unix.h
+++ b/src/filters/fd_unix/fd_unix.h
@@ -15,8 +15,8 @@ namespace Botan {
/*
* Unix I/O Operators for Pipe
*/
-int operator<<(int, Pipe&);
-int operator>>(int, Pipe&);
+int BOTAN_DLL operator<<(int, Pipe&);
+int BOTAN_DLL operator>>(int, Pipe&);
}
diff --git a/src/filters/modes/cbc/cbc.cpp b/src/filters/modes/cbc/cbc.cpp
index a52f4b2e1..48ecdf509 100644
--- a/src/filters/modes/cbc/cbc.cpp
+++ b/src/filters/modes/cbc/cbc.cpp
@@ -16,11 +16,14 @@ namespace Botan {
*/
CBC_Encryption::CBC_Encryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad) :
- BlockCipherMode(ciph, "CBC", ciph->BLOCK_SIZE),
- padder(pad)
+ cipher(ciph), padder(pad)
{
- if(!padder->valid_blocksize(BLOCK_SIZE))
+ if(!padder->valid_blocksize(cipher->BLOCK_SIZE))
throw Invalid_Block_Size(name(), padder->name());
+
+ buffer.resize(cipher->BLOCK_SIZE);
+ state.resize(cipher->BLOCK_SIZE);
+ position = 0;
}
/*
@@ -30,31 +33,48 @@ CBC_Encryption::CBC_Encryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad,
const SymmetricKey& key,
const InitializationVector& iv) :
- BlockCipherMode(ciph, "CBC", ciph->BLOCK_SIZE),
- padder(pad)
+ cipher(ciph), padder(pad)
{
- if(!padder->valid_blocksize(BLOCK_SIZE))
+ if(!padder->valid_blocksize(cipher->BLOCK_SIZE))
throw Invalid_Block_Size(name(), padder->name());
+
+ buffer.resize(cipher->BLOCK_SIZE);
+ state.resize(cipher->BLOCK_SIZE);
+ position = 0;
+
set_key(key);
set_iv(iv);
}
/*
+* Set the IV
+*/
+void CBC_Encryption::set_iv(const InitializationVector& iv)
+ {
+ if(iv.length() != state.size())
+ throw Invalid_IV_Length(name(), iv.length());
+
+ state = iv.bits_of();
+ buffer.clear();
+ position = 0;
+ }
+
+/*
* Encrypt in CBC mode
*/
void CBC_Encryption::write(const byte input[], u32bit length)
{
while(length)
{
- u32bit xored = std::min(BLOCK_SIZE - position, length);
+ u32bit xored = std::min(cipher->BLOCK_SIZE - position, length);
xor_buf(state + position, input, xored);
input += xored;
length -= xored;
position += xored;
- if(position == BLOCK_SIZE)
+ if(position == cipher->BLOCK_SIZE)
{
cipher->encrypt(state);
- send(state, BLOCK_SIZE);
+ send(state, cipher->BLOCK_SIZE);
position = 0;
}
}
@@ -65,9 +85,9 @@ void CBC_Encryption::write(const byte input[], u32bit length)
*/
void CBC_Encryption::end_msg()
{
- SecureVector<byte> padding(BLOCK_SIZE);
+ SecureVector<byte> padding(cipher->BLOCK_SIZE);
padder->pad(padding, padding.size(), position);
- write(padding, padder->pad_bytes(BLOCK_SIZE, position));
+ write(padding, padder->pad_bytes(cipher->BLOCK_SIZE, position));
if(position != 0)
throw Exception(name() + ": Did not pad to full blocksize");
}
@@ -77,7 +97,7 @@ void CBC_Encryption::end_msg()
*/
std::string CBC_Encryption::name() const
{
- return (cipher->name() + "/" + mode_name + "/" + padder->name());
+ return (cipher->name() + "/CBC/" + padder->name());
}
/*
@@ -85,12 +105,15 @@ std::string CBC_Encryption::name() const
*/
CBC_Decryption::CBC_Decryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad) :
- BlockCipherMode(ciph, "CBC", ciph->BLOCK_SIZE),
- padder(pad)
+ cipher(ciph), padder(pad)
{
- if(!padder->valid_blocksize(BLOCK_SIZE))
+ if(!padder->valid_blocksize(cipher->BLOCK_SIZE))
throw Invalid_Block_Size(name(), padder->name());
- temp.resize(BLOCK_SIZE);
+
+ buffer.resize(cipher->BLOCK_SIZE);
+ state.resize(cipher->BLOCK_SIZE);
+ temp.resize(cipher->BLOCK_SIZE);
+ position = 0;
}
/*
@@ -100,32 +123,50 @@ CBC_Decryption::CBC_Decryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad,
const SymmetricKey& key,
const InitializationVector& iv) :
- BlockCipherMode(ciph, "CBC", ciph->BLOCK_SIZE),
- padder(pad)
+ cipher(ciph), padder(pad)
{
- if(!padder->valid_blocksize(BLOCK_SIZE))
+ if(!padder->valid_blocksize(cipher->BLOCK_SIZE))
throw Invalid_Block_Size(name(), padder->name());
- temp.resize(BLOCK_SIZE);
+
+ buffer.resize(cipher->BLOCK_SIZE);
+ state.resize(cipher->BLOCK_SIZE);
+ temp.resize(cipher->BLOCK_SIZE);
+ position = 0;
+
set_key(key);
set_iv(iv);
}
/*
+* Set the IV
+*/
+void CBC_Decryption::set_iv(const InitializationVector& iv)
+ {
+ if(iv.length() != state.size())
+ throw Invalid_IV_Length(name(), iv.length());
+
+ state = iv.bits_of();
+ buffer.clear();
+ position = 0;
+ }
+
+/*
* Decrypt in CBC mode
*/
void CBC_Decryption::write(const byte input[], u32bit length)
{
while(length)
{
- if(position == BLOCK_SIZE)
+ if(position == cipher->BLOCK_SIZE)
{
cipher->decrypt(buffer, temp);
- xor_buf(temp, state, BLOCK_SIZE);
- send(temp, BLOCK_SIZE);
+ xor_buf(temp, state, cipher->BLOCK_SIZE);
+ send(temp, cipher->BLOCK_SIZE);
state = buffer;
position = 0;
}
- u32bit added = std::min(BLOCK_SIZE - position, length);
+
+ u32bit added = std::min(cipher->BLOCK_SIZE - position, length);
buffer.copy(position, input, added);
input += added;
length -= added;
@@ -138,11 +179,11 @@ void CBC_Decryption::write(const byte input[], u32bit length)
*/
void CBC_Decryption::end_msg()
{
- if(position != BLOCK_SIZE)
+ if(position != cipher->BLOCK_SIZE)
throw Decoding_Error(name());
cipher->decrypt(buffer, temp);
- xor_buf(temp, state, BLOCK_SIZE);
- send(temp, padder->unpad(temp, BLOCK_SIZE));
+ xor_buf(temp, state, cipher->BLOCK_SIZE);
+ send(temp, padder->unpad(temp, cipher->BLOCK_SIZE));
state = buffer;
position = 0;
}
@@ -152,7 +193,7 @@ void CBC_Decryption::end_msg()
*/
std::string CBC_Decryption::name() const
{
- return (cipher->name() + "/" + mode_name + "/" + padder->name());
+ return (cipher->name() + "/CBC/" + padder->name());
}
}
diff --git a/src/filters/modes/cbc/cbc.h b/src/filters/modes/cbc/cbc.h
index a926ac180..91ab21ab6 100644
--- a/src/filters/modes/cbc/cbc.h
+++ b/src/filters/modes/cbc/cbc.h
@@ -8,7 +8,8 @@
#ifndef BOTAN_CBC_H__
#define BOTAN_CBC_H__
-#include <botan/modebase.h>
+#include <botan/block_cipher.h>
+#include <botan/key_filt.h>
#include <botan/mode_pad.h>
namespace Botan {
@@ -16,38 +17,69 @@ namespace Botan {
/*
* CBC Encryption
*/
-class BOTAN_DLL CBC_Encryption : public BlockCipherMode
+class BOTAN_DLL CBC_Encryption : public Keyed_Filter
{
public:
- CBC_Encryption(BlockCipher*, BlockCipherModePaddingMethod*);
- CBC_Encryption(BlockCipher*, BlockCipherModePaddingMethod*,
- const SymmetricKey&, const InitializationVector&);
+ std::string name() const;
+
+ void set_iv(const InitializationVector&);
+
+ void set_key(const SymmetricKey& key) { cipher->set_key(key); }
+
+ bool valid_keylength(u32bit key_len) const
+ { return cipher->valid_keylength(key_len); }
+
+ CBC_Encryption(BlockCipher* cipher,
+ BlockCipherModePaddingMethod* padding);
+
+ CBC_Encryption(BlockCipher* cipher,
+ BlockCipherModePaddingMethod* padding,
+ const SymmetricKey& key,
+ const InitializationVector& iv);
~CBC_Encryption() { delete padder; }
private:
- std::string name() const;
void write(const byte[], u32bit);
void end_msg();
+
+ BlockCipher* cipher;
const BlockCipherModePaddingMethod* padder;
+ SecureVector<byte> buffer, state;
+ u32bit position;
};
/*
* CBC Decryption
*/
-class BOTAN_DLL CBC_Decryption : public BlockCipherMode
+class BOTAN_DLL CBC_Decryption : public Keyed_Filter
{
public:
- CBC_Decryption(BlockCipher*, BlockCipherModePaddingMethod*);
- CBC_Decryption(BlockCipher*, BlockCipherModePaddingMethod*,
- const SymmetricKey&, const InitializationVector&);
+ std::string name() const;
+
+ void set_iv(const InitializationVector&);
+
+ void set_key(const SymmetricKey& key) { cipher->set_key(key); }
+
+ bool valid_keylength(u32bit key_len) const
+ { return cipher->valid_keylength(key_len); }
+
+ CBC_Decryption(BlockCipher* cipher,
+ BlockCipherModePaddingMethod* padding);
+
+ CBC_Decryption(BlockCipher* cipher,
+ BlockCipherModePaddingMethod* padding,
+ const SymmetricKey& key,
+ const InitializationVector& iv);
~CBC_Decryption() { delete padder; }
private:
- std::string name() const;
void write(const byte[], u32bit);
void end_msg();
+
+ BlockCipher* cipher;
const BlockCipherModePaddingMethod* padder;
- SecureVector<byte> temp;
+ SecureVector<byte> buffer, state, temp;
+ u32bit position;
};
}
diff --git a/src/filters/modes/cbc/info.txt b/src/filters/modes/cbc/info.txt
index 92a39d674..229edfbf7 100644
--- a/src/filters/modes/cbc/info.txt
+++ b/src/filters/modes/cbc/info.txt
@@ -1,5 +1,6 @@
define CBC
<requires>
+block
mode_pad
</requires>
diff --git a/src/filters/modes/cfb/cfb.cpp b/src/filters/modes/cfb/cfb.cpp
index 777673d6f..778d47484 100644
--- a/src/filters/modes/cfb/cfb.cpp
+++ b/src/filters/modes/cfb/cfb.cpp
@@ -12,30 +12,21 @@
namespace Botan {
-namespace {
-
/*
-* Check the feedback size
+* CFB Encryption Constructor
*/
-void check_feedback(u32bit BLOCK_SIZE, u32bit FEEDBACK_SIZE, u32bit bits,
- const std::string& name)
+CFB_Encryption::CFB_Encryption(BlockCipher* ciph, u32bit fback_bits)
{
- if(FEEDBACK_SIZE == 0 || FEEDBACK_SIZE > BLOCK_SIZE || bits % 8 != 0)
- throw Invalid_Argument(name + ": Invalid feedback size " +
- to_string(bits));
- }
+ cipher = ciph;
+ feedback = fback_bits ? fback_bits / 8: cipher->BLOCK_SIZE;
-}
+ buffer.resize(cipher->BLOCK_SIZE);
+ state.resize(cipher->BLOCK_SIZE);
+ position = 0;
-/*
-* CFB Encryption Constructor
-*/
-CFB_Encryption::CFB_Encryption(BlockCipher* ciph,
- u32bit fback_bits) :
- BlockCipherMode(ciph, "CFB", ciph->BLOCK_SIZE, 1),
- FEEDBACK_SIZE(fback_bits ? fback_bits / 8: BLOCK_SIZE)
- {
- check_feedback(BLOCK_SIZE, FEEDBACK_SIZE, fback_bits, name());
+ if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->BLOCK_SIZE)
+ throw Invalid_Argument("CFB_Encryption: Invalid feedback size " +
+ to_string(fback_bits));
}
/*
@@ -44,15 +35,35 @@ CFB_Encryption::CFB_Encryption(BlockCipher* ciph,
CFB_Encryption::CFB_Encryption(BlockCipher* ciph,
const SymmetricKey& key,
const InitializationVector& iv,
- u32bit fback_bits) :
- BlockCipherMode(ciph, "CFB", ciph->BLOCK_SIZE, 1),
- FEEDBACK_SIZE(fback_bits ? fback_bits / 8: BLOCK_SIZE)
+ u32bit fback_bits)
{
- check_feedback(BLOCK_SIZE, FEEDBACK_SIZE, fback_bits, name());
+ cipher = ciph;
+ feedback = fback_bits ? fback_bits / 8: cipher->BLOCK_SIZE;
+
+ buffer.resize(cipher->BLOCK_SIZE);
+ state.resize(cipher->BLOCK_SIZE);
+ position = 0;
+
+ if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->BLOCK_SIZE)
+ throw Invalid_Argument("CFB_Encryption: Invalid feedback size " +
+ to_string(fback_bits));
+
set_key(key);
set_iv(iv);
}
+void CFB_Encryption::set_iv(const InitializationVector& iv)
+ {
+ if(iv.length() != state.size())
+ throw Invalid_IV_Length(name(), iv.length());
+
+ state = iv.bits_of();
+ buffer.clear();
+ position = 0;
+
+ cipher->encrypt(state, buffer);
+ }
+
/*
* Encrypt data in CFB mode
*/
@@ -60,38 +71,39 @@ void CFB_Encryption::write(const byte input[], u32bit length)
{
while(length)
{
- u32bit xored = std::min(FEEDBACK_SIZE - position, length);
+ u32bit xored = std::min(feedback - position, length);
xor_buf(buffer + position, input, xored);
send(buffer + position, xored);
input += xored;
length -= xored;
position += xored;
- if(position == FEEDBACK_SIZE)
- feedback();
+
+ if(position == feedback)
+ {
+ for(u32bit j = 0; j != cipher->BLOCK_SIZE - feedback; ++j)
+ state[j] = state[j + feedback];
+ state.copy(cipher->BLOCK_SIZE - feedback, buffer, feedback);
+ cipher->encrypt(state, buffer);
+ position = 0;
+ }
}
}
/*
-* Do the feedback
+* CFB Decryption Constructor
*/
-void CFB_Encryption::feedback()
+CFB_Decryption::CFB_Decryption(BlockCipher* ciph, u32bit fback_bits)
{
- for(u32bit j = 0; j != BLOCK_SIZE - FEEDBACK_SIZE; ++j)
- state[j] = state[j + FEEDBACK_SIZE];
- state.copy(BLOCK_SIZE - FEEDBACK_SIZE, buffer, FEEDBACK_SIZE);
- cipher->encrypt(state, buffer);
+ cipher = ciph;
+ feedback = fback_bits ? fback_bits / 8: cipher->BLOCK_SIZE;
+
+ buffer.resize(cipher->BLOCK_SIZE);
+ state.resize(cipher->BLOCK_SIZE);
position = 0;
- }
-/*
-* CFB Decryption Constructor
-*/
-CFB_Decryption::CFB_Decryption(BlockCipher* ciph,
- u32bit fback_bits) :
- BlockCipherMode(ciph, "CFB", ciph->BLOCK_SIZE, 1),
- FEEDBACK_SIZE(fback_bits ? fback_bits / 8 : BLOCK_SIZE)
- {
- check_feedback(BLOCK_SIZE, FEEDBACK_SIZE, fback_bits, name());
+ if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->BLOCK_SIZE)
+ throw Invalid_Argument("CFB_Decryption: Invalid feedback size " +
+ to_string(fback_bits));
}
/*
@@ -100,15 +112,35 @@ CFB_Decryption::CFB_Decryption(BlockCipher* ciph,
CFB_Decryption::CFB_Decryption(BlockCipher* ciph,
const SymmetricKey& key,
const InitializationVector& iv,
- u32bit fback_bits) :
- BlockCipherMode(ciph, "CFB", ciph->BLOCK_SIZE, 1),
- FEEDBACK_SIZE(fback_bits ? fback_bits / 8 : BLOCK_SIZE)
+ u32bit fback_bits)
{
- check_feedback(BLOCK_SIZE, FEEDBACK_SIZE, fback_bits, name());
+ cipher = ciph;
+ feedback = fback_bits ? fback_bits / 8: cipher->BLOCK_SIZE;
+
+ buffer.resize(cipher->BLOCK_SIZE);
+ state.resize(cipher->BLOCK_SIZE);
+ position = 0;
+
+ if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->BLOCK_SIZE)
+ throw Invalid_Argument("CFB_Decryption: Invalid feedback size " +
+ to_string(fback_bits));
+
set_key(key);
set_iv(iv);
}
+void CFB_Decryption::set_iv(const InitializationVector& iv)
+ {
+ if(iv.length() != state.size())
+ throw Invalid_IV_Length(name(), iv.length());
+
+ state = iv.bits_of();
+ buffer.clear();
+ position = 0;
+
+ cipher->encrypt(state, buffer);
+ }
+
/*
* Decrypt data in CFB mode
*/
@@ -116,28 +148,22 @@ void CFB_Decryption::write(const byte input[], u32bit length)
{
while(length)
{
- u32bit xored = std::min(FEEDBACK_SIZE - position, length);
+ u32bit xored = std::min(feedback - position, length);
xor_buf(buffer + position, input, xored);
send(buffer + position, xored);
buffer.copy(position, input, xored);
input += xored;
length -= xored;
position += xored;
- if(position == FEEDBACK_SIZE)
- feedback();
+ if(position == feedback)
+ {
+ for(u32bit j = 0; j != cipher->BLOCK_SIZE - feedback; ++j)
+ state[j] = state[j + feedback];
+ state.copy(cipher->BLOCK_SIZE - feedback, buffer, feedback);
+ cipher->encrypt(state, buffer);
+ position = 0;
+ }
}
}
-/*
-* Do the feedback
-*/
-void CFB_Decryption::feedback()
- {
- for(u32bit j = 0; j != BLOCK_SIZE - FEEDBACK_SIZE; ++j)
- state[j] = state[j + FEEDBACK_SIZE];
- state.copy(BLOCK_SIZE - FEEDBACK_SIZE, buffer, FEEDBACK_SIZE);
- cipher->encrypt(state, buffer);
- position = 0;
- }
-
}
diff --git a/src/filters/modes/cfb/cfb.h b/src/filters/modes/cfb/cfb.h
index 7810c00e4..917125e46 100644
--- a/src/filters/modes/cfb/cfb.h
+++ b/src/filters/modes/cfb/cfb.h
@@ -8,38 +8,67 @@
#ifndef BOTAN_CFB_H__
#define BOTAN_CFB_H__
-#include <botan/modebase.h>
+#include <botan/block_cipher.h>
+#include <botan/key_filt.h>
namespace Botan {
/*
* CFB Encryption
*/
-class BOTAN_DLL CFB_Encryption : public BlockCipherMode
+class BOTAN_DLL CFB_Encryption : public Keyed_Filter
{
public:
- CFB_Encryption(BlockCipher*, u32bit = 0);
- CFB_Encryption(BlockCipher*, const SymmetricKey&,
- const InitializationVector&, u32bit = 0);
+ std::string name() const { return cipher->name() + "/CFB"; }
+
+ void set_iv(const InitializationVector&);
+
+ void set_key(const SymmetricKey& key) { cipher->set_key(key); }
+
+ bool valid_keylength(u32bit key_len) const
+ { return cipher->valid_keylength(key_len); }
+
+ CFB_Encryption(BlockCipher* cipher, u32bit feedback = 0);
+
+ CFB_Encryption(BlockCipher* cipher,
+ const SymmetricKey& key,
+ const InitializationVector& iv,
+ u32bit feedback = 0);
private:
void write(const byte[], u32bit);
- void feedback();
- const u32bit FEEDBACK_SIZE;
+
+ BlockCipher* cipher;
+ SecureVector<byte> buffer, state;
+ u32bit position, feedback;
};
/*
* CFB Decryption
*/
-class BOTAN_DLL CFB_Decryption : public BlockCipherMode
+class BOTAN_DLL CFB_Decryption : public Keyed_Filter
{
public:
- CFB_Decryption(BlockCipher*, u32bit = 0);
- CFB_Decryption(BlockCipher*, const SymmetricKey&,
- const InitializationVector&, u32bit = 0);
+ std::string name() const { return cipher->name() + "/CFB"; }
+
+ void set_iv(const InitializationVector&);
+
+ void set_key(const SymmetricKey& key) { cipher->set_key(key); }
+
+ bool valid_keylength(u32bit key_len) const
+ { return cipher->valid_keylength(key_len); }
+
+ CFB_Decryption(BlockCipher* cipher, u32bit feedback = 0);
+
+ CFB_Decryption(BlockCipher* cipher,
+ const SymmetricKey& key,
+ const InitializationVector& iv,
+ u32bit feedback = 0);
private:
void write(const byte[], u32bit);
- void feedback();
- const u32bit FEEDBACK_SIZE;
+
+ BlockCipher* cipher;
+ SecureVector<byte> buffer, state;
+ u32bit position, feedback;
};
}
diff --git a/src/filters/modes/cfb/info.txt b/src/filters/modes/cfb/info.txt
index 230899a03..eb2cc69ba 100644
--- a/src/filters/modes/cfb/info.txt
+++ b/src/filters/modes/cfb/info.txt
@@ -1 +1,5 @@
define CFB
+
+<requires>
+block
+</requires>
diff --git a/src/filters/modes/cts/cts.cpp b/src/filters/modes/cts/cts.cpp
index 226a31898..3a15a1d68 100644
--- a/src/filters/modes/cts/cts.cpp
+++ b/src/filters/modes/cts/cts.cpp
@@ -12,13 +12,53 @@
namespace Botan {
/*
+* CTS Encryption Constructor
+*/
+CTS_Encryption::CTS_Encryption(BlockCipher* ciph) :
+ cipher(ciph)
+ {
+ buffer.resize(2 * cipher->BLOCK_SIZE);
+ state.resize(cipher->BLOCK_SIZE);
+ position = 0;
+ }
+
+/*
+* CTS Encryption Constructor
+*/
+CTS_Encryption::CTS_Encryption(BlockCipher* ciph,
+ const SymmetricKey& key,
+ const InitializationVector& iv) :
+ cipher(ciph)
+ {
+ buffer.resize(2 * cipher->BLOCK_SIZE);
+ state.resize(cipher->BLOCK_SIZE);
+ position = 0;
+
+ set_key(key);
+ set_iv(iv);
+ }
+
+/*
+* Set the IV
+*/
+void CTS_Encryption::set_iv(const InitializationVector& iv)
+ {
+ if(iv.length() != state.size())
+ throw Invalid_IV_Length(name(), iv.length());
+
+ state = iv.bits_of();
+ buffer.clear();
+ position = 0;
+ }
+
+/*
* Encrypt a block
*/
void CTS_Encryption::encrypt(const byte block[])
{
- xor_buf(state, block, BLOCK_SIZE);
+ xor_buf(state, block, cipher->BLOCK_SIZE);
cipher->encrypt(state);
- send(state, BLOCK_SIZE);
+ send(state, cipher->BLOCK_SIZE);
}
/*
@@ -26,7 +66,7 @@ void CTS_Encryption::encrypt(const byte block[])
*/
void CTS_Encryption::write(const byte input[], u32bit length)
{
- u32bit copied = std::min(BUFFER_SIZE - position, length);
+ u32bit copied = std::min(buffer.size() - position, length);
buffer.copy(position, input, copied);
length -= copied;
input += copied;
@@ -35,21 +75,21 @@ void CTS_Encryption::write(const byte input[], u32bit length)
if(length == 0) return;
encrypt(buffer);
- if(length > BLOCK_SIZE)
+ if(length > cipher->BLOCK_SIZE)
{
- encrypt(buffer + BLOCK_SIZE);
- while(length > 2*BLOCK_SIZE)
+ encrypt(buffer + cipher->BLOCK_SIZE);
+ while(length > 2*cipher->BLOCK_SIZE)
{
encrypt(input);
- length -= BLOCK_SIZE;
- input += BLOCK_SIZE;
+ length -= cipher->BLOCK_SIZE;
+ input += cipher->BLOCK_SIZE;
}
position = 0;
}
else
{
- copy_mem(buffer.begin(), buffer + BLOCK_SIZE, BLOCK_SIZE);
- position = BLOCK_SIZE;
+ copy_mem(buffer.begin(), buffer + cipher->BLOCK_SIZE, cipher->BLOCK_SIZE);
+ position = cipher->BLOCK_SIZE;
}
buffer.copy(position, input, length);
position += length;
@@ -60,14 +100,56 @@ void CTS_Encryption::write(const byte input[], u32bit length)
*/
void CTS_Encryption::end_msg()
{
- if(position < BLOCK_SIZE + 1)
+ if(position < cipher->BLOCK_SIZE + 1)
throw Exception("CTS_Encryption: insufficient data to encrypt");
- xor_buf(state, buffer, BLOCK_SIZE);
+ xor_buf(state, buffer, cipher->BLOCK_SIZE);
cipher->encrypt(state);
SecureVector<byte> cn = state;
- clear_mem(buffer + position, BUFFER_SIZE - position);
- encrypt(buffer + BLOCK_SIZE);
- send(cn, position - BLOCK_SIZE);
+ clear_mem(buffer + position, buffer.size() - position);
+ encrypt(buffer + cipher->BLOCK_SIZE);
+ send(cn, position - cipher->BLOCK_SIZE);
+ }
+
+/*
+* CTS Decryption Constructor
+*/
+CTS_Decryption::CTS_Decryption(BlockCipher* ciph) :
+ cipher(ciph)
+ {
+ buffer.resize(2 * cipher->BLOCK_SIZE);
+ state.resize(cipher->BLOCK_SIZE);
+ temp.resize(cipher->BLOCK_SIZE);
+ position = 0;
+ }
+
+/*
+* CTS Decryption Constructor
+*/
+CTS_Decryption::CTS_Decryption(BlockCipher* ciph,
+ const SymmetricKey& key,
+ const InitializationVector& iv) :
+ cipher(ciph)
+ {
+ buffer.resize(2 * cipher->BLOCK_SIZE);
+ state.resize(cipher->BLOCK_SIZE);
+ temp.resize(cipher->BLOCK_SIZE);
+ position = 0;
+
+ set_key(key);
+ set_iv(iv);
+ }
+
+/*
+* Set the IV
+*/
+void CTS_Decryption::set_iv(const InitializationVector& iv)
+ {
+ if(iv.length() != state.size())
+ throw Invalid_IV_Length(name(), iv.length());
+
+ state = iv.bits_of();
+ buffer.clear();
+ position = 0;
}
/*
@@ -76,9 +158,9 @@ void CTS_Encryption::end_msg()
void CTS_Decryption::decrypt(const byte block[])
{
cipher->decrypt(block, temp);
- xor_buf(temp, state, BLOCK_SIZE);
- send(temp, BLOCK_SIZE);
- state.copy(block, BLOCK_SIZE);
+ xor_buf(temp, state, cipher->BLOCK_SIZE);
+ send(temp, cipher->BLOCK_SIZE);
+ state.copy(block, cipher->BLOCK_SIZE);
}
/*
@@ -86,7 +168,7 @@ void CTS_Decryption::decrypt(const byte block[])
*/
void CTS_Decryption::write(const byte input[], u32bit length)
{
- u32bit copied = std::min(BUFFER_SIZE - position, length);
+ u32bit copied = std::min(buffer.size() - position, length);
buffer.copy(position, input, copied);
length -= copied;
input += copied;
@@ -95,21 +177,21 @@ void CTS_Decryption::write(const byte input[], u32bit length)
if(length == 0) return;
decrypt(buffer);
- if(length > BLOCK_SIZE)
+ if(length > cipher->BLOCK_SIZE)
{
- decrypt(buffer + BLOCK_SIZE);
- while(length > 2*BLOCK_SIZE)
+ decrypt(buffer + cipher->BLOCK_SIZE);
+ while(length > 2*cipher->BLOCK_SIZE)
{
decrypt(input);
- length -= BLOCK_SIZE;
- input += BLOCK_SIZE;
+ length -= cipher->BLOCK_SIZE;
+ input += cipher->BLOCK_SIZE;
}
position = 0;
}
else
{
- copy_mem(buffer.begin(), buffer + BLOCK_SIZE, BLOCK_SIZE);
- position = BLOCK_SIZE;
+ copy_mem(buffer.begin(), buffer + cipher->BLOCK_SIZE, cipher->BLOCK_SIZE);
+ position = cipher->BLOCK_SIZE;
}
buffer.copy(position, input, length);
position += length;
@@ -121,14 +203,14 @@ void CTS_Decryption::write(const byte input[], u32bit length)
void CTS_Decryption::end_msg()
{
cipher->decrypt(buffer, temp);
- xor_buf(temp, buffer + BLOCK_SIZE, position - BLOCK_SIZE);
+ xor_buf(temp, buffer + cipher->BLOCK_SIZE, position - cipher->BLOCK_SIZE);
SecureVector<byte> xn = temp;
- copy_mem(buffer + position, xn + (position - BLOCK_SIZE),
- BUFFER_SIZE - position);
- cipher->decrypt(buffer + BLOCK_SIZE, temp);
- xor_buf(temp, state, BLOCK_SIZE);
- send(temp, BLOCK_SIZE);
- send(xn, position - BLOCK_SIZE);
+ copy_mem(buffer + position, xn + (position - cipher->BLOCK_SIZE),
+ buffer.size() - position);
+ cipher->decrypt(buffer + cipher->BLOCK_SIZE, temp);
+ xor_buf(temp, state, cipher->BLOCK_SIZE);
+ send(temp, cipher->BLOCK_SIZE);
+ send(xn, position - cipher->BLOCK_SIZE);
}
}
diff --git a/src/filters/modes/cts/cts.h b/src/filters/modes/cts/cts.h
index 1a2cae44e..4a7513fa0 100644
--- a/src/filters/modes/cts/cts.h
+++ b/src/filters/modes/cts/cts.h
@@ -8,51 +8,69 @@
#ifndef BOTAN_CTS_H__
#define BOTAN_CTS_H__
-#include <botan/modebase.h>
#include <botan/block_cipher.h>
+#include <botan/key_filt.h>
namespace Botan {
/*
* CTS Encryption
*/
-class BOTAN_DLL CTS_Encryption : public BlockCipherMode
+class BOTAN_DLL CTS_Encryption : public Keyed_Filter
{
public:
- CTS_Encryption(BlockCipher* ciph) :
- BlockCipherMode(ciph, "CTS", ciph->BLOCK_SIZE, 0, 2) {}
+ std::string name() const { return cipher->name() + "/CTS"; }
- CTS_Encryption(BlockCipher* ciph,
+ void set_iv(const InitializationVector&);
+
+ void set_key(const SymmetricKey& key) { cipher->set_key(key); }
+
+ bool valid_keylength(u32bit key_len) const
+ { return cipher->valid_keylength(key_len); }
+
+ CTS_Encryption(BlockCipher* cipher);
+
+ CTS_Encryption(BlockCipher* cipher,
const SymmetricKey& key,
- const InitializationVector& iv) :
- BlockCipherMode(ciph, "CTS", ciph->BLOCK_SIZE, 0, 2)
- { set_key(key); set_iv(iv); }
+ const InitializationVector& iv);
private:
void write(const byte[], u32bit);
void end_msg();
void encrypt(const byte[]);
+
+ BlockCipher* cipher;
+ SecureVector<byte> buffer, state;
+ u32bit position;
};
/*
* CTS Decryption
*/
-class BOTAN_DLL CTS_Decryption : public BlockCipherMode
+class BOTAN_DLL CTS_Decryption : public Keyed_Filter
{
public:
- CTS_Decryption(BlockCipher* ciph) :
- BlockCipherMode(ciph, "CTS", ciph->BLOCK_SIZE, 0, 2)
- { temp.resize(BLOCK_SIZE); }
+ std::string name() const { return cipher->name() + "/CTS"; }
- CTS_Decryption(BlockCipher* ciph,
+ void set_iv(const InitializationVector&);
+
+ void set_key(const SymmetricKey& key) { cipher->set_key(key); }
+
+ bool valid_keylength(u32bit key_len) const
+ { return cipher->valid_keylength(key_len); }
+
+ CTS_Decryption(BlockCipher* cipher);
+
+ CTS_Decryption(BlockCipher* cipher,
const SymmetricKey& key,
- const InitializationVector& iv) :
- BlockCipherMode(ciph, "CTS", ciph->BLOCK_SIZE, 0, 2)
- { set_key(key); set_iv(iv); temp.resize(BLOCK_SIZE); }
+ const InitializationVector& iv);
private:
void write(const byte[], u32bit);
void end_msg();
void decrypt(const byte[]);
- SecureVector<byte> temp;
+
+ BlockCipher* cipher;
+ SecureVector<byte> buffer, state, temp;
+ u32bit position;
};
}
diff --git a/src/filters/modes/cts/info.txt b/src/filters/modes/cts/info.txt
index 237f8cd97..7b590c5cb 100644
--- a/src/filters/modes/cts/info.txt
+++ b/src/filters/modes/cts/info.txt
@@ -1 +1,5 @@
define CTS
+
+<requires>
+block
+</requires>
diff --git a/src/filters/modes/eax/eax.cpp b/src/filters/modes/eax/eax.cpp
index 7893ce258..2cb700daa 100644
--- a/src/filters/modes/eax/eax.cpp
+++ b/src/filters/modes/eax/eax.cpp
@@ -7,8 +7,9 @@
#include <botan/eax.h>
#include <botan/cmac.h>
-#include <botan/internal/xor_buf.h>
+#include <botan/ctr.h>
#include <botan/parsing.h>
+#include <botan/internal/xor_buf.h>
#include <algorithm>
namespace Botan {
@@ -34,20 +35,17 @@ SecureVector<byte> eax_prf(byte tag, u32bit BLOCK_SIZE,
/*
* EAX_Base Constructor
*/
-EAX_Base::EAX_Base(BlockCipher* ciph,
- u32bit tag_size) :
- TAG_SIZE(tag_size ? tag_size / 8 : ciph->BLOCK_SIZE),
- BLOCK_SIZE(ciph->BLOCK_SIZE)
+EAX_Base::EAX_Base(BlockCipher* cipher, u32bit tag_size) :
+ BLOCK_SIZE(cipher->BLOCK_SIZE),
+ TAG_SIZE(tag_size ? tag_size / 8 : BLOCK_SIZE),
+ cipher_name(cipher->name()),
+ ctr_buf(DEFAULT_BUFFERSIZE)
{
- cipher = ciph;
- mac = new CMAC(cipher->clone());
+ cmac = new CMAC(cipher->clone());
+ ctr = new CTR_BE(cipher); // takes ownership
- if(tag_size % 8 != 0 || TAG_SIZE == 0 || TAG_SIZE > mac->OUTPUT_LENGTH)
+ if(tag_size % 8 != 0 || TAG_SIZE == 0 || TAG_SIZE > cmac->OUTPUT_LENGTH)
throw Invalid_Argument(name() + ": Bad tag size " + to_string(tag_size));
-
- state.resize(BLOCK_SIZE);
- buffer.resize(BLOCK_SIZE);
- position = 0;
}
/*
@@ -55,9 +53,7 @@ EAX_Base::EAX_Base(BlockCipher* ciph,
*/
bool EAX_Base::valid_keylength(u32bit n) const
{
- if(!cipher->valid_keylength(n))
- return false;
- if(!mac->valid_keylength(n))
+ if(!ctr->valid_keylength(n))
return false;
return true;
}
@@ -67,9 +63,14 @@ bool EAX_Base::valid_keylength(u32bit n) const
*/
void EAX_Base::set_key(const SymmetricKey& key)
{
- cipher->set_key(key);
- mac->set_key(key);
- header_mac = eax_prf(1, BLOCK_SIZE, mac, 0, 0);
+ /*
+ * These could share the key schedule, which is one nice part of EAX,
+ * but it's much easier to ignore that here...
+ */
+ ctr->set_key(key);
+ cmac->set_key(key);
+
+ header_mac = eax_prf(1, BLOCK_SIZE, cmac, 0, 0);
}
/*
@@ -78,8 +79,8 @@ void EAX_Base::set_key(const SymmetricKey& key)
void EAX_Base::start_msg()
{
for(u32bit j = 0; j != BLOCK_SIZE - 1; ++j)
- mac->update(0);
- mac->update(2);
+ cmac->update(0);
+ cmac->update(2);
}
/*
@@ -87,9 +88,8 @@ void EAX_Base::start_msg()
*/
void EAX_Base::set_iv(const InitializationVector& iv)
{
- nonce_mac = eax_prf(0, BLOCK_SIZE, mac, iv.begin(), iv.length());
- state = nonce_mac;
- cipher->encrypt(state, buffer);
+ nonce_mac = eax_prf(0, BLOCK_SIZE, cmac, iv.begin(), iv.length());
+ ctr->set_iv(&nonce_mac[0], nonce_mac.size());
}
/*
@@ -97,7 +97,7 @@ void EAX_Base::set_iv(const InitializationVector& iv)
*/
void EAX_Base::set_header(const byte header[], u32bit length)
{
- header_mac = eax_prf(1, BLOCK_SIZE, mac, header, length);
+ header_mac = eax_prf(1, BLOCK_SIZE, cmac, header, length);
}
/*
@@ -105,19 +105,7 @@ void EAX_Base::set_header(const byte header[], u32bit length)
*/
std::string EAX_Base::name() const
{
- return (cipher->name() + "/EAX");
- }
-
-/*
-* Increment the counter and update the buffer
-*/
-void EAX_Base::increment_counter()
- {
- for(s32bit j = BLOCK_SIZE - 1; j >= 0; --j)
- if(++state[j])
- break;
- cipher->encrypt(state, buffer);
- position = 0;
+ return (cipher_name + "/EAX");
}
/*
@@ -125,32 +113,17 @@ void EAX_Base::increment_counter()
*/
void EAX_Encryption::write(const byte input[], u32bit length)
{
- u32bit copied = std::min(BLOCK_SIZE - position, length);
- xor_buf(buffer + position, input, copied);
- send(buffer + position, copied);
- mac->update(buffer + position, copied);
- input += copied;
- length -= copied;
- position += copied;
-
- if(position == BLOCK_SIZE)
- increment_counter();
-
- while(length >= BLOCK_SIZE)
+ while(length)
{
- xor_buf(buffer, input, BLOCK_SIZE);
- send(buffer, BLOCK_SIZE);
- mac->update(buffer, BLOCK_SIZE);
+ u32bit copied = std::min(length, ctr_buf.size());
- input += BLOCK_SIZE;
- length -= BLOCK_SIZE;
- increment_counter();
- }
+ ctr->cipher(input, ctr_buf, copied);
+ cmac->update(ctr_buf, copied);
- xor_buf(buffer + position, input, length);
- send(buffer + position, length);
- mac->update(buffer + position, length);
- position += length;
+ send(ctr_buf, copied);
+ input += copied;
+ length -= copied;
+ }
}
/*
@@ -158,15 +131,11 @@ void EAX_Encryption::write(const byte input[], u32bit length)
*/
void EAX_Encryption::end_msg()
{
- SecureVector<byte> data_mac = mac->final();
+ SecureVector<byte> data_mac = cmac->final();
xor_buf(data_mac, nonce_mac, data_mac.size());
xor_buf(data_mac, header_mac, data_mac.size());
send(data_mac, TAG_SIZE);
-
- state.clear();
- buffer.clear();
- position = 0;
}
}
diff --git a/src/filters/modes/eax/eax.h b/src/filters/modes/eax/eax.h
index f569f2ede..e45e29ba8 100644
--- a/src/filters/modes/eax/eax.h
+++ b/src/filters/modes/eax/eax.h
@@ -10,6 +10,7 @@
#include <botan/key_filt.h>
#include <botan/block_cipher.h>
+#include <botan/stream_cipher.h>
#include <botan/mac.h>
namespace Botan {
@@ -27,17 +28,19 @@ class BOTAN_DLL EAX_Base : public Keyed_Filter
bool valid_keylength(u32bit) const;
- ~EAX_Base() { delete cipher; delete mac; }
+ ~EAX_Base() { delete ctr; delete cmac; }
protected:
EAX_Base(BlockCipher*, u32bit);
void start_msg();
- void increment_counter();
- const u32bit TAG_SIZE, BLOCK_SIZE;
- BlockCipher* cipher;
- MessageAuthenticationCode* mac;
- SecureVector<byte> nonce_mac, header_mac, state, buffer;
- u32bit position;
+ const u32bit BLOCK_SIZE, TAG_SIZE;
+ std::string cipher_name;
+
+ StreamCipher* ctr;
+ MessageAuthenticationCode* cmac;
+
+ SecureVector<byte> nonce_mac, header_mac;
+ SecureVector<byte> ctr_buf;
};
/*
@@ -76,6 +79,7 @@ class BOTAN_DLL EAX_Decryption : public EAX_Base
void write(const byte[], u32bit);
void do_write(const byte[], u32bit);
void end_msg();
+
SecureVector<byte> queue;
u32bit queue_start, queue_end;
};
diff --git a/src/filters/modes/eax/eax_dec.cpp b/src/filters/modes/eax/eax_dec.cpp
index 24b68f3b7..f41327ffc 100644
--- a/src/filters/modes/eax/eax_dec.cpp
+++ b/src/filters/modes/eax/eax_dec.cpp
@@ -52,7 +52,6 @@ void EAX_Decryption::write(const byte input[], u32bit length)
length -= copied;
queue_end += copied;
- SecureVector<byte> block_buf(cipher->BLOCK_SIZE);
while((queue_end - queue_start) > TAG_SIZE)
{
u32bit removed = (queue_end - queue_start) - TAG_SIZE;
@@ -77,31 +76,20 @@ void EAX_Decryption::write(const byte input[], u32bit length)
*/
void EAX_Decryption::do_write(const byte input[], u32bit length)
{
- mac->update(input, length);
-
- u32bit copied = std::min(BLOCK_SIZE - position, length);
- xor_buf(buffer + position, input, copied);
- send(buffer + position, copied);
- input += copied;
- length -= copied;
- position += copied;
-
- if(position == BLOCK_SIZE)
- increment_counter();
-
- while(length >= BLOCK_SIZE)
+ while(length)
{
- xor_buf(buffer, input, BLOCK_SIZE);
- send(buffer, BLOCK_SIZE);
-
- input += BLOCK_SIZE;
- length -= BLOCK_SIZE;
- increment_counter();
+ u32bit copied = std::min(length, ctr_buf.size());
+
+ /*
+ Process same block with cmac and ctr at the same time to
+ help cache locality.
+ */
+ cmac->update(input, copied);
+ ctr->cipher(input, ctr_buf, copied);
+ send(ctr_buf, copied);
+ input += copied;
+ length -= copied;
}
-
- xor_buf(buffer + position, input, length);
- send(buffer + position, length);
- position += length;
}
/*
@@ -112,15 +100,12 @@ void EAX_Decryption::end_msg()
if((queue_end - queue_start) != TAG_SIZE)
throw Integrity_Failure(name() + ": Message authentication failure");
- SecureVector<byte> data_mac = mac->final();
+ SecureVector<byte> data_mac = cmac->final();
for(u32bit j = 0; j != TAG_SIZE; ++j)
if(queue[queue_start+j] != (data_mac[j] ^ nonce_mac[j] ^ header_mac[j]))
throw Integrity_Failure(name() + ": Message authentication failure");
- state.clear();
- buffer.clear();
- position = 0;
queue_start = queue_end = 0;
}
diff --git a/src/filters/modes/eax/info.txt b/src/filters/modes/eax/info.txt
index 4c91318d6..09d92e724 100644
--- a/src/filters/modes/eax/info.txt
+++ b/src/filters/modes/eax/info.txt
@@ -1,5 +1,7 @@
define EAX
<requires>
+block
cmac
+ctr
</requires>
diff --git a/src/filters/modes/ecb/ecb.h b/src/filters/modes/ecb/ecb.h
index ff9ea9635..2b3b3fe83 100644
--- a/src/filters/modes/ecb/ecb.h
+++ b/src/filters/modes/ecb/ecb.h
@@ -8,11 +8,9 @@
#ifndef BOTAN_ECB_H__
#define BOTAN_ECB_H__
-#include <botan/basefilt.h>
#include <botan/block_cipher.h>
#include <botan/mode_pad.h>
-
-#include <botan/modebase.h>
+#include <botan/key_filt.h>
namespace Botan {
diff --git a/src/filters/modes/ecb/info.txt b/src/filters/modes/ecb/info.txt
index a26930470..38a56040c 100644
--- a/src/filters/modes/ecb/info.txt
+++ b/src/filters/modes/ecb/info.txt
@@ -1,5 +1,6 @@
define ECB
<requires>
+block
mode_pad
</requires>
diff --git a/src/filters/modes/info.txt b/src/filters/modes/info.txt
deleted file mode 100644
index 6d27c9709..000000000
--- a/src/filters/modes/info.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-define CIPHER_MODEBASE
-
-<requires>
-block
-filters
-</requires>
diff --git a/src/filters/modes/mode_pad/mode_pad.cpp b/src/filters/modes/mode_pad/mode_pad.cpp
index 2204c28b5..94f84fa03 100644
--- a/src/filters/modes/mode_pad/mode_pad.cpp
+++ b/src/filters/modes/mode_pad/mode_pad.cpp
@@ -120,8 +120,7 @@ u32bit OneAndZeros_Padding::unpad(const byte block[], u32bit size) const
*/
bool OneAndZeros_Padding::valid_blocksize(u32bit size) const
{
- if(size) return true;
- else return false;
+ return (size > 0);
}
}
diff --git a/src/filters/modes/modebase.cpp b/src/filters/modes/modebase.cpp
deleted file mode 100644
index 59ee55a8a..000000000
--- a/src/filters/modes/modebase.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
-* Block Cipher Mode
-* (C) 1999-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include <botan/modebase.h>
-
-namespace Botan {
-
-/*
-* Block Cipher Mode Constructor
-*/
-BlockCipherMode::BlockCipherMode(BlockCipher* cipher_ptr,
- const std::string& cipher_mode_name,
- u32bit iv_size, u32bit iv_meth,
- u32bit buf_mult) :
- BLOCK_SIZE(cipher_ptr->BLOCK_SIZE), BUFFER_SIZE(buf_mult * BLOCK_SIZE),
- IV_METHOD(iv_meth), mode_name(cipher_mode_name)
- {
- cipher = cipher_ptr;
- buffer.resize(BUFFER_SIZE);
- state.resize(iv_size);
- position = 0;
- }
-
-/*
-* Return the name of this type
-*/
-std::string BlockCipherMode::name() const
- {
- return (cipher->name() + "/" + mode_name);
- }
-
-/*
-* Set the IV
-*/
-void BlockCipherMode::set_iv(const InitializationVector& new_iv)
- {
- if(new_iv.length() != state.size())
- throw Invalid_IV_Length(name(), new_iv.length());
-
- state = new_iv.bits_of();
- buffer.clear();
- position = 0;
-
- if(IV_METHOD == 1)
- cipher->encrypt(state, buffer);
- else if(IV_METHOD == 2)
- cipher->encrypt(state);
- }
-
-}
diff --git a/src/filters/modes/modebase.h b/src/filters/modes/modebase.h
deleted file mode 100644
index 4a15524b6..000000000
--- a/src/filters/modes/modebase.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
-* Block Cipher Mode
-* (C) 1999-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#ifndef BOTAN_MODEBASE_H__
-#define BOTAN_MODEBASE_H__
-
-#include <botan/key_filt.h>
-#include <botan/block_cipher.h>
-
-namespace Botan {
-
-/**
-* This class represents an abstract block cipher mode
-*/
-class BOTAN_DLL BlockCipherMode : public Keyed_Filter
- {
- public:
- std::string name() const;
-
- void set_iv(const InitializationVector&);
- void set_key(const SymmetricKey& key) { cipher->set_key(key); }
-
- bool valid_keylength(u32bit key_len) const
- { return cipher->valid_keylength(key_len); }
-
- BlockCipherMode(BlockCipher*, const std::string&,
- u32bit, u32bit = 0, u32bit = 1);
-
- virtual ~BlockCipherMode() { delete cipher; }
- protected:
- const u32bit BLOCK_SIZE, BUFFER_SIZE, IV_METHOD;
- const std::string mode_name;
- BlockCipher* cipher;
- SecureVector<byte> buffer, state;
- u32bit position;
- };
-
-}
-
-#endif
diff --git a/src/filters/modes/xts/info.txt b/src/filters/modes/xts/info.txt
index 9af3238f1..7327298f9 100644
--- a/src/filters/modes/xts/info.txt
+++ b/src/filters/modes/xts/info.txt
@@ -1 +1,5 @@
define XTS
+
+<requires>
+block
+</requires>
diff --git a/src/filters/pipe.h b/src/filters/pipe.h
index bab360c24..ba17e7e68 100644
--- a/src/filters/pipe.h
+++ b/src/filters/pipe.h
@@ -28,7 +28,7 @@ class BOTAN_DLL Pipe : public DataSource
public:
typedef u32bit message_id;
- class Invalid_Message_Number : public Invalid_Argument
+ class BOTAN_DLL Invalid_Message_Number : public Invalid_Argument
{
public:
Invalid_Message_Number(const std::string&, message_id);
diff --git a/src/hash/bmw/bmw_512.cpp b/src/hash/bmw/bmw_512.cpp
index 61c20d769..5ccb09579 100644
--- a/src/hash/bmw/bmw_512.cpp
+++ b/src/hash/bmw/bmw_512.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/bmw_512.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/hash/bmw/bmw_512.h b/src/hash/bmw/bmw_512.h
index 55cd761a9..8130a88e4 100644
--- a/src/hash/bmw/bmw_512.h
+++ b/src/hash/bmw/bmw_512.h
@@ -12,7 +12,7 @@
namespace Botan {
-class BMW_512 : public MDx_HashFunction
+class BOTAN_DLL BMW_512 : public MDx_HashFunction
{
public:
void clear();
diff --git a/src/hash/fork256/fork256.cpp b/src/hash/fork256/fork256.cpp
index 6e6e44fb8..bd85dfd7c 100644
--- a/src/hash/fork256/fork256.cpp
+++ b/src/hash/fork256/fork256.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/fork256.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/hash/gost_3411/gost_3411.cpp b/src/hash/gost_3411/gost_3411.cpp
index 6de3c9d52..01d8a0d46 100644
--- a/src/hash/gost_3411/gost_3411.cpp
+++ b/src/hash/gost_3411/gost_3411.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/gost_3411.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
#include <botan/internal/xor_buf.h>
namespace Botan {
diff --git a/src/hash/has160/has160.cpp b/src/hash/has160/has160.cpp
index 006e8f142..d245a0249 100644
--- a/src/hash/has160/has160.cpp
+++ b/src/hash/has160/has160.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/has160.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/hash/md4/md4.cpp b/src/hash/md4/md4.cpp
index 5713a17b2..f573dae25 100644
--- a/src/hash/md4/md4.cpp
+++ b/src/hash/md4/md4.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/md4.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/hash/md4_ia32/md4_ia32.cpp b/src/hash/md4_ia32/md4_ia32.cpp
index cdaffb62e..12fe71da4 100644
--- a/src/hash/md4_ia32/md4_ia32.cpp
+++ b/src/hash/md4_ia32/md4_ia32.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/md4_ia32.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/hash/md5/md5.cpp b/src/hash/md5/md5.cpp
index 4714603d3..8c1e5a8e1 100644
--- a/src/hash/md5/md5.cpp
+++ b/src/hash/md5/md5.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/md5.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/hash/md5_ia32/md5_ia32.cpp b/src/hash/md5_ia32/md5_ia32.cpp
index 5681a2763..443569b3b 100644
--- a/src/hash/md5_ia32/md5_ia32.cpp
+++ b/src/hash/md5_ia32/md5_ia32.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/md5_ia32.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/hash/mdx_hash/mdx_hash.cpp b/src/hash/mdx_hash/mdx_hash.cpp
index cc03d0319..28402c2c5 100644
--- a/src/hash/mdx_hash/mdx_hash.cpp
+++ b/src/hash/mdx_hash/mdx_hash.cpp
@@ -7,7 +7,7 @@
#include <botan/mdx_hash.h>
#include <botan/exceptn.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/hash/rmd128/rmd128.cpp b/src/hash/rmd128/rmd128.cpp
index f86addda4..51e416eb1 100644
--- a/src/hash/rmd128/rmd128.cpp
+++ b/src/hash/rmd128/rmd128.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/rmd128.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/hash/rmd160/rmd160.cpp b/src/hash/rmd160/rmd160.cpp
index e1d6a8dc5..5237f1e12 100644
--- a/src/hash/rmd160/rmd160.cpp
+++ b/src/hash/rmd160/rmd160.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/rmd160.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/hash/sha1/sha160.cpp b/src/hash/sha1/sha160.cpp
index 5666d8fa5..ff44593f6 100644
--- a/src/hash/sha1/sha160.cpp
+++ b/src/hash/sha1/sha160.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/sha160.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/hash/sha1_ia32/sha1_ia32.cpp b/src/hash/sha1_ia32/sha1_ia32.cpp
index a8f7f7b75..0fa0b6bf2 100644
--- a/src/hash/sha1_ia32/sha1_ia32.cpp
+++ b/src/hash/sha1_ia32/sha1_ia32.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/sha1_ia32.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/hash/sha1_sse2/sha1_sse2.cpp b/src/hash/sha1_sse2/sha1_sse2.cpp
index 89ad7b003..9267689e7 100644
--- a/src/hash/sha1_sse2/sha1_sse2.cpp
+++ b/src/hash/sha1_sse2/sha1_sse2.cpp
@@ -9,7 +9,7 @@
*/
#include <botan/sha1_sse2.h>
-#include <botan/internal/rotate.h>
+#include <botan/rotate.h>
#include <emmintrin.h>
namespace Botan {
diff --git a/src/hash/sha2/sha2_32.cpp b/src/hash/sha2/sha2_32.cpp
index d9d69e4a9..91375df04 100644
--- a/src/hash/sha2/sha2_32.cpp
+++ b/src/hash/sha2/sha2_32.cpp
@@ -7,8 +7,8 @@
*/
#include <botan/sha2_32.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/hash/sha2/sha2_64.cpp b/src/hash/sha2/sha2_64.cpp
index 9815a6e19..3e7c0e228 100644
--- a/src/hash/sha2/sha2_64.cpp
+++ b/src/hash/sha2/sha2_64.cpp
@@ -6,8 +6,8 @@
*/
#include <botan/sha2_64.h>
-#include <botan/internal/loadstor.h>
-#include <botan/internal/rotate.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
namespace Botan {
diff --git a/src/hash/skein/skein_512.cpp b/src/hash/skein/skein_512.cpp
index 1d683c3cf..cb4b7a7a2 100644
--- a/src/hash/skein/skein_512.cpp
+++ b/src/hash/skein/skein_512.cpp
@@ -6,9 +6,10 @@
*/
#include <botan/skein_512.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/parsing.h>
#include <botan/exceptn.h>
+#include <botan/rotate.h>
#include <algorithm>
namespace Botan {
@@ -26,11 +27,11 @@ enum type_code {
SKEIN_OUTPUT = 63
};
-void ubi_512(u64bit H[9], u64bit T[], const byte msg[], u64bit msg_len)
+void ubi_512(u64bit H[9], u64bit T[], const byte msg[], u32bit msg_len)
{
do
{
- const u64bit to_proc = std::min<u64bit>(msg_len, 64);
+ const u32bit to_proc = std::min<u32bit>(msg_len, 64);
T[0] += to_proc;
u64bit M[8] = { 0 };
diff --git a/src/hash/tiger/tiger.cpp b/src/hash/tiger/tiger.cpp
index 5a1d21847..4f4d4dc83 100644
--- a/src/hash/tiger/tiger.cpp
+++ b/src/hash/tiger/tiger.cpp
@@ -7,7 +7,7 @@
#include <botan/tiger.h>
#include <botan/exceptn.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/parsing.h>
namespace Botan {
diff --git a/src/hash/whirlpool/whrlpool.cpp b/src/hash/whirlpool/whrlpool.cpp
index c9d520776..06755fe77 100644
--- a/src/hash/whirlpool/whrlpool.cpp
+++ b/src/hash/whirlpool/whrlpool.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/whrlpool.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/kdf/kdf2/kdf2.cpp b/src/kdf/kdf2/kdf2.cpp
index f8f178c80..167f64436 100644
--- a/src/kdf/kdf2/kdf2.cpp
+++ b/src/kdf/kdf2/kdf2.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/kdf2.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/kdf/mgf1/mgf1.cpp b/src/kdf/mgf1/mgf1.cpp
index c61f583a7..a8c7e5fa3 100644
--- a/src/kdf/mgf1/mgf1.cpp
+++ b/src/kdf/mgf1/mgf1.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/mgf1.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/exceptn.h>
#include <botan/internal/xor_buf.h>
#include <algorithm>
diff --git a/src/kdf/x942_prf/prf_x942.cpp b/src/kdf/x942_prf/prf_x942.cpp
index 060fed700..d9ee09d20 100644
--- a/src/kdf/x942_prf/prf_x942.cpp
+++ b/src/kdf/x942_prf/prf_x942.cpp
@@ -9,7 +9,7 @@
#include <botan/der_enc.h>
#include <botan/oids.h>
#include <botan/sha160.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <algorithm>
#include <memory>
diff --git a/src/libstate/info.txt b/src/libstate/info.txt
index 605a5a6a0..d8e9869ac 100644
--- a/src/libstate/info.txt
+++ b/src/libstate/info.txt
@@ -8,10 +8,13 @@ libstate.h
init.h
look_pk.h
lookup.h
-pk_engine.h
scan_name.h
</header:public>
+<header:internal>
+pk_engine.h
+</header:internal>
+
<source>
get_enc.cpp
init.cpp
diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp
index 2de621648..9ac15e381 100644
--- a/src/libstate/libstate.cpp
+++ b/src/libstate/libstate.cpp
@@ -7,16 +7,19 @@
#include <botan/libstate.h>
#include <botan/charset.h>
-#include <botan/def_eng.h>
#include <botan/engine.h>
#include <botan/init.h>
-#include <botan/internal/mutex.h>
-#include <botan/selftest.h>
#include <botan/internal/defalloc.h>
+#include <botan/internal/default_engine.h>
+#include <botan/internal/mutex.h>
#include <botan/internal/mux_noop.h>
#include <botan/internal/stl_util.h>
#include <algorithm>
+#if defined(BOTAN_HAS_SELFTESTS)
+ #include <botan/selftest.h>
+#endif
+
#if defined(BOTAN_HAS_MUTEX_PTHREAD)
#include <botan/internal/mux_pthr.h>
#elif defined(BOTAN_HAS_MUTEX_WIN32)
@@ -30,27 +33,27 @@
#endif
#if defined(BOTAN_HAS_ENGINE_IA32_ASSEMBLER)
- #include <botan/eng_ia32.h>
+ #include <botan/internal/ia32_engine.h>
#endif
#if defined(BOTAN_HAS_ENGINE_AMD64_ASSEMBLER)
- #include <botan/eng_amd64.h>
+ #include <botan/internal/amd64_engine.h>
#endif
#if defined(BOTAN_HAS_ENGINE_AES_ISA)
- #include <botan/aes_isa_engine.h>
+ #include <botan/internal/aes_isa_engine.h>
#endif
#if defined(BOTAN_HAS_ENGINE_SIMD)
- #include <botan/simd_engine.h>
+ #include <botan/internal/simd_engine.h>
#endif
#if defined(BOTAN_HAS_ENGINE_GNU_MP)
- #include <botan/eng_gmp.h>
+ #include <botan/internal/gnump_engine.h>
#endif
#if defined(BOTAN_HAS_ENGINE_OPENSSL)
- #include <botan/eng_ossl.h>
+ #include <botan/internal/openssl_engine.h>
#endif
namespace Botan {
@@ -312,8 +315,10 @@ void Library_State::initialize(bool thread_safe)
m_algorithm_factory = new Algorithm_Factory(engines, *mutex_factory);
+#if defined(BOTAN_HAS_SELFTESTS)
if(!passes_self_tests(algorithm_factory()))
throw Self_Test_Failure("Startup self tests failed");
+#endif
}
/*
diff --git a/src/libstate/lookup.cpp b/src/libstate/lookup.cpp
index 3b49116f6..9016dbe6e 100644
--- a/src/libstate/lookup.cpp
+++ b/src/libstate/lookup.cpp
@@ -71,7 +71,7 @@ HashFunction* get_hash(const std::string& algo_spec)
bool have_hash(const std::string& algo_spec)
{
Algorithm_Factory& af = global_state().algorithm_factory();
- return af.prototype_hash_function(algo_spec);
+ return (af.prototype_hash_function(algo_spec) != 0);
}
/**
@@ -98,7 +98,7 @@ MessageAuthenticationCode* get_mac(const std::string& algo_spec)
bool have_mac(const std::string& algo_spec)
{
Algorithm_Factory& af = global_state().algorithm_factory();
- return af.prototype_mac(algo_spec);
+ return (af.prototype_mac(algo_spec) != 0);
}
/**
diff --git a/src/libstate/pk_engine.cpp b/src/libstate/pk_engine.cpp
index 790ddcde4..d6f4f7015 100644
--- a/src/libstate/pk_engine.cpp
+++ b/src/libstate/pk_engine.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/pk_engine.h>
+#include <botan/internal/pk_engine.h>
#include <botan/libstate.h>
#include <botan/engine.h>
diff --git a/src/math/bigint/bigint.cpp b/src/math/bigint/bigint.cpp
index a11960aca..70bb11a83 100644
--- a/src/math/bigint/bigint.cpp
+++ b/src/math/bigint/bigint.cpp
@@ -7,7 +7,7 @@
#include <botan/bigint.h>
#include <botan/internal/mp_core.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/parsing.h>
#include <botan/internal/rounding.h>
diff --git a/src/math/gfpmath/gfp_element.cpp b/src/math/gfpmath/gfp_element.cpp
index ebba236d5..233f2e4cd 100644
--- a/src/math/gfpmath/gfp_element.cpp
+++ b/src/math/gfpmath/gfp_element.cpp
@@ -8,7 +8,7 @@
#include <botan/gfp_element.h>
#include <botan/numthry.h>
-#include <botan/def_powm.h>
+#include <botan/internal/def_powm.h>
#include <botan/internal/mp_asm.h>
#include <botan/internal/mp_asmi.h>
#include <ostream>
diff --git a/src/math/numbertheory/def_powm.h b/src/math/numbertheory/def_powm.h
index 472c865c3..5b8a5a591 100644
--- a/src/math/numbertheory/def_powm.h
+++ b/src/math/numbertheory/def_powm.h
@@ -17,7 +17,7 @@ namespace Botan {
/*
* Fixed Window Exponentiator
*/
-class BOTAN_DLL Fixed_Window_Exponentiator : public Modular_Exponentiator
+class Fixed_Window_Exponentiator : public Modular_Exponentiator
{
public:
void set_exponent(const BigInt&);
@@ -39,7 +39,7 @@ class BOTAN_DLL Fixed_Window_Exponentiator : public Modular_Exponentiator
/*
* Montgomery Exponentiator
*/
-class BOTAN_DLL Montgomery_Exponentiator : public Modular_Exponentiator
+class Montgomery_Exponentiator : public Modular_Exponentiator
{
public:
void set_exponent(const BigInt&);
diff --git a/src/math/numbertheory/info.txt b/src/math/numbertheory/info.txt
index 4a3e3436b..19abfaaa0 100644
--- a/src/math/numbertheory/info.txt
+++ b/src/math/numbertheory/info.txt
@@ -4,12 +4,15 @@ define BIGINT_MATH
<header:public>
blinding.h
-def_powm.h
numthry.h
pow_mod.h
reducer.h
</header:public>
+<header:internal>
+def_powm.h
+</header:internal>
+
<source>
blinding.cpp
dsa_gen.cpp
diff --git a/src/math/numbertheory/numthry.cpp b/src/math/numbertheory/numthry.cpp
index ab51b75a3..0740ea21b 100644
--- a/src/math/numbertheory/numthry.cpp
+++ b/src/math/numbertheory/numthry.cpp
@@ -76,8 +76,6 @@ u32bit miller_rabin_test_iterations(u32bit bits, bool verify)
*/
u32bit low_zero_bits(const BigInt& n)
{
- if(n.is_negative() || n.is_zero()) return 0;
-
u32bit low_zero = 0;
if(n.is_positive() && n.is_nonzero())
diff --git a/src/math/numbertheory/numthry.h b/src/math/numbertheory/numthry.h
index e4c043799..ae2c219fc 100644
--- a/src/math/numbertheory/numthry.h
+++ b/src/math/numbertheory/numthry.h
@@ -41,7 +41,7 @@ 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);
+BigInt BOTAN_DLL ressol(const BigInt& x, const BigInt& p);
/*
* Utility Functions
diff --git a/src/math/numbertheory/pow_mod.cpp b/src/math/numbertheory/pow_mod.cpp
index fd9b8e921..8d6bac699 100644
--- a/src/math/numbertheory/pow_mod.cpp
+++ b/src/math/numbertheory/pow_mod.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/pow_mod.h>
-#include <botan/pk_engine.h>
+#include <botan/internal/pk_engine.h>
namespace Botan {
diff --git a/src/math/numbertheory/powm_fw.cpp b/src/math/numbertheory/powm_fw.cpp
index 8f39830a7..1cfcdcd66 100644
--- a/src/math/numbertheory/powm_fw.cpp
+++ b/src/math/numbertheory/powm_fw.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/def_powm.h>
+#include <botan/internal/def_powm.h>
#include <botan/numthry.h>
#include <vector>
diff --git a/src/math/numbertheory/powm_mnt.cpp b/src/math/numbertheory/powm_mnt.cpp
index d18081c6a..e356387c0 100644
--- a/src/math/numbertheory/powm_mnt.cpp
+++ b/src/math/numbertheory/powm_mnt.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/def_powm.h>
+#include <botan/internal/def_powm.h>
#include <botan/numthry.h>
#include <botan/internal/mp_core.h>
diff --git a/src/pubkey/dh/dh.cpp b/src/pubkey/dh/dh.cpp
index 149bc5882..baaa31126 100644
--- a/src/pubkey/dh/dh.cpp
+++ b/src/pubkey/dh/dh.cpp
@@ -7,7 +7,7 @@
#include <botan/dh.h>
#include <botan/numthry.h>
-#include <botan/workfactor.h>
+#include <botan/internal/workfactor.h>
namespace Botan {
diff --git a/src/pubkey/dh/dh_core.cpp b/src/pubkey/dh/dh_core.cpp
index 07d134c44..cbe2dc9f1 100644
--- a/src/pubkey/dh/dh_core.cpp
+++ b/src/pubkey/dh/dh_core.cpp
@@ -7,7 +7,7 @@
#include <botan/dh_core.h>
#include <botan/numthry.h>
-#include <botan/pk_engine.h>
+#include <botan/internal/pk_engine.h>
#include <botan/parsing.h>
#include <algorithm>
diff --git a/src/pubkey/dl_group/dl_group.cpp b/src/pubkey/dl_group/dl_group.cpp
index 13ea03016..a2e239783 100644
--- a/src/pubkey/dl_group/dl_group.cpp
+++ b/src/pubkey/dl_group/dl_group.cpp
@@ -12,8 +12,8 @@
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/pipe.h>
-#include <botan/workfactor.h>
#include <botan/pem.h>
+#include <botan/internal/workfactor.h>
namespace Botan {
diff --git a/src/pubkey/dsa/dsa_core.cpp b/src/pubkey/dsa/dsa_core.cpp
index e5a23a5c3..d952e10eb 100644
--- a/src/pubkey/dsa/dsa_core.cpp
+++ b/src/pubkey/dsa/dsa_core.cpp
@@ -7,7 +7,7 @@
#include <botan/dsa_core.h>
#include <botan/numthry.h>
-#include <botan/pk_engine.h>
+#include <botan/internal/pk_engine.h>
#include <botan/parsing.h>
#include <algorithm>
diff --git a/src/pubkey/ecdsa/ecdsa_core.cpp b/src/pubkey/ecdsa/ecdsa_core.cpp
index 0be186fb4..78b527786 100644
--- a/src/pubkey/ecdsa/ecdsa_core.cpp
+++ b/src/pubkey/ecdsa/ecdsa_core.cpp
@@ -7,7 +7,7 @@
*/
#include <botan/ecdsa_core.h>
-#include <botan/pk_engine.h>
+#include <botan/internal/pk_engine.h>
namespace Botan {
diff --git a/src/pubkey/ecdsa/ecdsa_op.cpp b/src/pubkey/ecdsa/ecdsa_op.cpp
index afa7d52bd..7bbeded73 100644
--- a/src/pubkey/ecdsa/ecdsa_op.cpp
+++ b/src/pubkey/ecdsa/ecdsa_op.cpp
@@ -9,9 +9,6 @@
#include <botan/ecdsa_op.h>
#include <botan/numthry.h>
-#include <stdio.h>
-#include <iostream>
-
namespace Botan {
Default_ECDSA_Op::Default_ECDSA_Op(const EC_Domain_Params& domain,
diff --git a/src/pubkey/eckaeg/eckaeg_core.cpp b/src/pubkey/eckaeg/eckaeg_core.cpp
index dc89a878d..eaf467933 100644
--- a/src/pubkey/eckaeg/eckaeg_core.cpp
+++ b/src/pubkey/eckaeg/eckaeg_core.cpp
@@ -8,7 +8,7 @@
#include <botan/eckaeg_core.h>
#include <botan/numthry.h>
-#include <botan/pk_engine.h>
+#include <botan/internal/pk_engine.h>
#include <botan/parsing.h>
#include <algorithm>
diff --git a/src/pubkey/elgamal/elg_core.cpp b/src/pubkey/elgamal/elg_core.cpp
index f2416d8a0..0005c4ffc 100644
--- a/src/pubkey/elgamal/elg_core.cpp
+++ b/src/pubkey/elgamal/elg_core.cpp
@@ -7,7 +7,7 @@
#include <botan/elg_core.h>
#include <botan/numthry.h>
-#include <botan/pk_engine.h>
+#include <botan/internal/pk_engine.h>
#include <botan/parsing.h>
#include <algorithm>
diff --git a/src/pubkey/elgamal/elgamal.cpp b/src/pubkey/elgamal/elgamal.cpp
index 8c07c5735..e3215f757 100644
--- a/src/pubkey/elgamal/elgamal.cpp
+++ b/src/pubkey/elgamal/elgamal.cpp
@@ -9,7 +9,7 @@
#include <botan/numthry.h>
#include <botan/keypair.h>
#include <botan/look_pk.h>
-#include <botan/workfactor.h>
+#include <botan/internal/workfactor.h>
namespace Botan {
diff --git a/src/pubkey/if_algo/if_core.cpp b/src/pubkey/if_algo/if_core.cpp
index 9c4a12ee5..41ebfe8dd 100644
--- a/src/pubkey/if_algo/if_core.cpp
+++ b/src/pubkey/if_algo/if_core.cpp
@@ -7,7 +7,7 @@
#include <botan/if_core.h>
#include <botan/numthry.h>
-#include <botan/pk_engine.h>
+#include <botan/internal/pk_engine.h>
#include <botan/parsing.h>
#include <algorithm>
diff --git a/src/pubkey/info.txt b/src/pubkey/info.txt
index 69e743351..b28bd1868 100644
--- a/src/pubkey/info.txt
+++ b/src/pubkey/info.txt
@@ -1,5 +1,24 @@
define PUBLIC_KEY_CRYPTO
+<source>
+pk_algs.cpp
+pk_keys.cpp
+pubkey.cpp
+pubkey_enums.cpp
+workfactor.cpp
+</source>
+
+<header:public>
+pk_keys.h
+pubkey.h
+pubkey_enums.h
+</header:public>
+
+<header:internal>
+pk_algs.h
+workfactor.h
+</header:internal>
+
<requires>
alloc
asn1
diff --git a/src/pubkey/nr/nr_core.cpp b/src/pubkey/nr/nr_core.cpp
index afa1115db..a87c32d60 100644
--- a/src/pubkey/nr/nr_core.cpp
+++ b/src/pubkey/nr/nr_core.cpp
@@ -7,7 +7,7 @@
#include <botan/nr_core.h>
#include <botan/numthry.h>
-#include <botan/pk_engine.h>
+#include <botan/internal/pk_engine.h>
#include <botan/parsing.h>
#include <algorithm>
diff --git a/src/pubkey/pk_algs.cpp b/src/pubkey/pk_algs.cpp
index ab922217a..dd62eb5ac 100644
--- a/src/pubkey/pk_algs.cpp
+++ b/src/pubkey/pk_algs.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/pk_algs.h>
+#include <botan/internal/pk_algs.h>
#if defined(BOTAN_HAS_RSA)
#include <botan/rsa.h>
diff --git a/src/pubkey/pk_codecs/pkcs8.cpp b/src/pubkey/pk_codecs/pkcs8.cpp
index 3d73b7ab1..f287e1e63 100644
--- a/src/pubkey/pk_codecs/pkcs8.cpp
+++ b/src/pubkey/pk_codecs/pkcs8.cpp
@@ -10,9 +10,9 @@
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/asn1_obj.h>
-#include <botan/pk_algs.h>
#include <botan/oids.h>
#include <botan/pem.h>
+#include <botan/internal/pk_algs.h>
#include <memory>
namespace Botan {
diff --git a/src/pubkey/pk_codecs/x509_key.cpp b/src/pubkey/pk_codecs/x509_key.cpp
index 3fec15f7f..fcfb2b165 100644
--- a/src/pubkey/pk_codecs/x509_key.cpp
+++ b/src/pubkey/pk_codecs/x509_key.cpp
@@ -10,9 +10,9 @@
#include <botan/asn1_obj.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
-#include <botan/pk_algs.h>
#include <botan/oids.h>
#include <botan/pem.h>
+#include <botan/internal/pk_algs.h>
#include <memory>
namespace Botan {
diff --git a/src/pubkey/workfactor.cpp b/src/pubkey/workfactor.cpp
index e40b7919c..f15c64783 100644
--- a/src/pubkey/workfactor.cpp
+++ b/src/pubkey/workfactor.cpp
@@ -5,7 +5,7 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/workfactor.h>
+#include <botan/internal/workfactor.h>
#include <algorithm>
#include <cmath>
diff --git a/src/rng/hmac_rng/hmac_rng.cpp b/src/rng/hmac_rng/hmac_rng.cpp
index ef9ecba2b..995ec9259 100644
--- a/src/rng/hmac_rng/hmac_rng.cpp
+++ b/src/rng/hmac_rng/hmac_rng.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/hmac_rng.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/internal/xor_buf.h>
#include <botan/internal/stl_util.h>
#include <algorithm>
diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp
index 0b7f2921b..f6479b2dd 100644
--- a/src/rng/randpool/randpool.cpp
+++ b/src/rng/randpool/randpool.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/randpool.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/internal/xor_buf.h>
#include <botan/internal/stl_util.h>
#include <algorithm>
diff --git a/src/s2k/pbkdf2/pbkdf2.cpp b/src/s2k/pbkdf2/pbkdf2.cpp
index 4fc1b8deb..6f790c06b 100644
--- a/src/s2k/pbkdf2/pbkdf2.cpp
+++ b/src/s2k/pbkdf2/pbkdf2.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/pbkdf2.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/internal/xor_buf.h>
namespace Botan {
diff --git a/src/selftest/selftest.cpp b/src/selftest/selftest.cpp
index a4da329f4..291643f2c 100644
--- a/src/selftest/selftest.cpp
+++ b/src/selftest/selftest.cpp
@@ -7,7 +7,7 @@
#include <botan/selftest.h>
#include <botan/filters.h>
-#include <botan/def_eng.h>
+#include <botan/internal/default_engine.h>
#include <botan/internal/stl_util.h>
namespace Botan {
@@ -19,12 +19,14 @@ namespace {
*/
bool test_filter_kat(Filter* filter,
const std::string& input,
- const std::string& output)
+ const std::string& expected_output)
{
Pipe pipe(new Hex_Decoder, filter, new Hex_Encoder);
pipe.process_msg(input);
- return (output == pipe.read_all_as_string());
+ std::string output = pipe.read_all_as_string();
+
+ return (output == expected_output);
}
}
diff --git a/src/stream/salsa20/salsa20.cpp b/src/stream/salsa20/salsa20.cpp
index cc5d3a712..1b97f4421 100644
--- a/src/stream/salsa20/salsa20.cpp
+++ b/src/stream/salsa20/salsa20.cpp
@@ -6,8 +6,9 @@
*/
#include <botan/salsa20.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
#include <botan/internal/xor_buf.h>
-#include <botan/internal/loadstor.h>
namespace Botan {
diff --git a/src/stream/turing/turing.cpp b/src/stream/turing/turing.cpp
index dec9190ab..159c262fd 100644
--- a/src/stream/turing/turing.cpp
+++ b/src/stream/turing/turing.cpp
@@ -6,7 +6,8 @@
*/
#include <botan/turing.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
+#include <botan/rotate.h>
#include <botan/internal/xor_buf.h>
namespace Botan {
diff --git a/src/stream/wid_wake/wid_wake.cpp b/src/stream/wid_wake/wid_wake.cpp
index d52851aee..225ccf9a6 100644
--- a/src/stream/wid_wake/wid_wake.cpp
+++ b/src/stream/wid_wake/wid_wake.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/wid_wake.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/internal/xor_buf.h>
namespace Botan {
diff --git a/src/utils/bswap.h b/src/utils/bswap.h
index 3294111a0..96ec4982a 100644
--- a/src/utils/bswap.h
+++ b/src/utils/bswap.h
@@ -10,7 +10,15 @@
#define BOTAN_BYTE_SWAP_H__
#include <botan/types.h>
-#include <botan/internal/rotate.h>
+#include <botan/rotate.h>
+
+#if defined(BOTAN_TARGET_CPU_HAS_SSE2)
+ #include <emmintrin.h>
+#endif
+
+#if defined(BOTAN_TARGET_CPU_HAS_SSSE3)
+ #include <tmmintrin.h>
+#endif
namespace Botan {
@@ -24,39 +32,90 @@ inline u16bit reverse_bytes(u16bit input)
inline u32bit reverse_bytes(u32bit input)
{
-#if BOTAN_USE_GCC_INLINE_ASM && \
- (defined(BOTAN_TARGET_ARCH_IS_IA32) || defined(BOTAN_TARGET_ARCH_IS_AMD64))
+#if BOTAN_USE_GCC_INLINE_ASM && (defined(BOTAN_TARGET_ARCH_IS_IA32) || \
+ defined(BOTAN_TARGET_ARCH_IS_AMD64))
- /* GCC-style inline assembly for x86 or x86-64 */
+ // GCC-style inline assembly for x86 or x86-64
asm("bswapl %0" : "=r" (input) : "0" (input));
return input;
#elif defined(_MSC_VER) && defined(BOTAN_TARGET_ARCH_IS_IA32)
- /* Visual C++ inline asm for 32-bit x86, by Yves Jerschow */
+ // Visual C++ inline asm for 32-bit x86, by Yves Jerschow
__asm mov eax, input;
__asm bswap eax;
#else
- /* Generic implementation */
- input = ((input & 0xFF00FF00) >> 8) | ((input & 0x00FF00FF) << 8);
- return rotate_left(input, 16);
+ // Generic implementation
+ return (rotate_right(input, 8) & 0xFF00FF00) |
+ (rotate_left (input, 8) & 0x00FF00FF);
#endif
}
inline u64bit reverse_bytes(u64bit input)
{
#if BOTAN_USE_GCC_INLINE_ASM && defined(BOTAN_TARGET_ARCH_IS_AMD64)
+ // GCC-style inline assembly for x86-64
asm("bswapq %0" : "=r" (input) : "0" (input));
return input;
+
#else
- u32bit hi = ((input >> 40) & 0x00FF00FF) | ((input >> 24) & 0xFF00FF00);
- u32bit lo = ((input & 0xFF00FF00) >> 8) | ((input & 0x00FF00FF) << 8);
- hi = (hi << 16) | (hi >> 16);
- lo = (lo << 16) | (lo >> 16);
+ /* Generic implementation. Defined in terms of 32-bit bswap so any
+ * optimizations in that version can help here (particularly
+ * useful for 32-bit x86).
+ */
+
+ u32bit hi = static_cast<u32bit>(input >> 32);
+ u32bit lo = static_cast<u32bit>(input);
+
+ hi = reverse_bytes(hi);
+ lo = reverse_bytes(lo);
+
return (static_cast<u64bit>(lo) << 32) | hi;
#endif
}
+template<typename T>
+inline void bswap_4(T x[4])
+ {
+ x[0] = reverse_bytes(x[0]);
+ x[1] = reverse_bytes(x[1]);
+ x[2] = reverse_bytes(x[2]);
+ x[3] = reverse_bytes(x[3]);
+ }
+
+#if defined(BOTAN_TARGET_CPU_HAS_SSSE3)
+
+template<>
+inline void bswap_4(u32bit x[4])
+ {
+ const __m128i bswap_mask = _mm_set_epi8(
+ 12, 13, 14, 15,
+ 8, 9, 10, 11,
+ 4, 5, 6, 7,
+ 0, 1, 2, 3);
+
+ __m128i T = _mm_loadu_si128((const __m128i*)x);
+ T = _mm_shuffle_epi8(T, bswap_mask);
+ _mm_storeu_si128((__m128i*)x, T);
+ }
+
+#elif defined(BOTAN_TARGET_CPU_HAS_SSE2)
+
+template<>
+inline void bswap_4(u32bit x[4])
+ {
+ __m128i T = _mm_loadu_si128((const __m128i*)x);
+
+ T = _mm_shufflehi_epi16(T, _MM_SHUFFLE(2, 3, 0, 1));
+ T = _mm_shufflelo_epi16(T, _MM_SHUFFLE(2, 3, 0, 1));
+
+ T = _mm_or_si128(_mm_srli_epi16(T, 8), _mm_slli_epi16(T, 8));
+
+ _mm_storeu_si128((__m128i*)x, T);
+ }
+
+#endif
+
}
#endif
diff --git a/src/utils/charset.h b/src/utils/charset.h
index eebb1997d..afb11733b 100644
--- a/src/utils/charset.h
+++ b/src/utils/charset.h
@@ -28,14 +28,16 @@ namespace Charset {
/*
* Character Set Handling
*/
-std::string transcode(const std::string&, Character_Set, Character_Set);
+std::string BOTAN_DLL transcode(const std::string& str,
+ Character_Set to,
+ Character_Set from);
-bool is_digit(char);
-bool is_space(char);
-bool caseless_cmp(char, char);
+bool BOTAN_DLL is_digit(char c);
+bool BOTAN_DLL is_space(char c);
+bool BOTAN_DLL caseless_cmp(char x, char y);
-byte char2digit(char);
-char digit2char(byte);
+byte BOTAN_DLL char2digit(char c);
+char BOTAN_DLL digit2char(byte b);
}
diff --git a/src/utils/cpuid.cpp b/src/utils/cpuid.cpp
index a6f40f53c..2ba7f9b77 100644
--- a/src/utils/cpuid.cpp
+++ b/src/utils/cpuid.cpp
@@ -7,7 +7,7 @@
#include <botan/cpuid.h>
#include <botan/types.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/mem_ops.h>
#if defined(BOTAN_TARGET_ARCH_IS_IA32) || defined(BOTAN_TARGET_ARCH_IS_AMD64)
diff --git a/src/utils/cpuid.h b/src/utils/cpuid.h
index 455721af9..2c9599899 100644
--- a/src/utils/cpuid.h
+++ b/src/utils/cpuid.h
@@ -12,7 +12,7 @@
namespace Botan {
-class CPUID
+class BOTAN_DLL CPUID
{
public:
enum CPUID_bits {
diff --git a/src/utils/info.txt b/src/utils/info.txt
index edeeb1cf9..93ece2e78 100644
--- a/src/utils/info.txt
+++ b/src/utils/info.txt
@@ -15,22 +15,22 @@ version.cpp
<header:internal>
bit_ops.h
-bswap.h
-loadstor.h
mlock.h
prefetch.h
-rotate.h
rounding.h
stl_util.h
xor_buf.h
</header:internal>
<header:public>
+bswap.h
charset.h
cpuid.h
exceptn.h
+loadstor.h
mem_ops.h
parsing.h
+rotate.h
time.h
types.h
ui.h
diff --git a/src/utils/loadstor.h b/src/utils/loadstor.h
index fa2e36c1e..bd2acc87d 100644
--- a/src/utils/loadstor.h
+++ b/src/utils/loadstor.h
@@ -10,9 +10,7 @@
#define BOTAN_LOAD_STORE_H__
#include <botan/types.h>
-#include <botan/internal/bswap.h>
-#include <botan/internal/rotate.h>
-#include <botan/internal/prefetch.h>
+#include <botan/bswap.h>
#include <cstring>
#if BOTAN_TARGET_UNALIGNED_MEMORY_ACCESS_OK
@@ -44,7 +42,9 @@ namespace Botan {
*/
template<typename T> inline byte get_byte(u32bit byte_num, T input)
{
- return (input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3));
+ return static_cast<byte>(
+ input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3)
+ );
}
/*
@@ -204,24 +204,22 @@ inline void load_le(T out[],
const byte in[],
u32bit count)
{
-#if defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN)
+#if defined(BOTAN_TARGET_CPU_HAS_KNOWN_ENDIANNESS)
std::memcpy(out, in, sizeof(T)*count);
-#else
+
+#if defined(BOTAN_TARGET_CPU_IS_BIG_ENDIAN)
const u32bit blocks = count - (count % 4);
const u32bit left = count - blocks;
for(u32bit i = 0; i != blocks; i += 4)
- {
- out[0] = load_le<T>(in, 0);
- out[1] = load_le<T>(in, 1);
- out[2] = load_le<T>(in, 2);
- out[3] = load_le<T>(in, 3);
-
- out += 4;
- in += 4*sizeof(T);
- }
+ bswap_4(out + i);
for(u32bit i = 0; i != left; ++i)
+ out[blocks+i] = reverse_bytes(out[blocks+i]);
+#endif
+
+#else
+ for(u32bit i = 0; i != count; ++i)
out[i] = load_le<T>(in, i);
#endif
}
@@ -263,24 +261,22 @@ inline void load_be(T out[],
const byte in[],
u32bit count)
{
-#if defined(BOTAN_TARGET_CPU_IS_BIG_ENDIAN)
+#if defined(BOTAN_TARGET_CPU_HAS_KNOWN_ENDIANNESS)
std::memcpy(out, in, sizeof(T)*count);
-#else
+
+#if defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN)
const u32bit blocks = count - (count % 4);
const u32bit left = count - blocks;
for(u32bit i = 0; i != blocks; i += 4)
- {
- out[0] = load_be<T>(in, 0);
- out[1] = load_be<T>(in, 1);
- out[2] = load_be<T>(in, 2);
- out[3] = load_be<T>(in, 3);
-
- out += 4;
- in += 4*sizeof(T);
- }
+ bswap_4(out + i);
for(u32bit i = 0; i != left; ++i)
+ out[blocks+i] = reverse_bytes(out[blocks+i]);
+#endif
+
+#else
+ for(u32bit i = 0; i != count; ++i)
out[i] = load_be<T>(in, i);
#endif
}
diff --git a/src/utils/parsing.cpp b/src/utils/parsing.cpp
index 0ccd8a312..58a8e0b38 100644
--- a/src/utils/parsing.cpp
+++ b/src/utils/parsing.cpp
@@ -8,7 +8,7 @@
#include <botan/parsing.h>
#include <botan/exceptn.h>
#include <botan/charset.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/utils/simd_32/simd_altivec.h b/src/utils/simd_32/simd_altivec.h
index d24c7e73f..9cc5c1068 100644
--- a/src/utils/simd_32/simd_altivec.h
+++ b/src/utils/simd_32/simd_altivec.h
@@ -10,7 +10,7 @@
#if defined(BOTAN_TARGET_CPU_HAS_ALTIVEC)
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/cpuid.h>
#include <altivec.h>
diff --git a/src/utils/simd_32/simd_scalar.h b/src/utils/simd_32/simd_scalar.h
index e8e46db44..148b76c35 100644
--- a/src/utils/simd_32/simd_scalar.h
+++ b/src/utils/simd_32/simd_scalar.h
@@ -8,8 +8,8 @@
#ifndef BOTAN_SIMD_SCALAR_H__
#define BOTAN_SIMD_SCALAR_H__
-#include <botan/internal/loadstor.h>
-#include <botan/internal/bswap.h>
+#include <botan/loadstor.h>
+#include <botan/bswap.h>
namespace Botan {
diff --git a/src/utils/time.cpp b/src/utils/time.cpp
index 856b1c7be..fe4521706 100644
--- a/src/utils/time.cpp
+++ b/src/utils/time.cpp
@@ -9,21 +9,25 @@
#include <botan/exceptn.h>
#include <ctime>
+#if defined(BOTAN_TARGET_OS_HAS_WIN32_GET_SYSTEMTIME)
+ #include <windows.h>
+#endif
+
#if defined(BOTAN_TARGET_OS_HAS_GETTIMEOFDAY)
#include <sys/time.h>
#endif
#if defined(BOTAN_TARGET_OS_HAS_CLOCK_GETTIME)
-#ifndef _POSIX_C_SOURCE
- #define _POSIX_C_SOURCE 199309
-#endif
+ #ifndef _POSIX_C_SOURCE
+ #define _POSIX_C_SOURCE 199309
+ #endif
-#include <time.h>
+ #include <time.h>
-#ifndef CLOCK_REALTIME
- #define CLOCK_REALTIME 0
-#endif
+ #ifndef CLOCK_REALTIME
+ #define CLOCK_REALTIME 0
+ #endif
#endif
@@ -43,6 +47,24 @@ u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz)
return res;
}
+std::tm do_gmtime(time_t time_val)
+ {
+ std::tm tm;
+
+#if defined(BOTAN_TARGET_OS_HAS_GMTIME_S)
+ gmtime_s(&tm, &time_val); // Windows
+#elif defined(BOTAN_TARGET_OS_HAS_GMTIME_R)
+ gmtime_r(&time_val, &tm); // Unix/SUSv2
+#else
+ std::tm* tm_p = std::gmtime(&time_val);
+ if (tm_p == 0)
+ throw Encoding_Error("time_t_to_tm could not convert");
+ tm = *tm_p;
+#endif
+
+ return tm;
+ }
+
}
/**
@@ -54,16 +76,18 @@ u64bit system_time()
}
/*
-* Convert a time_t to a struct tm
+* Convert a time_point to a calendar_point
*/
-std::tm time_t_to_tm(u64bit timer)
+calendar_point calendar_value(u64bit a_time_t)
{
- std::time_t time_val = static_cast<std::time_t>(timer);
-
- std::tm* tm_p = std::gmtime(&time_val);
- if (tm_p == 0)
- throw Encoding_Error("time_t_to_tm could not convert");
- return (*tm_p);
+ std::tm tm = do_gmtime(static_cast<std::time_t>(a_time_t));
+
+ return calendar_point(tm.tm_year + 1900,
+ tm.tm_mon + 1,
+ tm.tm_mday,
+ tm.tm_hour,
+ tm.tm_min,
+ tm.tm_sec);
}
u64bit get_nanoseconds_clock()
@@ -78,6 +102,16 @@ u64bit get_nanoseconds_clock()
::gettimeofday(&tv, 0);
return combine_timers(tv.tv_sec, tv.tv_usec, 1000000);
+#elif defined(BOTAN_TARGET_OS_HAS_WIN32_GET_SYSTEMTIME)
+
+ // Returns time since January 1, 1601 in 100-ns increments
+ ::FILETIME tv;
+ ::GetSystemTimeAsFileTime(&tv);
+ u64bit tstamp = (static_cast<u64bit>(tv.dwHighDateTime) << 32) |
+ tv.dwLowDateTime;
+
+ return (tstamp * 100); // Scale to 1 nanosecond units
+
#else
return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC);
diff --git a/src/utils/time.h b/src/utils/time.h
index c7f459096..bc571120b 100644
--- a/src/utils/time.h
+++ b/src/utils/time.h
@@ -13,15 +13,35 @@
namespace Botan {
-/*
-* Time Access/Conversion Functions
+/**
+* Struct representing a particular date and time
*/
-BOTAN_DLL u64bit system_time();
+struct BOTAN_DLL calendar_point
+ {
+ u32bit year;
+ byte month;
+ byte day;
+ byte hour;
+ byte minutes;
+ byte seconds;
+
+ calendar_point(u32bit y, byte mon, byte d, byte h, byte min, byte sec) :
+ year(y), month(mon), day(d), hour(h), minutes(min), seconds(sec) {}
+ };
+
+/**
+* @param time_point a time point from the system clock
+* @returns calendar_point object representing this time point
+*/
+BOTAN_DLL calendar_point calendar_value(u64bit time_point);
-BOTAN_DLL std::tm time_t_to_tm(u64bit);
+/**
+* @return seconds resolution timestamp, unknown epoch
+*/
+BOTAN_DLL u64bit system_time();
/**
-@return nanoseconds resolution timestamp, unknown epoch
+* @return nanoseconds resolution timestamp, unknown epoch
*/
BOTAN_DLL u64bit get_nanoseconds_clock();
diff --git a/src/utils/xor_buf.h b/src/utils/xor_buf.h
index 39c4a493d..0d7d587c8 100644
--- a/src/utils/xor_buf.h
+++ b/src/utils/xor_buf.h
@@ -22,7 +22,7 @@ inline void xor_buf(byte out[], const byte in[], u32bit length)
{
while(length >= 8)
{
-#if BOTAN_UNALIGNED_MEMORY_ACCESS_OK
+#if BOTAN_TARGET_UNALIGNED_MEMORY_ACCESS_OK
*reinterpret_cast<u64bit*>(out) ^= *reinterpret_cast<const u64bit*>(in);
#else
out[0] ^= in[0]; out[1] ^= in[1];
@@ -51,7 +51,7 @@ inline void xor_buf(byte out[],
{
while(length >= 8)
{
-#if BOTAN_UNALIGNED_MEMORY_ACCESS_OK
+#if BOTAN_TARGET_UNALIGNED_MEMORY_ACCESS_OK
*reinterpret_cast<u64bit*>(out) =
*reinterpret_cast<const u64bit*>(in) ^
*reinterpret_cast<const u64bit*>(in2);