diff options
author | lloyd <[email protected]> | 2008-09-30 04:35:34 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-30 04:35:34 +0000 |
commit | 3c55f159b8e2ff80c0f0ab0820de0afc414be7db (patch) | |
tree | 6370650255987e8df89b8ef90f46a5eec92b70ed /src/core | |
parent | eee6e1e1ec225c3301cef6839225317a8cc9cf4a (diff) |
Split off part of the core module into libstate (basically the whole
lookup/global_state piece).
Move timer and mutex directories into utils/
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/info.txt | 42 | ||||
-rw-r--r-- | src/core/libstate/def_alg.cpp (renamed from src/core/def_alg.cpp) | 0 | ||||
-rw-r--r-- | src/core/libstate/def_mode.cpp (renamed from src/core/def_mode.cpp) | 0 | ||||
-rw-r--r-- | src/core/libstate/eng_base.cpp (renamed from src/core/eng_base.cpp) | 0 | ||||
-rw-r--r-- | src/core/libstate/engine.cpp (renamed from src/core/engine.cpp) | 0 | ||||
-rw-r--r-- | src/core/libstate/engine.h (renamed from src/core/engine.h) | 0 | ||||
-rw-r--r-- | src/core/libstate/get_enc.cpp (renamed from src/core/get_enc.cpp) | 0 | ||||
-rw-r--r-- | src/core/libstate/get_pbe.cpp (renamed from src/core/get_pbe.cpp) | 0 | ||||
-rw-r--r-- | src/core/libstate/get_pbe.h (renamed from src/core/get_pbe.h) | 0 | ||||
-rw-r--r-- | src/core/libstate/info.txt | 34 | ||||
-rw-r--r-- | src/core/libstate/init.h (renamed from src/core/init.h) | 0 | ||||
-rw-r--r-- | src/core/libstate/init_def.cpp (renamed from src/core/init_def.cpp) | 0 | ||||
-rw-r--r-- | src/core/libstate/init_opt.cpp (renamed from src/core/init_opt.cpp) | 0 | ||||
-rw-r--r-- | src/core/libstate/libstate.cpp (renamed from src/core/libstate.cpp) | 0 | ||||
-rw-r--r-- | src/core/libstate/libstate.h (renamed from src/core/libstate.h) | 0 | ||||
-rw-r--r-- | src/core/libstate/look_add.h (renamed from src/core/look_add.h) | 0 | ||||
-rw-r--r-- | src/core/libstate/look_pk.cpp (renamed from src/core/look_pk.cpp) | 0 | ||||
-rw-r--r-- | src/core/libstate/look_pk.h (renamed from src/core/look_pk.h) | 0 | ||||
-rw-r--r-- | src/core/libstate/lookup.cpp (renamed from src/core/lookup.cpp) | 0 | ||||
-rw-r--r-- | src/core/libstate/lookup.h (renamed from src/core/lookup.h) | 0 | ||||
-rw-r--r-- | src/core/libstate/oids.cpp (renamed from src/core/oids.cpp) | 0 | ||||
-rw-r--r-- | src/core/libstate/oids.h (renamed from src/core/oids.h) | 0 | ||||
-rw-r--r-- | src/core/libstate/policy.cpp (renamed from src/core/policy.cpp) | 0 | ||||
-rw-r--r-- | src/core/selftest/info.txt | 24 | ||||
-rw-r--r-- | src/core/selftest/selftest.cpp | 163 | ||||
-rw-r--r-- | src/core/selftest/selftest.h | 20 |
26 files changed, 252 insertions, 31 deletions
diff --git a/src/core/info.txt b/src/core/info.txt index 681f72379..3a9f9f34f 100644 --- a/src/core/info.txt +++ b/src/core/info.txt @@ -11,54 +11,34 @@ sha2 hmac allocators filters +libstate timer_base </requires> <add> base.cpp -data_src.cpp -datastor.cpp -def_alg.cpp -def_mode.cpp -def_powm.cpp -eng_base.cpp -engine.cpp -exceptn.cpp -get_enc.cpp -get_pbe.cpp -init_def.cpp -init_opt.cpp -kdf.cpp -libstate.cpp -look_pk.cpp -lookup.cpp -modules.cpp -oids.cpp -pk_pad.cpp -policy.cpp -rng.cpp -s2k.cpp -symkey.cpp base.h botan.h +data_src.cpp data_src.h +datastor.cpp datastor.h +def_powm.cpp eng_def.h -engine.h enums.h +exceptn.cpp exceptn.h -init.h +kdf.cpp kdf.h -libstate.h -look_add.h -look_pk.h -get_pbe.h -lookup.h +modules.cpp modules.h mutex.h -oids.h +pk_pad.cpp pk_pad.h +rng.cpp rng.h +s2k.cpp s2k.h +symkey.cpp symkey.h </add> diff --git a/src/core/def_alg.cpp b/src/core/libstate/def_alg.cpp index cad5dca5a..cad5dca5a 100644 --- a/src/core/def_alg.cpp +++ b/src/core/libstate/def_alg.cpp diff --git a/src/core/def_mode.cpp b/src/core/libstate/def_mode.cpp index b062cc34b..b062cc34b 100644 --- a/src/core/def_mode.cpp +++ b/src/core/libstate/def_mode.cpp diff --git a/src/core/eng_base.cpp b/src/core/libstate/eng_base.cpp index 38234d462..38234d462 100644 --- a/src/core/eng_base.cpp +++ b/src/core/libstate/eng_base.cpp diff --git a/src/core/engine.cpp b/src/core/libstate/engine.cpp index 804ab3580..804ab3580 100644 --- a/src/core/engine.cpp +++ b/src/core/libstate/engine.cpp diff --git a/src/core/engine.h b/src/core/libstate/engine.h index 13007e662..13007e662 100644 --- a/src/core/engine.h +++ b/src/core/libstate/engine.h diff --git a/src/core/get_enc.cpp b/src/core/libstate/get_enc.cpp index fb5952a3e..fb5952a3e 100644 --- a/src/core/get_enc.cpp +++ b/src/core/libstate/get_enc.cpp diff --git a/src/core/get_pbe.cpp b/src/core/libstate/get_pbe.cpp index cd1ed2aa4..cd1ed2aa4 100644 --- a/src/core/get_pbe.cpp +++ b/src/core/libstate/get_pbe.cpp diff --git a/src/core/get_pbe.h b/src/core/libstate/get_pbe.h index e7b434c1f..e7b434c1f 100644 --- a/src/core/get_pbe.h +++ b/src/core/libstate/get_pbe.h diff --git a/src/core/libstate/info.txt b/src/core/libstate/info.txt new file mode 100644 index 000000000..f0040a688 --- /dev/null +++ b/src/core/libstate/info.txt @@ -0,0 +1,34 @@ +realname "Botan Core Module" + +load_on auto + +define CORE_MODULE + +<requires> +aes +sha1 +</requires> + +<add> +def_alg.cpp +def_mode.cpp +eng_base.cpp +engine.cpp +get_enc.cpp +get_pbe.cpp +init.h +init_def.cpp +init_opt.cpp +libstate.cpp +look_pk.cpp +lookup.cpp +oids.cpp +policy.cpp +engine.h +get_pbe.h +libstate.h +look_add.h +look_pk.h +lookup.h +oids.h +</add> diff --git a/src/core/init.h b/src/core/libstate/init.h index f4296a868..f4296a868 100644 --- a/src/core/init.h +++ b/src/core/libstate/init.h diff --git a/src/core/init_def.cpp b/src/core/libstate/init_def.cpp index 03f97252e..03f97252e 100644 --- a/src/core/init_def.cpp +++ b/src/core/libstate/init_def.cpp diff --git a/src/core/init_opt.cpp b/src/core/libstate/init_opt.cpp index 5c4fbee65..5c4fbee65 100644 --- a/src/core/init_opt.cpp +++ b/src/core/libstate/init_opt.cpp diff --git a/src/core/libstate.cpp b/src/core/libstate/libstate.cpp index 60bb24fee..60bb24fee 100644 --- a/src/core/libstate.cpp +++ b/src/core/libstate/libstate.cpp diff --git a/src/core/libstate.h b/src/core/libstate/libstate.h index 4b1221c84..4b1221c84 100644 --- a/src/core/libstate.h +++ b/src/core/libstate/libstate.h diff --git a/src/core/look_add.h b/src/core/libstate/look_add.h index 8c170049d..8c170049d 100644 --- a/src/core/look_add.h +++ b/src/core/libstate/look_add.h diff --git a/src/core/look_pk.cpp b/src/core/libstate/look_pk.cpp index a4062b57c..a4062b57c 100644 --- a/src/core/look_pk.cpp +++ b/src/core/libstate/look_pk.cpp diff --git a/src/core/look_pk.h b/src/core/libstate/look_pk.h index 63756ad22..63756ad22 100644 --- a/src/core/look_pk.h +++ b/src/core/libstate/look_pk.h diff --git a/src/core/lookup.cpp b/src/core/libstate/lookup.cpp index 8e65afb93..8e65afb93 100644 --- a/src/core/lookup.cpp +++ b/src/core/libstate/lookup.cpp diff --git a/src/core/lookup.h b/src/core/libstate/lookup.h index 016ad4618..016ad4618 100644 --- a/src/core/lookup.h +++ b/src/core/libstate/lookup.h diff --git a/src/core/oids.cpp b/src/core/libstate/oids.cpp index 0823625ea..0823625ea 100644 --- a/src/core/oids.cpp +++ b/src/core/libstate/oids.cpp diff --git a/src/core/oids.h b/src/core/libstate/oids.h index b5be0e01f..b5be0e01f 100644 --- a/src/core/oids.h +++ b/src/core/libstate/oids.h diff --git a/src/core/policy.cpp b/src/core/libstate/policy.cpp index 39810760b..39810760b 100644 --- a/src/core/policy.cpp +++ b/src/core/libstate/policy.cpp diff --git a/src/core/selftest/info.txt b/src/core/selftest/info.txt new file mode 100644 index 000000000..e786437d5 --- /dev/null +++ b/src/core/selftest/info.txt @@ -0,0 +1,24 @@ +realname "Selftests" + +define SELFTESTS + +load_on auto + +<add> +selftest.cpp +selftest.h +</add> + +<requires> +hex +des +aes +sha1 +sha2 +hmac +ecb +cbc +cfb +ofb +ctr +</requires> diff --git a/src/core/selftest/selftest.cpp b/src/core/selftest/selftest.cpp new file mode 100644 index 000000000..0dede1c9d --- /dev/null +++ b/src/core/selftest/selftest.cpp @@ -0,0 +1,163 @@ +/************************************************* +* Startup Self Tests Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include <botan/selftest.h> +#include <botan/libstate.h> +#include <botan/lookup.h> + +namespace Botan { + +namespace { + +/************************************************* +* Perform a Known Answer Test * +*************************************************/ +void do_kat(const std::string& in, const std::string& out, + const std::string& algo_name, Filter* filter) + { + if(out.length()) + { + Pipe pipe(new Hex_Decoder, filter, new Hex_Encoder); + pipe.process_msg(in); + + if(out != pipe.read_all_as_string()) + throw Self_Test_Failure("FIPS-140 " + algo_name + " test"); + } + } + +/************************************************* +* Perform a KAT for a cipher * +*************************************************/ +void cipher_kat(const std::string& in, const std::string& out, + const std::string& key, const std::string& iv, + const std::string& cipher) + { + do_kat(in, out, cipher, + get_cipher(global_state(), cipher, key, iv, ENCRYPTION)); + do_kat(out, in, cipher, + get_cipher(global_state(), cipher, key, iv, DECRYPTION)); + } + +/************************************************* +* Perform a KAT for a cipher * +*************************************************/ +void cipher_kat(const std::string& cipher, const std::string& key, + const std::string& iv, const std::string& in, + const std::string& ecb_out, const std::string& cbc_out, + const std::string& cfb_out, const std::string& ofb_out, + const std::string& ctr_out) + { + if(!have_block_cipher(cipher)) + return; + + cipher_kat(in, ecb_out, key, "", cipher + "/ECB"); + cipher_kat(in, cbc_out, key, iv, cipher + "/CBC/NoPadding"); + cipher_kat(in, cfb_out, key, iv, cipher + "/CFB"); + cipher_kat(in, ofb_out, key, iv, cipher + "/OFB"); + cipher_kat(in, ctr_out, key, iv, cipher + "/CTR-BE"); + } + +/************************************************* +* Perform a KAT for a hash * +*************************************************/ +void hash_kat(const std::string& hash, const std::string& in, + const std::string& out) + { + if(!have_hash(hash)) + return; + do_kat(in, out, hash, new Hash_Filter(hash)); + } + +/************************************************* +* Perform a KAT for a MAC * +*************************************************/ +void mac_kat(const std::string& mac, const std::string& in, + const std::string& out, const std::string& key) + { + if(!have_mac(mac)) + return; + do_kat(in, out, mac, new MAC_Filter(mac, key)); + } + +} + +/************************************************* +* Perform FIPS 140 Self Tests * +*************************************************/ +bool passes_self_tests() + { + try { + cipher_kat("DES", "0123456789ABCDEF", "1234567890ABCDEF", + "4E6F77206973207468652074696D6520666F7220616C6C20", + "3FA40E8A984D48156A271787AB8883F9893D51EC4B563B53", + "E5C7CDDE872BF27C43E934008C389C0F683788499A7C05F6", + "F3096249C7F46E51A69E839B1A92F78403467133898EA622", + "F3096249C7F46E5135F24A242EEB3D3F3D6D5BE3255AF8C3", + "F3096249C7F46E51163A8CA0FFC94C27FA2F80F480B86F75"); + + cipher_kat("TripleDES", + "385D7189A5C3D485E1370AA5D408082B5CCCCB5E19F2D90E", + "C141B5FCCD28DC8A", + "6E1BD7C6120947A464A6AAB293A0F89A563D8D40D3461B68", + "64EAAD4ACBB9CEAD6C7615E7C7E4792FE587D91F20C7D2F4", + "6235A461AFD312973E3B4F7AA7D23E34E03371F8E8C376C9", + "E26BA806A59B0330DE40CA38E77A3E494BE2B212F6DD624B", + "E26BA806A59B03307DE2BCC25A08BA40A8BA335F5D604C62", + "E26BA806A59B03303C62C2EFF32D3ACDD5D5F35EBCC53371"); + + cipher_kat("AES", + "2B7E151628AED2A6ABF7158809CF4F3C", + "000102030405060708090A0B0C0D0E0F", + "6BC1BEE22E409F96E93D7E117393172A" + "AE2D8A571E03AC9C9EB76FAC45AF8E51", + "3AD77BB40D7A3660A89ECAF32466EF97" + "F5D3D58503B9699DE785895A96FDBAAF", + "7649ABAC8119B246CEE98E9B12E9197D" + "5086CB9B507219EE95DB113A917678B2", + "3B3FD92EB72DAD20333449F8E83CFB4A" + "C8A64537A0B3A93FCDE3CDAD9F1CE58B", + "3B3FD92EB72DAD20333449F8E83CFB4A" + "7789508D16918F03F53C52DAC54ED825", + "3B3FD92EB72DAD20333449F8E83CFB4A" + "010C041999E03F36448624483E582D0E"); + + hash_kat("SHA-1", "", "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709"); + hash_kat("SHA-1", "616263", "A9993E364706816ABA3E25717850C26C9CD0D89D"); + hash_kat("SHA-1", + "6162636462636465636465666465666765666768666768696768696A" + "68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F7071", + "84983E441C3BD26EBAAE4AA1F95129E5E54670F1"); + + hash_kat("SHA-256", "", + "E3B0C44298FC1C149AFBF4C8996FB924" + "27AE41E4649B934CA495991B7852B855"); + hash_kat("SHA-256", "616263", + "BA7816BF8F01CFEA414140DE5DAE2223" + "B00361A396177A9CB410FF61F20015AD"); + hash_kat("SHA-256", + "6162636462636465636465666465666765666768666768696768696A" + "68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F7071", + "248D6A61D20638B8E5C026930C3E6039" + "A33CE45964FF2167F6ECEDD419DB06C1"); + + mac_kat("HMAC(SHA-1)", "4869205468657265", + "B617318655057264E28BC0B6FB378C8EF146BE00", + "0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B"); + + mac_kat("HMAC(SHA-256)", "4869205468657265", + "198A607EB44BFBC69903A0F1CF2BBDC5" + "BA0AA3F3D9AE3C1C7A3B1696A0B68CF7", + "0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B" + "0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B"); + } + catch(std::exception& e) + { + return false; + } + + return true; + } + +} diff --git a/src/core/selftest/selftest.h b/src/core/selftest/selftest.h new file mode 100644 index 000000000..ff011a32c --- /dev/null +++ b/src/core/selftest/selftest.h @@ -0,0 +1,20 @@ +/************************************************* +* Startup Self Test Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_SELF_TEST_H__ +#define BOTAN_SELF_TEST_H__ + +#include <botan/base.h> + +namespace Botan { + +/************************************************* +* Self Tests * +*************************************************/ +BOTAN_DLL bool passes_self_tests(); + +} + +#endif |