-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add known answer test for AsconCXOF-128
Signed-off-by: Anjan Roy <[email protected]>
- Loading branch information
1 parent
06f8ccf
commit 5d0f370
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "ascon/hashes/ascon_cxof128.hpp" | ||
#include "test_helper.hpp" | ||
#include <fstream> | ||
#include <gtest/gtest.h> | ||
|
||
TEST(AsconCXOF128, KnownAnswerTests) | ||
{ | ||
using namespace std::literals; | ||
|
||
const std::string kat_file = "./kats/ascon_cxof128.kat"; | ||
std::fstream file(kat_file); | ||
|
||
while (true) { | ||
std::string count0; | ||
|
||
if (!std::getline(file, count0).eof()) { | ||
std::string msg0; | ||
std::string customization_str0; | ||
std::string md0; | ||
|
||
std::getline(file, msg0); | ||
std::getline(file, customization_str0); | ||
std::getline(file, md0); | ||
|
||
auto msg1 = std::string_view(msg0); | ||
auto customization_str1 = std::string_view(customization_str0); | ||
auto md1 = std::string_view(md0); | ||
|
||
auto msg2 = msg1.substr(msg1.find("="sv) + 2, msg1.size()); | ||
auto customization_str2 = customization_str1.substr(customization_str1.find("="sv) + 2, customization_str1.size()); | ||
auto md2 = md1.substr(md1.find("="sv) + 2, md1.size()); | ||
|
||
auto msg = hex_to_bytes(msg2); | ||
auto customization_str = hex_to_bytes(customization_str2); | ||
auto md = hex_to_bytes(md2); | ||
|
||
std::vector<uint8_t> computed_md(md.size()); | ||
|
||
ascon_cxof128::ascon_cxof128_t hasher; | ||
EXPECT_TRUE(hasher.customize(customization_str)); | ||
EXPECT_TRUE(hasher.absorb(msg)); | ||
EXPECT_TRUE(hasher.finalize()); | ||
EXPECT_TRUE(hasher.squeeze(computed_md)); | ||
|
||
EXPECT_EQ(computed_md, md); | ||
|
||
std::string empty_line; | ||
std::getline(file, empty_line); | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
file.close(); | ||
} |