diff options
author | lloyd <[email protected]> | 2008-09-28 18:30:25 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-28 18:30:25 +0000 |
commit | ed39cde548c5cbff3896dc4c9ab5803d1334dd29 (patch) | |
tree | 2aff7e517a1e8bf239f601b938f6930c30783526 /src | |
parent | c9d4ef2b4500ff890c91e9dcaef61ad844a08782 (diff) |
Modularize RNG implementations
Diffstat (limited to 'src')
-rw-r--r-- | src/def_alg.cpp | 296 | ||||
-rw-r--r-- | src/def_mode.cpp | 42 | ||||
-rw-r--r-- | src/get_enc.cpp | 72 | ||||
-rw-r--r-- | src/randpool.cpp | 223 | ||||
-rw-r--r-- | src/rng.cpp | 23 | ||||
-rw-r--r-- | src/x931_rng.cpp | 142 |
6 files changed, 223 insertions, 575 deletions
diff --git a/src/def_alg.cpp b/src/def_alg.cpp index 285cca8f2..7bcc84378 100644 --- a/src/def_alg.cpp +++ b/src/def_alg.cpp @@ -10,202 +10,202 @@ #include <botan/par_hash.h> #include <botan/mode_pad.h> -#ifdef BOTAN_HAS_AES - #include <botan/aes.h> +#if defined(BOTAN_HAS_AES) + #include <botan/aes.h> #endif -#ifdef BOTAN_HAS_BLOWFISH - #include <botan/blowfish.h> +#if defined(BOTAN_HAS_BLOWFISH) + #include <botan/blowfish.h> #endif -#ifdef BOTAN_HAS_CAST - #include <botan/cast128.h> - #include <botan/cast256.h> +#if defined(BOTAN_HAS_CAST) + #include <botan/cast128.h> + #include <botan/cast256.h> #endif -#ifdef BOTAN_HAS_DES - #include <botan/des.h> +#if defined(BOTAN_HAS_DES) + #include <botan/des.h> #endif -#ifdef BOTAN_HAS_GOST - #include <botan/gost.h> +#if defined(BOTAN_HAS_GOST) + #include <botan/gost.h> #endif -#ifdef BOTAN_HAS_IDEA - #include <botan/idea.h> +#if defined(BOTAN_HAS_IDEA) + #include <botan/idea.h> #endif -#ifdef BOTAN_HAS_KASUMI - #include <botan/kasumi.h> +#if defined(BOTAN_HAS_KASUMI) + #include <botan/kasumi.h> #endif -#ifdef BOTAN_HAS_LION - #include <botan/lion.h> +#if defined(BOTAN_HAS_LION) + #include <botan/lion.h> #endif -#ifdef BOTAN_HAS_LUBY_RACKOFF - #include <botan/lubyrack.h> +#if defined(BOTAN_HAS_LUBY_RACKOFF) + #include <botan/lubyrack.h> #endif -#ifdef BOTAN_HAS_MARS - #include <botan/mars.h> +#if defined(BOTAN_HAS_MARS) + #include <botan/mars.h> #endif -#ifdef BOTAN_HAS_MISTY1 - #include <botan/misty1.h> +#if defined(BOTAN_HAS_MISTY1) + #include <botan/misty1.h> #endif -#ifdef BOTAN_HAS_NOEKEON - #include <botan/noekeon.h> +#if defined(BOTAN_HAS_NOEKEON) + #include <botan/noekeon.h> #endif -#ifdef BOTAN_HAS_RC2 - #include <botan/rc2.h> +#if defined(BOTAN_HAS_RC2) + #include <botan/rc2.h> #endif -#ifdef BOTAN_HAS_RC5 - #include <botan/rc5.h> +#if defined(BOTAN_HAS_RC5) + #include <botan/rc5.h> #endif -#ifdef BOTAN_HAS_RC6 - #include <botan/rc6.h> +#if defined(BOTAN_HAS_RC6) + #include <botan/rc6.h> #endif -#ifdef BOTAN_HAS_SAFER - #include <botan/safer_sk.h> +#if defined(BOTAN_HAS_SAFER) + #include <botan/safer_sk.h> #endif -#ifdef BOTAN_HAS_SEED - #include <botan/seed.h> +#if defined(BOTAN_HAS_SEED) + #include <botan/seed.h> #endif -#ifdef BOTAN_HAS_SERPENT - #include <botan/serpent.h> +#if defined(BOTAN_HAS_SERPENT) + #include <botan/serpent.h> #endif -#ifdef BOTAN_HAS_SKIPJACK - #include <botan/skipjack.h> +#if defined(BOTAN_HAS_SKIPJACK) + #include <botan/skipjack.h> #endif -#ifdef BOTAN_HAS_SQUARE - #include <botan/square.h> +#if defined(BOTAN_HAS_SQUARE) + #include <botan/square.h> #endif -#ifdef BOTAN_HAS_TEA - #include <botan/tea.h> +#if defined(BOTAN_HAS_TEA) + #include <botan/tea.h> #endif -#ifdef BOTAN_HAS_TWOFISH - #include <botan/twofish.h> +#if defined(BOTAN_HAS_TWOFISH) + #include <botan/twofish.h> #endif -#ifdef BOTAN_HAS_XTEA - #include <botan/xtea.h> +#if defined(BOTAN_HAS_XTEA) + #include <botan/xtea.h> #endif -#ifdef BOTAN_HAS_ARC4 - #include <botan/arc4.h> +#if defined(BOTAN_HAS_ARC4) + #include <botan/arc4.h> #endif -#ifdef BOTAN_HAS_SALSA20 - #include <botan/salsa20.h> +#if defined(BOTAN_HAS_SALSA20) + #include <botan/salsa20.h> #endif -#ifdef BOTAN_HAS_TURING - #include <botan/turing.h> +#if defined(BOTAN_HAS_TURING) + #include <botan/turing.h> #endif -#ifdef BOTAN_HAS_WID_WAKE - #include <botan/wid_wake.h> +#if defined(BOTAN_HAS_WID_WAKE) + #include <botan/wid_wake.h> #endif -#ifdef BOTAN_HAS_ADLER32 +#if defined(BOTAN_HAS_ADLER32) #include <botan/adler32.h> #endif -#ifdef BOTAN_HAS_CRC24 - #include <botan/crc24.h> +#if defined(BOTAN_HAS_CRC24) + #include <botan/crc24.h> #endif -#ifdef BOTAN_HAS_CRC32 - #include <botan/crc32.h> +#if defined(BOTAN_HAS_CRC32) + #include <botan/crc32.h> #endif -#ifdef BOTAN_HAS_FORK_256 - #include <botan/fork256.h> +#if defined(BOTAN_HAS_FORK_256) + #include <botan/fork256.h> #endif -#ifdef BOTAN_HAS_HAS_160 - #include <botan/has160.h> +#if defined(BOTAN_HAS_HAS_160) + #include <botan/has160.h> #endif -#ifdef BOTAN_HAS_MD2 - #include <botan/md2.h> +#if defined(BOTAN_HAS_MD2) + #include <botan/md2.h> #endif -#ifdef BOTAN_HAS_MD4 - #include <botan/md4.h> +#if defined(BOTAN_HAS_MD4) + #include <botan/md4.h> #endif -#ifdef BOTAN_HAS_MD5 - #include <botan/md5.h> +#if defined(BOTAN_HAS_MD5) + #include <botan/md5.h> #endif -#ifdef BOTAN_HAS_RIPEMD_128 - #include <botan/rmd128.h> +#if defined(BOTAN_HAS_RIPEMD_128) + #include <botan/rmd128.h> #endif -#ifdef BOTAN_HAS_RIPEMD_160 - #include <botan/rmd160.h> +#if defined(BOTAN_HAS_RIPEMD_160) + #include <botan/rmd160.h> #endif -#ifdef BOTAN_HAS_SHA1 - #include <botan/sha160.h> +#if defined(BOTAN_HAS_SHA1) + #include <botan/sha160.h> #endif -#ifdef BOTAN_HAS_SHA2 - #include <botan/sha256.h> - #include <botan/sha_64.h> +#if defined(BOTAN_HAS_SHA2) + #include <botan/sha256.h> + #include <botan/sha_64.h> #endif -#ifdef BOTAN_HAS_TIGER - #include <botan/tiger.h> +#if defined(BOTAN_HAS_TIGER) + #include <botan/tiger.h> #endif -#ifdef BOTAN_HAS_WHIRLPOOL - #include <botan/whrlpool.h> +#if defined(BOTAN_HAS_WHIRLPOOL) + #include <botan/whrlpool.h> #endif -#ifdef BOTAN_HAS_CBC_MAC - #include <botan/cbc_mac.h> +#if defined(BOTAN_HAS_CBC_MAC) + #include <botan/cbc_mac.h> #endif -#ifdef BOTAN_HAS_CMAC - #include <botan/cmac.h> +#if defined(BOTAN_HAS_CMAC) + #include <botan/cmac.h> #endif -#ifdef BOTAN_HAS_HMAC - #include <botan/hmac.h> +#if defined(BOTAN_HAS_HMAC) + #include <botan/hmac.h> #endif -#ifdef BOTAN_HAS_SSL3_MAC - #include <botan/ssl3_mac.h> +#if defined(BOTAN_HAS_SSL3_MAC) + #include <botan/ssl3_mac.h> #endif -#ifdef BOTAN_HAS_ANSI_X919_MAC - #include <botan/x919_mac.h> +#if defined(BOTAN_HAS_ANSI_X919_MAC) + #include <botan/x919_mac.h> #endif -#ifdef BOTAN_HAS_PBKDF1 - #include <botan/pbkdf1.h> +#if defined(BOTAN_HAS_PBKDF1) + #include <botan/pbkdf1.h> #endif -#ifdef BOTAN_HAS_PBKDF2 - #include <botan/pbkdf2.h> +#if defined(BOTAN_HAS_PBKDF2) + #include <botan/pbkdf2.h> #endif -#ifdef BOTAN_HAS_PGPS2K - #include <botan/pgp_s2k.h> +#if defined(BOTAN_HAS_PGPS2K) + #include <botan/pgp_s2k.h> #endif namespace Botan { @@ -262,97 +262,97 @@ Default_Engine::find_block_cipher(const std::string& algo_spec) const return 0; const std::string algo_name = global_state().deref_alias(name[0]); -#ifdef BOTAN_HAS_AES +#if defined(BOTAN_HAS_AES) HANDLE_TYPE_NO_ARGS("AES", AES); HANDLE_TYPE_NO_ARGS("AES-128", AES_128); HANDLE_TYPE_NO_ARGS("AES-192", AES_192); HANDLE_TYPE_NO_ARGS("AES-256", AES_256); #endif -#ifdef BOTAN_HAS_BLOWFISH +#if defined(BOTAN_HAS_BLOWFISH) HANDLE_TYPE_NO_ARGS("Blowfish", Blowfish); #endif -#ifdef BOTAN_HAS_CAST +#if defined(BOTAN_HAS_CAST) HANDLE_TYPE_NO_ARGS("CAST-128", CAST_128); HANDLE_TYPE_NO_ARGS("CAST-256", CAST_256); #endif -#ifdef BOTAN_HAS_DES +#if defined(BOTAN_HAS_DES) HANDLE_TYPE_NO_ARGS("DES", DES); HANDLE_TYPE_NO_ARGS("DESX", DESX); HANDLE_TYPE_NO_ARGS("TripleDES", TripleDES); #endif -#ifdef BOTAN_HAS_GOST +#if defined(BOTAN_HAS_GOST) HANDLE_TYPE_NO_ARGS("GOST", GOST); #endif -#ifdef BOTAN_HAS_IDEA +#if defined(BOTAN_HAS_IDEA) HANDLE_TYPE_NO_ARGS("IDEA", IDEA); #endif -#ifdef BOTAN_HAS_KASUMI +#if defined(BOTAN_HAS_KASUMI) HANDLE_TYPE_NO_ARGS("KASUMI", KASUMI); #endif -#ifdef BOTAN_HAS_MARS +#if defined(BOTAN_HAS_MARS) HANDLE_TYPE_NO_ARGS("MARS", MARS); #endif -#ifdef BOTAN_HAS_MISTY1 +#if defined(BOTAN_HAS_MISTY1) HANDLE_TYPE_ONE_U32BIT("MISTY1", MISTY1, 8); #endif -#ifdef BOTAN_HAS_NOEKEON +#if defined(BOTAN_HAS_NOEKEON) HANDLE_TYPE_NO_ARGS("Noekeon", Noekeon); #endif -#ifdef BOTAN_HAS_RC2 +#if defined(BOTAN_HAS_RC2) HANDLE_TYPE_NO_ARGS("RC2", RC2); #endif -#ifdef BOTAN_HAS_RC5 +#if defined(BOTAN_HAS_RC5) HANDLE_TYPE_ONE_U32BIT("RC5", RC5, 12); #endif -#ifdef BOTAN_HAS_RC6 +#if defined(BOTAN_HAS_RC6) HANDLE_TYPE_NO_ARGS("RC6", RC6); #endif -#ifdef BOTAN_HAS_SAFER +#if defined(BOTAN_HAS_SAFER) HANDLE_TYPE_ONE_U32BIT("SAFER-SK", SAFER_SK, 10); #endif -#ifdef BOTAN_HAS_SEED +#if defined(BOTAN_HAS_SEED) HANDLE_TYPE_NO_ARGS("SEED", SEED); #endif -#ifdef BOTAN_HAS_SERPENT +#if defined(BOTAN_HAS_SERPENT) HANDLE_TYPE_NO_ARGS("Serpent", Serpent); #endif -#ifdef BOTAN_HAS_SKIPJACK +#if defined(BOTAN_HAS_SKIPJACK) HANDLE_TYPE_NO_ARGS("Skipjack", Skipjack); #endif -#ifdef BOTAN_HAS_SQUARE +#if defined(BOTAN_HAS_SQUARE) HANDLE_TYPE_NO_ARGS("Square", Square); #endif -#ifdef BOTAN_HAS_TEA +#if defined(BOTAN_HAS_TEA) HANDLE_TYPE_NO_ARGS("TEA", TEA); #endif -#ifdef BOTAN_HAS_TWOFISH +#if defined(BOTAN_HAS_TWOFISH) HANDLE_TYPE_NO_ARGS("Twofish", Twofish); #endif -#ifdef BOTAN_HAS_XTEA +#if defined(BOTAN_HAS_XTEA) HANDLE_TYPE_NO_ARGS("XTEA", XTEA); #endif -#ifdef BOTAN_HAS_LUBY_RACKOFF +#if defined(BOTAN_HAS_LUBY_RACKOFF) if(algo_name == "Luby-Rackoff" && name.size() >= 2) { HashFunction* hash = find_hash(name[1]); @@ -361,7 +361,7 @@ Default_Engine::find_block_cipher(const std::string& algo_spec) const } #endif -#ifdef BOTAN_HAS_LION +#if defined(BOTAN_HAS_LION) if(algo_name == "Lion") { if(name.size() != 4) @@ -384,20 +384,20 @@ Default_Engine::find_stream_cipher(const std::string& algo_spec) const return 0; const std::string algo_name = global_state().deref_alias(name[0]); -#ifdef BOTAN_HAS_ARC4 +#if defined(BOTAN_HAS_ARC4) HANDLE_TYPE_ONE_U32BIT("ARC4", ARC4, 0); HANDLE_TYPE_ONE_U32BIT("RC4_drop", ARC4, 768); #endif -#ifdef BOTAN_HAS_SALSA20 +#if defined(BOTAN_HAS_SALSA20) HANDLE_TYPE_NO_ARGS("Salsa20", Salsa20); #endif -#ifdef BOTAN_HAS_TURING +#if defined(BOTAN_HAS_TURING) HANDLE_TYPE_NO_ARGS("Turing", Turing); #endif -#ifdef BOTAN_HAS_WID_WAKE +#if defined(BOTAN_HAS_WID_WAKE) HANDLE_TYPE_NO_ARGS("WiderWake4+1-BE", WiderWake_41_BE); #endif @@ -415,61 +415,61 @@ Default_Engine::find_hash(const std::string& algo_spec) const return 0; const std::string algo_name = global_state().deref_alias(name[0]); -#ifdef BOTAN_HAS_ADLER32 +#if defined(BOTAN_HAS_ADLER32) HANDLE_TYPE_NO_ARGS("Adler32", Adler32); #endif -#ifdef BOTAN_HAS_CRC24 +#if defined(BOTAN_HAS_CRC24) HANDLE_TYPE_NO_ARGS("CRC24", CRC24); #endif -#ifdef BOTAN_HAS_CRC32 +#if defined(BOTAN_HAS_CRC32) HANDLE_TYPE_NO_ARGS("CRC32", CRC32); #endif -#ifdef BOTAN_HAS_FORK_256 +#if defined(BOTAN_HAS_FORK_256) HANDLE_TYPE_NO_ARGS("FORK-256", FORK_256); #endif -#ifdef BOTAN_HAS_HAS_160 +#if defined(BOTAN_HAS_HAS_160) HANDLE_TYPE_NO_ARGS("HAS-160", HAS_160); #endif -#ifdef BOTAN_HAS_MD2 +#if defined(BOTAN_HAS_MD2) HANDLE_TYPE_NO_ARGS("MD2", MD2); #endif -#ifdef BOTAN_HAS_MD4 +#if defined(BOTAN_HAS_MD4) HANDLE_TYPE_NO_ARGS("MD4", MD4); #endif -#ifdef BOTAN_HAS_MD5 +#if defined(BOTAN_HAS_MD5) HANDLE_TYPE_NO_ARGS("MD5", MD5); #endif -#ifdef BOTAN_HAS_RIPEMD_128 +#if defined(BOTAN_HAS_RIPEMD_128) HANDLE_TYPE_NO_ARGS("RIPEMD-128", RIPEMD_128); #endif -#ifdef BOTAN_HAS_RIPEMD_160 +#if defined(BOTAN_HAS_RIPEMD_160) HANDLE_TYPE_NO_ARGS("RIPEMD-160", RIPEMD_160); #endif -#ifdef BOTAN_HAS_SHA1 +#if defined(BOTAN_HAS_SHA1) HANDLE_TYPE_NO_ARGS("SHA-160", SHA_160); #endif -#ifdef BOTAN_HAS_SHA2 +#if defined(BOTAN_HAS_SHA2) HANDLE_TYPE_NO_ARGS("SHA-256", SHA_256); HANDLE_TYPE_NO_ARGS("SHA-384", SHA_384); HANDLE_TYPE_NO_ARGS("SHA-512", SHA_512); #endif -#ifdef BOTAN_HAS_TIGER +#if defined(BOTAN_HAS_TIGER) HANDLE_TYPE_TWO_U32BIT("Tiger", Tiger, 24); #endif -#ifdef BOTAN_HAS_WHIRLPOOL +#if defined(BOTAN_HAS_WHIRLPOOL) HANDLE_TYPE_NO_ARGS("Whirlpool", Whirlpool); #endif @@ -495,23 +495,23 @@ Default_Engine::find_mac(const std::string& algo_spec) const return 0; const std::string algo_name = global_state().deref_alias(name[0]); -#ifdef BOTAN_HAS_CBC_MAC +#if defined(BOTAN_HAS_CBC_MAC) HANDLE_TYPE_ONE_STRING("CBC-MAC", CBC_MAC); #endif -#ifdef BOTAN_HAS_CMAC +#if defined(BOTAN_HAS_CMAC) HANDLE_TYPE_ONE_STRING("CMAC", CMAC); #endif -#ifdef BOTAN_HAS_HMAC +#if defined(BOTAN_HAS_HMAC) HANDLE_TYPE_ONE_STRING("HMAC", HMAC); #endif -#ifdef BOTAN_HAS_SSL3_MAC +#if defined(BOTAN_HAS_SSL3_MAC) HANDLE_TYPE_ONE_STRING("SSL3-MAC", SSL3_MAC); #endif -#ifdef BOTAN_HAS_ANSI_X919_MAC +#if defined(BOTAN_HAS_ANSI_X919_MAC) HANDLE_TYPE_NO_ARGS("X9.19-MAC", ANSI_X919_MAC); #endif @@ -529,15 +529,15 @@ S2K* Default_Engine::find_s2k(const std::string& algo_spec) const const std::string algo_name = global_state().deref_alias(name[0]); -#ifdef BOTAN_HAS_PBKDF1 +#if defined(BOTAN_HAS_PBKDF1) HANDLE_TYPE_ONE_STRING("PBKDF1", PKCS5_PBKDF1); #endif -#ifdef BOTAN_HAS_PBKDF2 +#if defined(BOTAN_HAS_PBKDF2) HANDLE_TYPE_ONE_STRING("PBKDF2", PKCS5_PBKDF2); #endif -#ifdef BOTAN_HAS_PGPS2K +#if defined(BOTAN_HAS_PGPS2K) HANDLE_TYPE_ONE_STRING("OpenPGP-S2K", OpenPGP_S2K); #endif diff --git a/src/def_mode.cpp b/src/def_mode.cpp index 0645364a0..b062cc34b 100644 --- a/src/def_mode.cpp +++ b/src/def_mode.cpp @@ -8,32 +8,32 @@ #include <botan/filters.h> #include <botan/lookup.h> -#ifdef BOTAN_HAS_ECB - #include <botan/ecb.h> +#if defined(BOTAN_HAS_ECB) + #include <botan/ecb.h> #endif -#ifdef BOTAN_HAS_CBC - #include <botan/cbc.h> +#if defined(BOTAN_HAS_CBC) + #include <botan/cbc.h> #endif -#ifdef BOTAN_HAS_CTS - #include <botan/cts.h> +#if defined(BOTAN_HAS_CTS) + #include <botan/cts.h> #endif -#ifdef BOTAN_HAS_CFB - #include <botan/cfb.h> +#if defined(BOTAN_HAS_CFB) + #include <botan/cfb.h> #endif -#ifdef BOTAN_HAS_OFB - #include <botan/ofb.h> +#if defined(BOTAN_HAS_OFB) + #include <botan/ofb.h> #endif -#ifdef BOTAN_HAS_CTR - #include <botan/ctr.h> +#if defined(BOTAN_HAS_CTR) + #include <botan/ctr.h> #endif -#ifdef BOTAN_HAS_EAX - #include <botan/eax.h> +#if defined(BOTAN_HAS_EAX) + #include <botan/eax.h> #endif namespace Botan { @@ -90,7 +90,7 @@ Keyed_Filter* Default_Engine::get_cipher(const std::string& algo_spec, if(mode == "OFB") { -#ifdef BOTAN_HAS_OFB +#if defined(BOTAN_HAS_OFB) return new OFB(cipher); #else return 0; @@ -98,7 +98,7 @@ Keyed_Filter* Default_Engine::get_cipher(const std::string& algo_spec, } else if(mode == "CTR-BE") { -#ifdef BOTAN_HAS_CTR +#if defined(BOTAN_HAS_CTR) return new CTR_BE(cipher); #else return 0; @@ -109,7 +109,7 @@ Keyed_Filter* Default_Engine::get_cipher(const std::string& algo_spec, { if(mode == "ECB") { -#ifdef BOTAN_HAS_ECB +#if defined(BOTAN_HAS_ECB) if(direction == ENCRYPTION) return new ECB_Encryption(cipher, padding); else @@ -120,7 +120,7 @@ Keyed_Filter* Default_Engine::get_cipher(const std::string& algo_spec, } else if(mode == "CFB") { -#ifdef BOTAN_HAS_CFB +#if defined(BOTAN_HAS_CFB) if(direction == ENCRYPTION) return new CFB_Encryption(cipher, bits); else @@ -133,7 +133,7 @@ Keyed_Filter* Default_Engine::get_cipher(const std::string& algo_spec, { if(padding == "CTS") { -#ifdef BOTAN_HAS_CTS +#if defined(BOTAN_HAS_CTS) if(direction == ENCRYPTION) return new CTS_Encryption(cipher); else @@ -143,7 +143,7 @@ Keyed_Filter* Default_Engine::get_cipher(const std::string& algo_spec, #endif } -#ifdef BOTAN_HAS_CBC +#if defined(BOTAN_HAS_CBC) if(direction == ENCRYPTION) return new CBC_Encryption(cipher, padding); else @@ -154,7 +154,7 @@ Keyed_Filter* Default_Engine::get_cipher(const std::string& algo_spec, } else if(mode == "EAX") { -#ifdef BOTAN_HAS_EAX +#if defined(BOTAN_HAS_EAX) if(direction == ENCRYPTION) return new EAX_Encryption(cipher, bits); else diff --git a/src/get_enc.cpp b/src/get_enc.cpp index 8137f4645..cdef00980 100644 --- a/src/get_enc.cpp +++ b/src/get_enc.cpp @@ -9,52 +9,52 @@ #include <botan/mgf1.h> #include <botan/util.h> -#ifdef BOTAN_HAS_EMSA1 - #include <botan/emsa1.h> +#if defined(BOTAN_HAS_EMSA1) + #include <botan/emsa1.h> #endif -#ifdef BOTAN_HAS_EMSA2 - #include <botan/emsa2.h> +#if defined(BOTAN_HAS_EMSA2) + #include <botan/emsa2.h> #endif -#ifdef BOTAN_HAS_EMSA3 - #include <botan/emsa3.h> +#if defined(BOTAN_HAS_EMSA3) + #include <botan/emsa3.h> #endif -#ifdef BOTAN_HAS_EMSA4 - #include <botan/emsa4.h> +#if defined(BOTAN_HAS_EMSA4) + #include <botan/emsa4.h> #endif -#ifdef BOTAN_HAS_EMSA_RAW - #include <botan/emsa_raw.h> +#if defined(BOTAN_HAS_EMSA_RAW) + #include <botan/emsa_raw.h> #endif -#ifdef BOTAN_HAS_EME1 - #include <botan/eme1.h> +#if defined(BOTAN_HAS_EME1) + #include <botan/eme1.h> #endif -#ifdef BOTAN_HAS_EME_PKCS1v15 - #include <botan/eme_pkcs.h> +#if defined(BOTAN_HAS_EME_PKCS1v15) + #include <botan/eme_pkcs.h> #endif -#ifdef BOTAN_HAS_KDF1 - #include <botan/kdf1.h> +#if defined(BOTAN_HAS_KDF1) + #include <botan/kdf1.h> #endif -#ifdef BOTAN_HAS_KDF2 - #include <botan/kdf2.h> +#if defined(BOTAN_HAS_KDF2) + #include <botan/kdf2.h> #endif -#ifdef BOTAN_HAS_X942_PRF - #include <botan/prf_x942.h> +#if defined(BOTAN_HAS_X942_PRF) + #include <botan/prf_x942.h> #endif -#ifdef BOTAN_HAS_SSL_V3_PRF - #include <botan/prf_ssl3.h> +#if defined(BOTAN_HAS_SSL_V3_PRF) + #include <botan/prf_ssl3.h> #endif -#ifdef BOTAN_HAS_TLS_V10_PRF - #include <botan/prf_tls.h> +#if defined(BOTAN_HAS_TLS_V10_PRF) + #include <botan/prf_tls.h> #endif namespace Botan { @@ -67,7 +67,7 @@ EMSA* get_emsa(const std::string& algo_spec) std::vector<std::string> name = parse_algorithm_name(algo_spec); const std::string emsa_name = global_state().deref_alias(name[0]); -#ifdef BOTAN_HAS_EMSA_RAW +#if defined(BOTAN_HAS_EMSA_RAW) if(emsa_name == "Raw") { if(name.size() == 1) @@ -75,7 +75,7 @@ EMSA* get_emsa(const std::string& algo_spec) } #endif -#ifdef BOTAN_HAS_EMSA1 +#if defined(BOTAN_HAS_EMSA1) if(emsa_name == "EMSA1") { if(name.size() == 2) @@ -83,7 +83,7 @@ EMSA* get_emsa(const std::string& algo_spec) } #endif -#ifdef BOTAN_HAS_EMSA2 +#if defined(BOTAN_HAS_EMSA2) if(emsa_name == "EMSA2") { if(name.size() == 2) @@ -91,7 +91,7 @@ EMSA* get_emsa(const std::string& algo_spec) } #endif -#ifdef BOTAN_HAS_EMSA3 +#if defined(BOTAN_HAS_EMSA3) if(emsa_name == "EMSA3") { if(name.size() == 2) @@ -99,7 +99,7 @@ EMSA* get_emsa(const std::string& algo_spec) } #endif -#ifdef BOTAN_HAS_EMSA4 +#if defined(BOTAN_HAS_EMSA4) if(emsa_name == "EMSA4") { if(name.size() == 2) @@ -122,7 +122,7 @@ EME* get_eme(const std::string& algo_spec) std::vector<std::string> name = parse_algorithm_name(algo_spec); const std::string eme_name = global_state().deref_alias(name[0]); -#ifdef BOTAN_HAS_EME_PKCS1v15 +#if defined(BOTAN_HAS_EME_PKCS1v15) if(eme_name == "PKCS1v15") { if(name.size() == 1) @@ -130,7 +130,7 @@ EME* get_eme(const std::string& algo_spec) } #endif -#ifdef BOTAN_HAS_EME1 +#if defined(BOTAN_HAS_EME1) if(eme_name == "EME1") { if(name.size() == 2) @@ -151,7 +151,7 @@ KDF* get_kdf(const std::string& algo_spec) std::vector<std::string> name = parse_algorithm_name(algo_spec); const std::string kdf_name = global_state().deref_alias(name[0]); -#ifdef BOTAN_HAS_KDF1 +#if defined(BOTAN_HAS_KDF1) if(kdf_name == "KDF1") { if(name.size() == 2) @@ -159,7 +159,7 @@ KDF* get_kdf(const std::string& algo_spec) } #endif -#ifdef BOTAN_HAS_KDF2 +#if defined(BOTAN_HAS_KDF2) if(kdf_name == "KDF2") { if(name.size() == 2) @@ -167,7 +167,7 @@ KDF* get_kdf(const std::string& algo_spec) } #endif -#ifdef BOTAN_HAS_X942_PRF +#if defined(BOTAN_HAS_X942_PRF) if(kdf_name == "X9.42-PRF") { if(name.size() == 2) @@ -175,7 +175,7 @@ KDF* get_kdf(const std::string& algo_spec) } #endif -#ifdef BOTAN_HAS_TLS_V10_PRF +#if defined(BOTAN_HAS_TLS_V10_PRF) if(kdf_name == "TLS-PRF") { if(name.size() == 1) @@ -183,7 +183,7 @@ KDF* get_kdf(const std::string& algo_spec) } #endif -#ifdef BOTAN_HAS_SSL_V3_PRF +#if defined(BOTAN_HAS_SSL_V3_PRF) if(kdf_name == "SSL3-PRF") { if(name.size() == 1) diff --git a/src/randpool.cpp b/src/randpool.cpp deleted file mode 100644 index 69ef3b9e7..000000000 --- a/src/randpool.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/************************************************* -* Randpool Source File * -* (C) 1999-2008 Jack Lloyd * -*************************************************/ - -#include <botan/randpool.h> -#include <botan/lookup.h> -#include <botan/loadstor.h> -#include <botan/xor_buf.h> -#include <botan/util.h> -#include <botan/stl_util.h> -#include <algorithm> - -namespace Botan { - -namespace { - -/************************************************* -* PRF based on a MAC * -*************************************************/ -enum RANDPOOL_PRF_TAG { - CIPHER_KEY = 0, - MAC_KEY = 1, - GEN_OUTPUT = 2 -}; - -} - -/************************************************* -* Generate a buffer of random bytes * -*************************************************/ -void Randpool::randomize(byte out[], u32bit length) - { - if(!is_seeded()) - { - reseed(); - - if(!is_seeded()) - throw PRNG_Unseeded(name()); - } - - update_buffer(); - while(length) - { - const u32bit copied = std::min(length, buffer.size()); - copy_mem(out, buffer.begin(), copied); - out += copied; - length -= copied; - update_buffer(); - } - } - -/************************************************* -* Refill the output buffer * -*************************************************/ -void Randpool::update_buffer() - { - const u64bit timestamp = system_time(); - - for(u32bit j = 0; j != counter.size(); ++j) - if(++counter[j]) - break; - store_be(timestamp, counter + 4); - - mac->update(static_cast<byte>(GEN_OUTPUT)); - mac->update(counter, counter.size()); - SecureVector<byte> mac_val = mac->final(); - - for(u32bit j = 0; j != mac_val.size(); ++j) - buffer[j % buffer.size()] ^= mac_val[j]; - cipher->encrypt(buffer); - - if(counter[0] % ITERATIONS_BEFORE_RESEED == 0) - mix_pool(); - } - -/************************************************* -* Mix the entropy pool * -*************************************************/ -void Randpool::mix_pool() - { - const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE; - - mac->update(static_cast<byte>(MAC_KEY)); - mac->update(pool, pool.size()); - mac->set_key(mac->final()); - - mac->update(static_cast<byte>(CIPHER_KEY)); - mac->update(pool, pool.size()); - cipher->set_key(mac->final()); - - xor_buf(pool, buffer, BLOCK_SIZE); - cipher->encrypt(pool); - for(u32bit j = 1; j != POOL_BLOCKS; ++j) - { - const byte* previous_block = pool + BLOCK_SIZE*(j-1); - byte* this_block = pool + BLOCK_SIZE*j; - xor_buf(this_block, previous_block, BLOCK_SIZE); - cipher->encrypt(this_block); - } - - update_buffer(); - } - -/************************************************* -* Reseed the internal state * -*************************************************/ -void Randpool::reseed() - { - SecureVector<byte> buffer(1024); - u32bit gathered_entropy = 0; - - for(u32bit j = 0; j != entropy_sources.size(); ++j) - { - u32bit got = entropy_sources[j]->slow_poll(buffer, buffer.size()); - - mac->update(buffer, got); - - gathered_entropy += entropy_estimate(buffer, got); - if(gathered_entropy > 512) - break; - } - - SecureVector<byte> mac_val = mac->final(); - xor_buf(pool, mac_val, mac_val.size()); - mix_pool(); - - entropy += gathered_entropy; - } - -/************************************************* -* Add user-supplied entropy * -*************************************************/ -void Randpool::add_entropy(const byte input[], u32bit length) - { - SecureVector<byte> mac_val = mac->process(input, length); - xor_buf(pool, mac_val, mac_val.size()); - mix_pool(); - - entropy += entropy_estimate(input, length); - } - -/************************************************* -* Add another entropy source to the list * -*************************************************/ -void Randpool::add_entropy_source(EntropySource* src) - { - entropy_sources.push_back(src); - } - -/************************************************* -* Check if the the pool is seeded * -*************************************************/ -bool Randpool::is_seeded() const - { - return (entropy >= 384); - } - -/************************************************* -* Clear memory of sensitive data * -*************************************************/ -void Randpool::clear() throw() - { - cipher->clear(); - mac->clear(); - pool.clear(); - buffer.clear(); - counter.clear(); - entropy = 0; - } - -/************************************************* -* Return the name of this type * -*************************************************/ -std::string Randpool::name() const - { - return "Randpool(" + cipher->name() + "," + mac->name() + ")"; - } - -/************************************************* -* Randpool Constructor * -*************************************************/ -Randpool::Randpool(const std::string& cipher_name, - const std::string& mac_name) : - ITERATIONS_BEFORE_RESEED(128), POOL_BLOCKS(32) - { - cipher = get_block_cipher(cipher_name); - mac = get_mac(mac_name); - - const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE; - const u32bit OUTPUT_LENGTH = mac->OUTPUT_LENGTH; - - if(OUTPUT_LENGTH < BLOCK_SIZE || - !cipher->valid_keylength(OUTPUT_LENGTH) || - !mac->valid_keylength(OUTPUT_LENGTH)) - { - delete cipher; - delete mac; - throw Internal_Error("Randpool: Invalid algorithm combination " + - cipher_name + "/" + mac_name); - } - - buffer.create(BLOCK_SIZE); - pool.create(POOL_BLOCKS * BLOCK_SIZE); - counter.create(12); - entropy = 0; - } - -/************************************************* -* Randpool Destructor * -*************************************************/ -Randpool::~Randpool() - { - delete cipher; - delete mac; - - std::for_each(entropy_sources.begin(), entropy_sources.end(), - del_fun<EntropySource>()); - - entropy = 0; - } - -} diff --git a/src/rng.cpp b/src/rng.cpp index 3d13533ab..9bed40dc1 100644 --- a/src/rng.cpp +++ b/src/rng.cpp @@ -4,12 +4,18 @@ *************************************************/ #include <botan/rng.h> -#include <botan/randpool.h> -#include <botan/x931_rng.h> #include <botan/util.h> #include <botan/parsing.h> #include <botan/timers.h> +#if defined(BOTAN_HAS_RANDPOOL) + #include <botan/randpool.h> +#endif + +#if defined(BOTAN_HAS_X931_RNG) + #include <botan/x931_rng.h> +#endif + #if defined(BOTAN_HAS_TIMER_HARDWARE) #include <botan/tm_hard.h> #elif defined(BOTAN_HAS_TIMER_POSIX) @@ -73,9 +79,14 @@ byte RandomNumberGenerator::next_byte() *************************************************/ RandomNumberGenerator* RandomNumberGenerator::make_rng() { - RandomNumberGenerator* rng = - new ANSI_X931_RNG("AES-256", - new Randpool("AES-256", "HMAC(SHA-256)")); + RandomNumberGenerator* rng = 0; + +#if defined(BOTAN_HAS_RANDPOOL) + rng = new Randpool("AES-256", "HMAC(SHA-256)"); + +#if defined(BOTAN_HAS_X931_RNG) + rng = new ANSI_X931_RNG("AES-256", rng); +#endif #if defined(BOTAN_HAS_TIMER_HARDWARE) rng->add_entropy_source(new Hardware_Timer); @@ -125,6 +136,8 @@ RandomNumberGenerator* RandomNumberGenerator::make_rng() rng->add_entropy_source(new FTW_EntropySource("/proc")); #endif +#endif + return rng; } diff --git a/src/x931_rng.cpp b/src/x931_rng.cpp deleted file mode 100644 index f4b0f71a9..000000000 --- a/src/x931_rng.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/************************************************* -* ANSI X9.31 RNG Source File * -* (C) 1999-2008 Jack Lloyd * -*************************************************/ - -#include <botan/x931_rng.h> -#include <botan/lookup.h> -#include <botan/xor_buf.h> -#include <algorithm> - -namespace Botan { - -/************************************************* -* Generate a buffer of random bytes * -*************************************************/ -void ANSI_X931_RNG::randomize(byte out[], u32bit length) - { - if(!is_seeded()) - reseed(); - - while(length) - { - if(position == R.size()) - update_buffer(); - - const u32bit copied = std::min(length, R.size() - position); - - copy_mem(out, R + position, copied); - out += copied; - length -= copied; - position += copied; - } - } - -/************************************************* -* Refill the internal state * -*************************************************/ -void ANSI_X931_RNG::update_buffer() - { - SecureVector<byte> DT(cipher->BLOCK_SIZE); - - prng->randomize(DT, DT.size()); - cipher->encrypt(DT); - - xor_buf(R, V, DT, cipher->BLOCK_SIZE); - cipher->encrypt(R); - - xor_buf(V, R, DT, cipher->BLOCK_SIZE); - cipher->encrypt(V); - - position = 0; - } - -/************************************************* -* Reseed the internal state * -*************************************************/ -void ANSI_X931_RNG::reseed() - { - prng->reseed(); - - SecureVector<byte> key(cipher->MAXIMUM_KEYLENGTH); - prng->randomize(key, key.size()); - cipher->set_key(key, key.size()); - - if(V.size() != cipher->BLOCK_SIZE) - V.create(cipher->BLOCK_SIZE); - prng->randomize(V, V.size()); - - update_buffer(); - } - -/************************************************* -* Add a entropy source to the underlying PRNG * -*************************************************/ -void ANSI_X931_RNG::add_entropy_source(EntropySource* src) - { - prng->add_entropy_source(src); - } - -/************************************************* -* Add some entropy to the underlying PRNG * -*************************************************/ -void ANSI_X931_RNG::add_entropy(const byte input[], u32bit length) - { - prng->add_entropy(input, length); - } - -/************************************************* -* Check if the the PRNG is seeded * -*************************************************/ -bool ANSI_X931_RNG::is_seeded() const - { - return V.has_items(); - } - -/************************************************* -* Clear memory of sensitive data * -*************************************************/ -void ANSI_X931_RNG::clear() throw() - { - cipher->clear(); - prng->clear(); - R.clear(); - V.destroy(); - - position = 0; - } - -/************************************************* -* Return the name of this type * -*************************************************/ -std::string ANSI_X931_RNG::name() const - { - return "X9.31(" + cipher->name() + ")"; - } - -/************************************************* -* ANSI X931 RNG Constructor * -*************************************************/ -ANSI_X931_RNG::ANSI_X931_RNG(const std::string& cipher_name, - RandomNumberGenerator* prng_ptr) - { - if(!prng_ptr) - throw Invalid_Argument("ANSI_X931_RNG constructor: NULL prng"); - - prng = prng_ptr; - cipher = get_block_cipher(cipher_name); - - R.create(cipher->BLOCK_SIZE); - position = 0; - } - -/************************************************* -* ANSI X931 RNG Destructor * -*************************************************/ -ANSI_X931_RNG::~ANSI_X931_RNG() - { - delete cipher; - delete prng; - } - -} |