diff options
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/data/aead/gcm.vec | 143 | ||||
-rw-r--r-- | src/tests/data/ecc/ecc_private_with_rfc5915_parameters.pem | 6 | ||||
-rw-r--r-- | src/tests/test_filters.cpp | 71 | ||||
-rw-r--r-- | src/tests/tests.cpp | 41 | ||||
-rw-r--r-- | src/tests/unit_ecdsa.cpp | 27 |
5 files changed, 235 insertions, 53 deletions
diff --git a/src/tests/data/aead/gcm.vec b/src/tests/data/aead/gcm.vec index 65a75873e..4a3c955b5 100644 --- a/src/tests/data/aead/gcm.vec +++ b/src/tests/data/aead/gcm.vec @@ -63,6 +63,21 @@ In = 00000000000000000000000000000000000000000000000000000000000000000000000 Out = A833DCC2EC04BEF5ED9E7E7FB08D61244CD795C21FEE194E7AAF7D9BD66B324F39FFC46DB5A7B9E1D6703F95290027DE6AC274CAE11C632F16261B71CE97EEA6CBE8A82B4F55F5A8B5CE1B268A7B35D8 +[AES-128/GCM(12)] +# Nist | Test Case 5 with 12 byte tag +Key = FEFFE9928665731C6D6A8F9467308308 +Nonce = CAFEBABEFACEDBAD +In = D9313225F88406E5A55909C5AFF5269A86A7A9531534F7DA2E4C303D8A318A721C3C0C95956809532FCF0E2449A6B525B16AEDF5AA0DE657BA637B39 +AD = FEEDFACEDEADBEEFFEEDFACEDEADBEEFABADDAD2 +Out = 61353B4C2806934A777FF51FA22A4755699B2A714FCDC6F83766E5F97B6C742373806900E49F24B22B097544D4896B424989B5E1EBAC0F07C23F45983612D2E79E3B0785561BE14A + +# Nist | Test Case 6 with 12 byte tag +Key = FEFFE9928665731C6D6A8F9467308308 +Nonce = 9313225DF88406E555909C5AFF5269AA6A7A9538534F7DA1E4C303D2A318A728C3C0C95156809539FCF0E2429A6B525416AEDBF5A0DE6A57A637B39B +In = D9313225F88406E5A55909C5AFF5269A86A7A9531534F7DA2E4C303D8A318A721C3C0C95956809532FCF0E2449A6B525B16AEDF5AA0DE657BA637B39 +AD = FEEDFACEDEADBEEFFEEDFACEDEADBEEFABADDAD2 +Out = 8CE24998625615B603A033ACA13FB894BE9112A5C3A211A8BA262A3CCA7E2CA701E4A9A4FBA43C90CCDCB281D48C7C6FD62875D2ACA417034C34AEE5619CC5AEFFFE0BFA462AF43C + [AES-192/GCM] # Nist | Test Case 7 @@ -104,6 +119,23 @@ In = d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c9 AD = feedfacedeadbeeffeedfacedeadbeefabaddad2 Out = d27e88681ce3243c4830165a8fdcf9ff1de9a1d8e6b447ef6ef7b79828666e4581e79012af34ddd9e2f037589b292db3e67c036745fa22e7e9b7373bdcf566ff291c25bbb8568fc3d376a6d9 + +[AES-192/GCM(12)] +# Nist | Test Case 10 with 12 byte tag +Key = feffe9928665731c6d6a8f9467308308feffe9928665731c +Nonce = cafebabefacedbaddecaf888 +In = d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39 +AD = feedfacedeadbeeffeedfacedeadbeefabaddad2 +Out = 3980ca0b3c00e841eb06fac4872a2757859e1ceaa6efd984628593b40ca1e19c7d773d00c144c525ac619d18c84a3f4718e2448b2fe324d9ccda27102519498e80f1478f37ba55bd + +# Nist | Test Case 11 with 12 byte tag +Key = feffe9928665731c6d6a8f9467308308feffe9928665731c +Nonce = cafebabefacedbad +In = d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39 +AD = feedfacedeadbeeffeedfacedeadbeefabaddad2 +Out = 0f10f599ae14a154ed24b36e25324db8c566632ef2bbb34f8347280fc4507057fddc29df9a471f75c66541d4d4dad1c9e93a19a58e8b473fa0f062f765dcc57fcf623a24094fcca4 + + [AES-256/GCM] # Nist | Test Case 13 Key = 0000000000000000000000000000000000000000000000000000000000000000 @@ -144,43 +176,132 @@ In = d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c9 AD = feedfacedeadbeeffeedfacedeadbeefabaddad2 Out = 5a8def2f0c9e53f1f75d7853659e2a20eeb2b22aafde6419a058ab4f6f746bf40fc0c3b780f244452da3ebf1c5d82cdea2418997200ef82e44ae7e3fa44a8266ee1c8eb0c8b5d4cf5ae9f19a -[AES-128/GCM(8)] -Key = 00000000000000000000000000000000 -Nonce = 000000000000000000000000 -In = -Out = 58E2FCCEFA7E3061 + +[AES-256/GCM(12)] +# Nist | Test Case 16 with 12 byte tag +Key = feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308 +Nonce = cafebabefacedbaddecaf888 +In = d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39 +AD = feedfacedeadbeeffeedfacedeadbeefabaddad2 +Out = 522dc1f099567d07f47f37a32a84427d643a8cdcbfe5c0c97598a2bd2555d1aa8cb08e48590dbb3da7b08b1056828838c5f61e6393ba7a0abcc9f66276fc6ece0f4e1768cddf8853 + +# Nist | Test Case 17 with 12 byte tag +Key = feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308 +Nonce = cafebabefacedbad +In = d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39 +AD = feedfacedeadbeeffeedfacedeadbeefabaddad2 +Out = c3762df1ca787d32ae47c13bf19844cbaf1ae14d0b976afac52ff7d79bba9de0feb582d33934a4f0954cc2363bc73f7862ac430e64abe499f47c9b1f3a337dbf46a792c45e454913 + + +[AES-256/GCM(13)] +# Nist | Test Case 16 with 13 byte tag +Key = feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308 +Nonce = cafebabefacedbaddecaf888 +In = d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39 +AD = feedfacedeadbeeffeedfacedeadbeefabaddad2 +Out = 522dc1f099567d07f47f37a32a84427d643a8cdcbfe5c0c97598a2bd2555d1aa8cb08e48590dbb3da7b08b1056828838c5f61e6393ba7a0abcc9f66276fc6ece0f4e1768cddf8853bb + +# Nist | Test Case 17 with 13 byte tag +Key = feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308 +Nonce = cafebabefacedbad +In = d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39 +AD = feedfacedeadbeeffeedfacedeadbeefabaddad2 +Out = c3762df1ca787d32ae47c13bf19844cbaf1ae14d0b976afac52ff7d79bba9de0feb582d33934a4f0954cc2363bc73f7862ac430e64abe499f47c9b1f3a337dbf46a792c45e454913fe + + +[AES-256/GCM(14)] +# Nist | Test Case 16 with 14 byte tag +Key = feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308 +Nonce = cafebabefacedbaddecaf888 +In = d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39 +AD = feedfacedeadbeeffeedfacedeadbeefabaddad2 +Out = 522dc1f099567d07f47f37a32a84427d643a8cdcbfe5c0c97598a2bd2555d1aa8cb08e48590dbb3da7b08b1056828838c5f61e6393ba7a0abcc9f66276fc6ece0f4e1768cddf8853bb2d + +# Nist | Test Case 17 with 14 byte tag +Key = feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308 +Nonce = cafebabefacedbad +In = d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39 +AD = feedfacedeadbeeffeedfacedeadbeefabaddad2 +Out = c3762df1ca787d32ae47c13bf19844cbaf1ae14d0b976afac52ff7d79bba9de0feb582d33934a4f0954cc2363bc73f7862ac430e64abe499f47c9b1f3a337dbf46a792c45e454913fe2e + + +[AES-256/GCM(15)] +# Nist | Test Case 16 with 15 byte tag +Key = feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308 +Nonce = cafebabefacedbaddecaf888 +In = d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39 +AD = feedfacedeadbeeffeedfacedeadbeefabaddad2 +Out = 522dc1f099567d07f47f37a32a84427d643a8cdcbfe5c0c97598a2bd2555d1aa8cb08e48590dbb3da7b08b1056828838c5f61e6393ba7a0abcc9f66276fc6ece0f4e1768cddf8853bb2d55 + +# Nist | Test Case 17 with 15 byte tag +Key = feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308 +Nonce = cafebabefacedbad +In = d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39 +AD = feedfacedeadbeeffeedfacedeadbeefabaddad2 +Out = c3762df1ca787d32ae47c13bf19844cbaf1ae14d0b976afac52ff7d79bba9de0feb582d33934a4f0954cc2363bc73f7862ac430e64abe499f47c9b1f3a337dbf46a792c45e454913fe2ea8 # Wycheproof GCM tests [AES-128/GCM(8)] -# This was a 96 bit tag test, truncated since Botan GCM supports only 64/128 Key = 5b9604fe14eadba931b0ccf34843dab9 Nonce = 921d2507fa8007b7bd067d34 AD = 00112233445566778899aabbccddeeff -In = 001d0c231287c1182784554ca3a21908 +In = 001d0c231287c1182784554ca3a21908 Out = 49d8b9783e911913d87094d1f63cc7651e348ba07cca2cf0 -[AES-128/GCM] +[AES-128/GCM(12)] +Key = 5b9604fe14eadba931b0ccf34843dab9 +Nonce = 921d2507fa8007b7bd067d34 +AD = 00112233445566778899aabbccddeeff In = 001d0c231287c1182784554ca3a21908 +Out = 49d8b9783e911913d87094d1f63cc7651e348ba07cca2cf04c618cb4 + +[AES-128/GCM] Key = 5b9604fe14eadba931b0ccf34843dab9 Nonce = 028318abc1824029138141a2 +AD = +In = 001d0c231287c1182784554ca3a21908 Out = 26073cc1d851beff176384dc9896d5ff0a3ea7a5487cb5f7d70fb6c58d038554 -In = 2035af313d1346ab00154fea78322105 Key = aa023d0478dcb2b2312498293d9a9129 Nonce = 0432bc49ac34412081288127 AD = aac39231129872a2 +In = 2035af313d1346ab00154fea78322105 Out = eea945f3d0f98cc0fbab472a0cf24e874bb9b4812519dadf9e1232016d068133 -In = 2035af313d1346ab00154fea78322105 Key = aa023d0478dcb2b2312498293d9a9129 Nonce = 0432bc49ac344120 AD = aac39231129872a2 +In = 2035af313d1346ab00154fea78322105 Out = 64c36bb3b732034e3a7d04efc5197785b7d0dd70b00d65b97cfd080ff4b819d1 -In = 02efd2e5782312827ed5d230189a2a342b277ce048462193 Key = 2034a82547276c83dd3212a813572bce Nonce = 3254202d854734812398127a3d134421 AD = 1a0293d8f90219058902139013908190bc490890d3ff12a3 +In = 02efd2e5782312827ed5d230189a2a342b277ce048462193 Out = 64069c2d58690561f27ee199e6b479b6369eec688672bde99b7abadd6e69c1d9ec925786534f5075 + +Key = 00112233445566778899aabbccddeeff +Nonce = 7b95b8c356810a84711d68150a1b7750 +AD = +In = 00000000000000000000000000000000000000000000000000000000000000000000000000000000 +Out = 84d4c9c08b4f482861e3a9c6c35bc4d91df927374513bfd49f436bd73f325285daef4ff7e13d46a6213a3cb93855d18e69337eee66aeec07 + +Key = 00112233445566778899aabbccddeeff +Nonce = 1a552e67cdc4dc1a33b824874ebf0bed +AD = +In = 00000000000000000000000000000000000000000000000000000000000000000000000000000000 +Out = 948ca37a8e6649e88aeffb1c598f3607007702417ea0e0bc3c60ad5a949886de968cf53ea6462aed99b381bfa2af9751c39d1b6e86d1be6a + +Key = 00112233445566778899aabbccddeeff +Nonce = 99821c2dd5daecded07300f577f7aff1 +AD = +In = 00000000000000000000000000000000000000000000000000000000000000000000000000000000 +Out = 127af9b39ecdfc57bb11a2847c7c2d3d8f938f40f877e0c4af37d0fe9af033052bd537c4ae978f6007eb2fe4a958f8434d40684899507c7c + +Key = 00112233445566778899aabbccddeeff +Nonce = 5e4a3900142358d1c774d8d124d8d27d +AD = +In = 00000000000000000000000000000000000000000000000000000000000000000000000000000000 +Out = 0cf6ae47156b14dce03c8a07a2e172b1127af9b39ecdfc57bb11a2847c7c2d3d8f938f40f877e0c4f145c2dcaf339eede427be934357eac0 diff --git a/src/tests/data/ecc/ecc_private_with_rfc5915_parameters.pem b/src/tests/data/ecc/ecc_private_with_rfc5915_parameters.pem new file mode 100644 index 000000000..9044ba49e --- /dev/null +++ b/src/tests/data/ecc/ecc_private_with_rfc5915_parameters.pem @@ -0,0 +1,6 @@ +-----BEGIN PRIVATE KEY----- +MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgQsaM/yuLh6H7UPb+ +1oizCkiyxY9Q4M9A+lfRxmwgZMWgCgYIKoZIzj0DAQehRANCAAScslLLwFzPl93W +50kyRwyO222/yBoKAeheP45kM7QVuxul7flLp+heb0kk9zL0m0xH3PEoRBw32+77 +2L1OXOsH +-----END PRIVATE KEY----- diff --git a/src/tests/test_filters.cpp b/src/tests/test_filters.cpp index 6199f88e2..7de68accb 100644 --- a/src/tests/test_filters.cpp +++ b/src/tests/test_filters.cpp @@ -43,6 +43,7 @@ class Filter_Tests : public Test results.push_back(test_pipe_mac()); results.push_back(test_pipe_stream()); results.push_back(test_pipe_cbc()); + results.push_back(test_pipe_cfb()); results.push_back(test_pipe_compress()); results.push_back(test_pipe_codec()); results.push_back(test_fork()); @@ -274,6 +275,76 @@ class Filter_Tests : public Test return result; } + Test::Result test_pipe_cfb() + { + Test::Result result("Pipe CFB"); + +#if defined(BOTAN_HAS_BLOWFISH) && defined(BOTAN_HAS_MODE_CFB) + + // Generated with Botan 1.10 + + const Botan::InitializationVector iv("AABBCCDDEEFF0123"); + const Botan::SymmetricKey key("AABBCCDDEEFF0123"); + + const uint8_t msg_bits[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; + + const std::string cfb_expected[] = { + "A4", + "BEA4", + "06AD98", + "E4AFC5AC", + "A9B531559C", + "38B60DA66445", + "194F5E93199839", + "093B6381D2E5D806", + "B44FA624226EECF027", + "80B8DC3332A835AC11A8", + "2C0E910A1E5C38344CC5BB", + "3CB6180AE2E189342F681023", + "DE0F4B10C7D9CADDB5A9078199", + "FAE18B0ED873F234CCD6E1555B2D", + "7195FFE735B0A95065BA244C77A11F", + }; + + Botan::Keyed_Filter* cfb_enc = + new Botan::Cipher_Mode_Filter(Botan::get_cipher_mode("Blowfish/CFB", Botan::ENCRYPTION)); + cfb_enc->set_key(key); + cfb_enc->set_iv(iv); + Botan::Pipe enc_pipe(cfb_enc, new Botan::Hex_Encoder); + + Botan::Keyed_Filter* cfb_dec = + new Botan::Cipher_Mode_Filter(Botan::get_cipher_mode("Blowfish/CFB", Botan::DECRYPTION)); + cfb_dec->set_key(key); + cfb_dec->set_iv(iv); + Botan::Pipe dec_pipe(new Botan::Hex_Decoder, cfb_dec, new Botan::Hex_Encoder); + + for(size_t i = 1; i != sizeof(msg_bits); ++i) + { + enc_pipe.start_msg(); + enc_pipe.write(msg_bits, i); + enc_pipe.end_msg(); + + dec_pipe.process_msg(cfb_expected[i-1]); + } + + result.test_eq("enc pipe msg count", enc_pipe.message_count(), sizeof(msg_bits) - 1); + result.test_eq("dec pipe msg count", dec_pipe.message_count(), sizeof(msg_bits) - 1); + + for(size_t i = 0; i != enc_pipe.message_count(); ++i) + { + result.test_eq("encrypt", enc_pipe.read_all_as_string(i), cfb_expected[i]); + } + + for(size_t i = 0; i != dec_pipe.message_count(); ++i) + { + result.test_eq("decrypt", dec_pipe.read_all_as_string(i), + Botan::hex_encode(msg_bits, i+1)); + } +#endif + + return result; + } + Test::Result test_pipe_cbc() { Test::Result result("Pipe CBC"); diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index d7917bcc6..930d7c623 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -872,52 +872,13 @@ std::string strip_ws(const std::string& in) return in.substr(first_c, last_c - first_c + 1); } -std::vector<Botan::CPUID::CPUID_bits> map_cpuid_string(const std::string& tok) - { -#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY) - if(tok == "sse2" || tok == "simd") - return {Botan::CPUID::CPUID_SSE2_BIT}; - if(tok == "ssse3") - return {Botan::CPUID::CPUID_SSSE3_BIT}; - if(tok == "aesni") - return {Botan::CPUID::CPUID_AESNI_BIT}; - if(tok == "clmul") - return {Botan::CPUID::CPUID_CLMUL_BIT}; - if(tok == "avx2") - return {Botan::CPUID::CPUID_AVX2_BIT}; - if(tok == "sha") - return {Botan::CPUID::CPUID_SHA_BIT}; - -#elif defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY) - if(tok == "altivec" || tok == "simd") - return {Botan::CPUID::CPUID_ALTIVEC_BIT}; - -#elif defined(BOTAN_TARGET_CPU_IS_ARM_FAMILY) - if(tok == "neon" || tok == "simd") - return {Botan::CPUID::CPUID_ARM_NEON_BIT}; - if(tok == "armv8sha1") - return {Botan::CPUID::CPUID_ARM_SHA1_BIT}; - if(tok == "armv8sha2") - return {Botan::CPUID::CPUID_ARM_SHA2_BIT}; - if(tok == "armv8aes") - return {Botan::CPUID::CPUID_ARM_AES_BIT}; - if(tok == "armv8pmull") - return {Botan::CPUID::CPUID_ARM_PMULL_BIT}; - -#else - BOTAN_UNUSED(tok); -#endif - - return {}; - } - std::vector<Botan::CPUID::CPUID_bits> parse_cpuid_bits(const std::vector<std::string>& tok) { std::vector<Botan::CPUID::CPUID_bits> bits; for(size_t i = 1; i < tok.size(); ++i) { - const std::vector<Botan::CPUID::CPUID_bits> more = map_cpuid_string(tok[i]); + const std::vector<Botan::CPUID::CPUID_bits> more = Botan::CPUID::bit_from_string(tok[i]); bits.insert(bits.end(), more.begin(), more.end()); } diff --git a/src/tests/unit_ecdsa.cpp b/src/tests/unit_ecdsa.cpp index ea622ade4..2654753eb 100644 --- a/src/tests/unit_ecdsa.cpp +++ b/src/tests/unit_ecdsa.cpp @@ -370,18 +370,40 @@ Test::Result test_ecc_key_with_rfc5915_extensions() std::unique_ptr<Botan::Private_Key> pkcs8( Botan::PKCS8::load_key(Test::data_file("ecc/ecc_private_with_rfc5915_ext.pem"), Test::rng())); - result.confirm("loaded RFC 5914 key", pkcs8.get()); + result.confirm("loaded RFC 5915 key", pkcs8.get()); result.test_eq("key is ECDSA", pkcs8->algo_name(), "ECDSA"); result.confirm("key type is ECDSA", dynamic_cast<Botan::ECDSA_PrivateKey*>(pkcs8.get())); } catch(std::exception& e) { - result.test_failure("load_rfc5915", e.what()); + result.test_failure("load_rfc5915_ext", e.what()); } return result; } +Test::Result test_ecc_key_with_rfc5915_parameters() + { + Test::Result result("ECDSA Unit"); + + try + { + std::unique_ptr<Botan::Private_Key> pkcs8( + Botan::PKCS8::load_key(Test::data_file("ecc/ecc_private_with_rfc5915_parameters.pem"), Test::rng())); + + result.confirm("loaded RFC 5915 key", pkcs8.get()); + result.test_eq("key is ECDSA", pkcs8->algo_name(), "ECDSA"); + result.confirm("key type is ECDSA", dynamic_cast<Botan::ECDSA_PrivateKey*>(pkcs8.get())); + } + catch(std::exception& e) + { + result.test_failure("load_rfc5915_params", e.what()); + } + + return result; + } + + class ECDSA_Unit_Tests : public Test { @@ -402,6 +424,7 @@ class ECDSA_Unit_Tests : public Test results.push_back(test_unusual_curve()); results.push_back(test_curve_registry()); results.push_back(test_ecc_key_with_rfc5915_extensions()); + results.push_back(test_ecc_key_with_rfc5915_parameters()); return results; } }; |