diff options
author | Jack Lloyd <[email protected]> | 2017-06-16 15:35:51 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-06-16 17:07:36 -0400 |
commit | 46e34bf0513129b76481477c4d07452cb48b3cd9 (patch) | |
tree | d233736ee6cf901d70ba2e377279654695c1fa32 /src/tests | |
parent | 37dac0dc7e1f28e30d25c544cc16dcf49575a0b4 (diff) |
Add SM4 block cipher
This work was sponsored by Ribose Inc
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/data/block/sm4.vec | 9 | ||||
-rw-r--r-- | src/tests/test_block.cpp | 14 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/tests/data/block/sm4.vec b/src/tests/data/block/sm4.vec new file mode 100644 index 000000000..fbdba610f --- /dev/null +++ b/src/tests/data/block/sm4.vec @@ -0,0 +1,9 @@ +[SM4] +Key = 0123456789abcdeffedcba9876543210 +In = 0123456789abcdeffedcba9876543210 +Out = 681edf34d206965e86b3e94f536e4246 + +Iterations = 1000000 +Key = 0123456789abcdeffedcba9876543210 +In = 0123456789abcdeffedcba9876543210 +Out = 595298c7c6fd271f0402f804c33d3f66 diff --git a/src/tests/test_block.cpp b/src/tests/test_block.cpp index 7f4856374..16f83a1cb 100644 --- a/src/tests/test_block.cpp +++ b/src/tests/test_block.cpp @@ -12,7 +12,7 @@ namespace Botan_Tests { class Block_Cipher_Tests : public Text_Based_Test { public: - Block_Cipher_Tests() : Text_Based_Test("block", "Key,In,Out") {} + Block_Cipher_Tests() : Text_Based_Test("block", "Key,In,Out", "Iterations") {} std::vector<std::string> possible_providers(const std::string& algo) override { @@ -24,6 +24,7 @@ class Block_Cipher_Tests : public Text_Based_Test const std::vector<uint8_t> key = get_req_bin(vars, "Key"); const std::vector<uint8_t> input = get_req_bin(vars, "In"); const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); + const size_t iterations = get_opt_sz(vars, "Iterations", 1); Test::Result result(algo); @@ -69,13 +70,20 @@ class Block_Cipher_Tests : public Text_Based_Test // have called set_key on clone: process input values std::vector<uint8_t> buf = input; - cipher->encrypt(buf); + for(size_t i = 0; i != iterations; ++i) + { + cipher->encrypt(buf); + } result.test_eq(provider, "encrypt", buf, expected); // always decrypt expected ciphertext vs what we produced above buf = expected; - cipher->decrypt(buf); + + for(size_t i = 0; i != iterations; ++i) + { + cipher->decrypt(buf); + } cipher->clear(); |