From cdeb2b9a08c9c55a0e1c310253797691af225523 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 20 Apr 2012 16:48:27 +0000 Subject: Some fixes for very minimal builds (typically due to --no-autoload) --- checks/pk.cpp | 6 ++++++ checks/pk_bench.cpp | 6 ++++++ checks/validate.cpp | 2 ++ 3 files changed, 14 insertions(+) (limited to 'checks') diff --git a/checks/pk.cpp b/checks/pk.cpp index 6291b1566..d45fc59fe 100644 --- a/checks/pk.cpp +++ b/checks/pk.cpp @@ -14,6 +14,12 @@ #include #include +#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO) + #include + #include + #include +#endif + #if defined(BOTAN_HAS_RSA) #include #endif diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp index de8ad0730..682efc043 100644 --- a/checks/pk_bench.cpp +++ b/checks/pk_bench.cpp @@ -10,6 +10,12 @@ #include #include +#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO) + #include + #include + #include +#endif + #if defined(BOTAN_HAS_RSA) #include #endif diff --git a/checks/validate.cpp b/checks/validate.cpp index 65317604e..3de081d56 100644 --- a/checks/validate.cpp +++ b/checks/validate.cpp @@ -110,6 +110,7 @@ bool keywrap_test(const char* key_str, bool ok = true; +#if defined(BOTAN_HAS_RFC3394_KEYWRAP) try { SymmetricKey key(key_str); @@ -140,6 +141,7 @@ bool keywrap_test(const char* key_str, { std::cout << e.what() << "\n"; } +#endif return ok; } -- cgit v1.2.3 From cd82d3641c891ef6e446cdfe584dbd936f6a564d Mon Sep 17 00:00:00 2001 From: lloyd Date: Mon, 23 Apr 2012 13:16:49 +0000 Subject: Fix various typos, and remove an unused macro in checks/bench.cpp All reported by Patrick Pelletier. --- checks/bench.cpp | 12 ------------ checks/validate.cpp | 2 +- src/cert/cvc/cvc_req.h | 2 +- src/engine/asm_engine/asm_engine.h | 2 +- src/engine/core_engine/core_engine.h | 4 ++-- src/engine/openssl/ossl_arc4.cpp | 2 +- src/engine/simd_engine/simd_engine.h | 2 +- src/libstate/init.cpp | 2 +- 8 files changed, 8 insertions(+), 20 deletions(-) (limited to 'checks') diff --git a/checks/bench.cpp b/checks/bench.cpp index e9eb92199..21b568902 100644 --- a/checks/bench.cpp +++ b/checks/bench.cpp @@ -150,18 +150,6 @@ void report_results(const std::string& algo, std::cout << algo; -#if defined(__SUNPRO_CC) - #define REVERSE_ITERATOR_BUG 1 -#elif defined(__GNUC__) && __GNUC__ <= 3 - #define REVERSE_ITERATOR_BUG 1 -#elif defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 0) - #define REVERSE_ITERATOR_BUG 1 -#endif - -#ifndef REVERSE_ITERATOR_BUG - #define REVERSE_ITERATOR_BUG 0 -#endif - #if (defined(__GNUC__) && __GNUC__ <= 3) || defined(__SUNPRO_CC) // Work around GCC 3.x bug, reverse iterators don't work for(std::map::const_iterator i = results.begin(); i != results.end(); ++i) diff --git a/checks/validate.cpp b/checks/validate.cpp index 3de081d56..2bb099030 100644 --- a/checks/validate.cpp +++ b/checks/validate.cpp @@ -341,7 +341,7 @@ u32bit do_validation_tests(const std::string& filename, if(should_pass) std::cout << "Testing " << algorithm << "..." << std::endl; else - std::cout << "Testing (expecing failure) " + std::cout << "Testing (expecting failure) " << algorithm << "..." << std::endl; #endif alg_count = 0; diff --git a/src/cert/cvc/cvc_req.h b/src/cert/cvc/cvc_req.h index 1e8cea7f8..ac4e22453 100644 --- a/src/cert/cvc/cvc_req.h +++ b/src/cert/cvc/cvc_req.h @@ -35,7 +35,7 @@ class BOTAN_DLL EAC1_1_Req : public EAC1_1_gen_CVC EAC1_1_Req(DataSource& source); /** - * Construct a CVC request from a DER encoded CVC reqeust file. + * Construct a CVC request from a DER encoded CVC request file. * @param str the path to the DER encoded file */ EAC1_1_Req(const std::string& str); diff --git a/src/engine/asm_engine/asm_engine.h b/src/engine/asm_engine/asm_engine.h index bd82566d3..40fe5342f 100644 --- a/src/engine/asm_engine/asm_engine.h +++ b/src/engine/asm_engine/asm_engine.h @@ -23,7 +23,7 @@ class Assembler_Engine : public Engine BlockCipher* find_block_cipher(const SCAN_Name&, Algorithm_Factory&) const; - HashFunction* find_hash(const SCAN_Name& reqeust, + HashFunction* find_hash(const SCAN_Name& request, Algorithm_Factory&) const; }; diff --git a/src/engine/core_engine/core_engine.h b/src/engine/core_engine/core_engine.h index 5386991c3..983b75290 100644 --- a/src/engine/core_engine/core_engine.h +++ b/src/engine/core_engine/core_engine.h @@ -44,10 +44,10 @@ class Core_Engine : public Engine StreamCipher* find_stream_cipher(const SCAN_Name&, Algorithm_Factory&) const; - HashFunction* find_hash(const SCAN_Name& reqeust, + HashFunction* find_hash(const SCAN_Name& request, Algorithm_Factory&) const; - MessageAuthenticationCode* find_mac(const SCAN_Name& reqeust, + MessageAuthenticationCode* find_mac(const SCAN_Name& request, Algorithm_Factory&) const; PBKDF* find_pbkdf(const SCAN_Name& algo_spec, diff --git a/src/engine/openssl/ossl_arc4.cpp b/src/engine/openssl/ossl_arc4.cpp index 0b1f7f1f3..0c524003d 100644 --- a/src/engine/openssl/ossl_arc4.cpp +++ b/src/engine/openssl/ossl_arc4.cpp @@ -71,7 +71,7 @@ void ARC4_OpenSSL::cipher(const byte in[], byte out[], size_t length) } /** -* Look for an OpenSSL-suported stream cipher (ARC4) +* Look for an OpenSSL-supported stream cipher (ARC4) */ StreamCipher* OpenSSL_Engine::find_stream_cipher(const SCAN_Name& request, diff --git a/src/engine/simd_engine/simd_engine.h b/src/engine/simd_engine/simd_engine.h index 73f7d2233..66c8886f1 100644 --- a/src/engine/simd_engine/simd_engine.h +++ b/src/engine/simd_engine/simd_engine.h @@ -23,7 +23,7 @@ class SIMD_Engine : public Engine BlockCipher* find_block_cipher(const SCAN_Name&, Algorithm_Factory&) const; - HashFunction* find_hash(const SCAN_Name& reqeust, + HashFunction* find_hash(const SCAN_Name& request, Algorithm_Factory&) const; }; diff --git a/src/libstate/init.cpp b/src/libstate/init.cpp index 7cdc615bd..6d1ca1dbc 100644 --- a/src/libstate/init.cpp +++ b/src/libstate/init.cpp @@ -51,7 +51,7 @@ void LibraryInitializer::initialize(const std::string& arg_string) /* This two stage initialization process is because Library_State's constructor will implicitly refer to global state through the - allocators and so for, so global_state() has to be a valid + allocators and so forth, so global_state() has to be a valid reference before initialize() can be called. Yeah, gross. */ Global_State_Management::set_global_state(new Library_State); -- cgit v1.2.3 From 25f329b8a45b6f84f9a01a0326db48f6853dc59c Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 24 Apr 2012 20:09:51 +0000 Subject: Patrick Pelletier noted on the mailing list that the implementation of Camellia exposed by the OpenSSL module is parameterized by the key length, much as AES is, while the version in the main source uses a single name/type for all variants. For consistency, convert to using a key length parameterized name in our version as well. In the future this might allow for better loop unrolling, etc but currently we don't make use of that. --- checks/validate.dat | 22 ++-- src/block/camellia/camellia.cpp | 226 +++++++++++++++++++------------- src/block/camellia/camellia.h | 44 ++++++- src/engine/core_engine/lookup_block.cpp | 8 +- 4 files changed, 191 insertions(+), 109 deletions(-) (limited to 'checks') diff --git a/checks/validate.dat b/checks/validate.dat index 6b9a49e52..4c579bf81 100644 --- a/checks/validate.dat +++ b/checks/validate.dat @@ -4123,26 +4123,28 @@ F0E1D2C3B4A5968778695A4B3C2D1E0F00112233445566 FEDCBA9876543210:05044B62FA52D080:\ F0E1D2C3B4A5968778695A4B3C2D1E0F0011223344556677 -[Camellia] +[Camellia-128] # From RFC 3713 - 0123456789ABCDEFFEDCBA9876543210:67673138549669730857065648EABE43:\ 0123456789ABCDEFFEDCBA9876543210 -0123456789ABCDEFFEDCBA9876543210:B4993401B3E996F84EE5CEE7D79B09B9:\ -0123456789ABCDEFFEDCBA98765432100011223344556677 - -0123456789ABCDEFFEDCBA9876543210:9ACC237DFF16D76C20EF7C919E3A7509:\ -0123456789ABCDEFFEDCBA987654321000112233445566778899AABBCCDDEEFF - -# From NESSIE - +# Nessie 00000000000000000000000000000000:6C227F749319A3AA7DA235A9BBA05A2C:\ 80000000000000000000000000000000 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:25DD9EB9DD67FBC6E8431F56F4FBE651:\ FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF +[Camellia-192] +# From RFC 3713 +0123456789ABCDEFFEDCBA9876543210:B4993401B3E996F84EE5CEE7D79B09B9:\ +0123456789ABCDEFFEDCBA98765432100011223344556677 + +[Camellia-256] +# From RFC 3713 +0123456789ABCDEFFEDCBA9876543210:9ACC237DFF16D76C20EF7C919E3A7509:\ +0123456789ABCDEFFEDCBA987654321000112233445566778899AABBCCDDEEFF + # First one is from RFC 2144. The rest were done with OpenSSL and bits taken # from /dev/urandom [CAST-128] diff --git a/src/block/camellia/camellia.cpp b/src/block/camellia/camellia.cpp index 54c54e7d2..2b4862efc 100644 --- a/src/block/camellia/camellia.cpp +++ b/src/block/camellia/camellia.cpp @@ -103,103 +103,11 @@ u64bit left_rot_lo(u64bit h, u64bit l, size_t shift) return (h >> (64-shift)) | (l << shift); } -} - -} - -/* -* Camellia Encryption -*/ -void Camellia::encrypt_n(const byte in[], byte out[], size_t blocks) const - { - using namespace Camellia_F; - - for(size_t i = 0; i != blocks; ++i) - { - u64bit D1 = load_be(in, 0); - u64bit D2 = load_be(in, 1); - - const u64bit* K = &SK[0]; - - D1 ^= *K++; - D2 ^= *K++; - - while(true) - { - D2 ^= F(D1, *K++); - D1 ^= F(D2, *K++); - D2 ^= F(D1, *K++); - D1 ^= F(D2, *K++); - D2 ^= F(D1, *K++); - D1 ^= F(D2, *K++); - - if(K == &SK[SK.size()-2]) - break; - - D1 = FL (D1, *K++); - D2 = FLINV(D2, *K++); - } - - D2 ^= *K++; - D1 ^= *K++; - - store_be(out, D2, D1); - - in += BLOCK_SIZE; - out += BLOCK_SIZE; - } - } - -/* -* Camellia Decryption -*/ -void Camellia::decrypt_n(const byte in[], byte out[], size_t blocks) const - { - using namespace Camellia_F; - - for(size_t i = 0; i != blocks; ++i) - { - u64bit D1 = load_be(in, 0); - u64bit D2 = load_be(in, 1); - - const u64bit* K = &SK[SK.size()-1]; - - D2 ^= *K--; - D1 ^= *K--; - - while(true) - { - D2 ^= F(D1, *K--); - D1 ^= F(D2, *K--); - D2 ^= F(D1, *K--); - D1 ^= F(D2, *K--); - D2 ^= F(D1, *K--); - D1 ^= F(D2, *K--); - - if(K == &SK[1]) - break; - - D1 = FL (D1, *K--); - D2 = FLINV(D2, *K--); - } - - D1 ^= *K--; - D2 ^= *K; - - store_be(out, D2, D1); - - in += BLOCK_SIZE; - out += BLOCK_SIZE; - } - } - /* * Camellia Key Schedule */ -void Camellia::key_schedule(const byte key[], size_t length) +void key_schedule(SecureVector& SK, const byte key[], size_t length) { - using namespace Camellia_F; - const u64bit Sigma1 = 0xA09E667F3BCC908B; const u64bit Sigma2 = 0xB67AE8584CAA73B2; const u64bit Sigma3 = 0xC6EF372FE94F82BE; @@ -312,4 +220,136 @@ void Camellia::key_schedule(const byte key[], size_t length) } } + +/* +* Camellia Encryption +*/ +void encrypt(const byte in[], byte out[], size_t blocks, const SecureVector& SK) + { + for(size_t i = 0; i != blocks; ++i) + { + u64bit D1 = load_be(in, 0); + u64bit D2 = load_be(in, 1); + + const u64bit* K = &SK[0]; + + D1 ^= *K++; + D2 ^= *K++; + + while(true) + { + D2 ^= F(D1, *K++); + D1 ^= F(D2, *K++); + D2 ^= F(D1, *K++); + D1 ^= F(D2, *K++); + D2 ^= F(D1, *K++); + D1 ^= F(D2, *K++); + + if(K == &SK[SK.size()-2]) + break; + + D1 = FL (D1, *K++); + D2 = FLINV(D2, *K++); + } + + D2 ^= *K++; + D1 ^= *K++; + + store_be(out, D2, D1); + + in += 16; + out += 16; + } + } + +/* +* Camellia Decryption +*/ +void decrypt(const byte in[], byte out[], size_t blocks, const SecureVector& SK) + { + for(size_t i = 0; i != blocks; ++i) + { + u64bit D1 = load_be(in, 0); + u64bit D2 = load_be(in, 1); + + const u64bit* K = &SK[SK.size()-1]; + + D2 ^= *K--; + D1 ^= *K--; + + while(true) + { + D2 ^= F(D1, *K--); + D1 ^= F(D2, *K--); + D2 ^= F(D1, *K--); + D1 ^= F(D2, *K--); + D2 ^= F(D1, *K--); + D1 ^= F(D2, *K--); + + if(K == &SK[1]) + break; + + D1 = FL (D1, *K--); + D2 = FLINV(D2, *K--); + } + + D1 ^= *K--; + D2 ^= *K; + + store_be(out, D2, D1); + + in += 16; + out += 16; + } + } + +} + +} + +void Camellia_128::encrypt_n(const byte in[], byte out[], size_t blocks) const + { + Camellia_F::encrypt(in, out, blocks, SK); + } + +void Camellia_192::encrypt_n(const byte in[], byte out[], size_t blocks) const + { + Camellia_F::encrypt(in, out, blocks, SK); + } + +void Camellia_256::encrypt_n(const byte in[], byte out[], size_t blocks) const + { + Camellia_F::encrypt(in, out, blocks, SK); + } + +void Camellia_128::decrypt_n(const byte in[], byte out[], size_t blocks) const + { + Camellia_F::decrypt(in, out, blocks, SK); + } + +void Camellia_192::decrypt_n(const byte in[], byte out[], size_t blocks) const + { + Camellia_F::decrypt(in, out, blocks, SK); + } + +void Camellia_256::decrypt_n(const byte in[], byte out[], size_t blocks) const + { + Camellia_F::decrypt(in, out, blocks, SK); + } + +void Camellia_128::key_schedule(const byte key[], size_t length) + { + Camellia_F::key_schedule(SK, key, length); + } + +void Camellia_192::key_schedule(const byte key[], size_t length) + { + Camellia_F::key_schedule(SK, key, length); + } + +void Camellia_256::key_schedule(const byte key[], size_t length) + { + Camellia_F::key_schedule(SK, key, length); + } + } diff --git a/src/block/camellia/camellia.h b/src/block/camellia/camellia.h index aaf3ad9e3..9ce305983 100644 --- a/src/block/camellia/camellia.h +++ b/src/block/camellia/camellia.h @@ -13,17 +13,53 @@ namespace Botan { /** -* Camellia +* Camellia-128 +*/ +class BOTAN_DLL Camellia_128 : public Block_Cipher_Fixed_Params<16, 16> + { + public: + void encrypt_n(const byte in[], byte out[], size_t blocks) const; + void decrypt_n(const byte in[], byte out[], size_t blocks) const; + + void clear() { SK.clear(); } + std::string name() const { return "Camellia-128"; } + BlockCipher* clone() const { return new Camellia_128; } + private: + void key_schedule(const byte key[], size_t length); + + SecureVector SK; + }; + +/** +* Camellia-192 +*/ +class BOTAN_DLL Camellia_192 : public Block_Cipher_Fixed_Params<16, 24> + { + public: + void encrypt_n(const byte in[], byte out[], size_t blocks) const; + void decrypt_n(const byte in[], byte out[], size_t blocks) const; + + void clear() { SK.clear(); } + std::string name() const { return "Camellia-192"; } + BlockCipher* clone() const { return new Camellia_192; } + private: + void key_schedule(const byte key[], size_t length); + + SecureVector SK; + }; + +/** +* Camellia-256 */ -class BOTAN_DLL Camellia : public Block_Cipher_Fixed_Params<16, 16, 32, 8> +class BOTAN_DLL Camellia_256 : public Block_Cipher_Fixed_Params<16, 32> { public: void encrypt_n(const byte in[], byte out[], size_t blocks) const; void decrypt_n(const byte in[], byte out[], size_t blocks) const; void clear() { SK.clear(); } - std::string name() const { return "Camellia"; } - BlockCipher* clone() const { return new Camellia; } + std::string name() const { return "Camellia-256"; } + BlockCipher* clone() const { return new Camellia_256; } private: void key_schedule(const byte key[], size_t length); diff --git a/src/engine/core_engine/lookup_block.cpp b/src/engine/core_engine/lookup_block.cpp index c27a13237..c46d4f4cd 100644 --- a/src/engine/core_engine/lookup_block.cpp +++ b/src/engine/core_engine/lookup_block.cpp @@ -135,8 +135,12 @@ BlockCipher* Core_Engine::find_block_cipher(const SCAN_Name& request, #endif #if defined(BOTAN_HAS_CAMELLIA) - if(request.algo_name() == "Camellia") - return new Camellia; + if(request.algo_name() == "Camellia-128") + return new Camellia_128; + if(request.algo_name() == "Camellia-192") + return new Camellia_192; + if(request.algo_name() == "Camellia-256") + return new Camellia_256; #endif #if defined(BOTAN_HAS_CAST) -- cgit v1.2.3