diff options
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/data/mac/siphash.vec | 4 | ||||
-rw-r--r-- | src/tests/test_hash.cpp | 20 | ||||
-rw-r--r-- | src/tests/test_mac.cpp | 28 |
3 files changed, 46 insertions, 6 deletions
diff --git a/src/tests/data/mac/siphash.vec b/src/tests/data/mac/siphash.vec new file mode 100644 index 000000000..7e4bfed04 --- /dev/null +++ b/src/tests/data/mac/siphash.vec @@ -0,0 +1,4 @@ +[SipHash(2,4)] +Key = 000102030405060708090A0B0C0D0E0F +In = 000102030405060708090A0B0C0D0E +Out = E545BE4961CA29A1 diff --git a/src/tests/test_hash.cpp b/src/tests/test_hash.cpp index 242988c80..fb8d54e1f 100644 --- a/src/tests/test_hash.cpp +++ b/src/tests/test_hash.cpp @@ -42,9 +42,11 @@ size_t hash_test(const std::string& algo, continue; } + const std::vector<byte> in = hex_decode(in_hex); + std::unique_ptr<HashFunction> hash(proto->clone()); - hash->update(hex_decode(in_hex)); + hash->update(in); auto h = hash->final(); @@ -58,7 +60,7 @@ size_t hash_test(const std::string& algo, hash->update("some discarded input"); hash->clear(); - hash->update(hex_decode(in_hex)); + hash->update(in); h = hash->final(); @@ -68,6 +70,20 @@ size_t hash_test(const std::string& algo, << " (with discarded input)\n"; ++fails; } + + if(in.size() > 1) + { + hash->update(in[0]); + hash->update(&in[1], in.size() - 1); + h = hash->final(); + + if(h != hex_decode_locked(out_hex)) + { + std::cout << algo << " " << provider << " got " << hex_encode(h) << " != " << out_hex + << " (with offset input)\n"; + ++fails; + } + } } return fails; diff --git a/src/tests/test_mac.cpp b/src/tests/test_mac.cpp index 45092d4f3..8be57afbe 100644 --- a/src/tests/test_mac.cpp +++ b/src/tests/test_mac.cpp @@ -45,16 +45,36 @@ size_t mac_test(const std::string& algo, std::unique_ptr<MessageAuthenticationCode> mac(proto->clone()); + const std::vector<byte> in = hex_decode(in_hex); + const std::vector<byte> exp = hex_decode(out_hex); + mac->set_key(hex_decode(key_hex)); - mac->update(hex_decode(in_hex)); - auto h = mac->final(); + mac->update(in); + + const std::vector<byte> out = unlock(mac->final()); - if(h != hex_decode_locked(out_hex)) + if(out != exp) { - std::cout << algo << " " << provider << " got " << hex_encode(h) << " != " << out_hex << "\n"; + std::cout << algo << " " << provider << " got " << hex_encode(out) << " != " << hex_encode(exp) << "\n"; ++fails; } + + if(in.size() > 2) + { + mac->set_key(hex_decode(key_hex)); + mac->update(in[0]); + mac->update(&in[1], in.size() - 2); + mac->update(in[in.size()-1]); + + const std::vector<byte> out2 = unlock(mac->final()); + + if(out2 != exp) + { + std::cout << algo << " " << provider << " got " << hex_encode(out2) << " != " << hex_encode(exp) << "\n"; + ++fails; + } + } } return fails; |