Add travis config, fix tests.
This commit is contained in:
@@ -78,10 +78,13 @@ hash_equal_test(void)
|
||||
}
|
||||
|
||||
if (!(emsha::hash_equal(a, b))) {
|
||||
string s;
|
||||
cerr << "FAILED: hash_equal\n";
|
||||
cerr << "\thash_equal should have succeeded comparing a and b.\n";
|
||||
cerr << "\ta <- " << dump_hexstring(a, emsha::SHA256_HASH_SIZE) << std::endl;
|
||||
cerr << "\tb <- " << dump_hexstring(b, emsha::SHA256_HASH_SIZE) << std::endl;
|
||||
dump_hexstring(s, a, emsha::SHA256_HASH_SIZE);
|
||||
cerr << "\ta <- " << s << std::endl;
|
||||
dump_hexstring(s, b, emsha::SHA256_HASH_SIZE);
|
||||
cerr << "\tb <- " << s << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -91,10 +94,13 @@ hash_equal_test(void)
|
||||
}
|
||||
|
||||
if (emsha::hash_equal(a, b)) {
|
||||
string s;
|
||||
cerr << "FAILED: hash_equal\n";
|
||||
cerr << "\thash_equal should not have succeeded comparing a and b.\n";
|
||||
cerr << "\ta <- " << dump_hexstring(a, emsha::SHA256_HASH_SIZE) << std::endl;
|
||||
cerr << "\tb <- " << dump_hexstring(b, emsha::SHA256_HASH_SIZE) << std::endl;
|
||||
dump_hexstring(s, a, emsha::SHA256_HASH_SIZE);
|
||||
cerr << "\ta <- " << s << std::endl;
|
||||
dump_hexstring(s, b, emsha::SHA256_HASH_SIZE);
|
||||
cerr << "\tb <- " << s << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,18 +38,18 @@ using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
|
||||
string
|
||||
dump_hexstring(uint8_t *s, uint32_t sl)
|
||||
void
|
||||
dump_hexstring(string& hs, uint8_t *s, uint32_t sl)
|
||||
{
|
||||
uint32_t bl = (2 * sl) + 1;
|
||||
char *buf = new char[bl];
|
||||
string hs;
|
||||
string tmp;
|
||||
|
||||
memset(buf, 0, bl);
|
||||
emsha::hexstring((uint8_t *)buf, s, sl);
|
||||
hs = string(buf);
|
||||
tmp = string(buf);
|
||||
hs.swap(tmp);
|
||||
delete[] buf;
|
||||
return hs;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ run_hmac_test(struct hmac_test test, string label)
|
||||
goto exit;
|
||||
}
|
||||
|
||||
hs = dump_hexstring(dig, emsha::SHA256_HASH_SIZE);
|
||||
dump_hexstring(hs, dig, emsha::SHA256_HASH_SIZE);
|
||||
if (hs != test.output) {
|
||||
res = emsha::EMSHA_TEST_FAILURE;
|
||||
goto exit;
|
||||
@@ -94,7 +94,7 @@ run_hmac_test(struct hmac_test test, string label)
|
||||
goto exit;
|
||||
}
|
||||
|
||||
hs = dump_hexstring(dig, emsha::SHA256_HASH_SIZE);
|
||||
dump_hexstring(hs, dig, emsha::SHA256_HASH_SIZE);
|
||||
if (hs != test.output) {
|
||||
res = emsha::EMSHA_TEST_FAILURE;
|
||||
goto exit;
|
||||
@@ -111,7 +111,7 @@ run_hmac_test(struct hmac_test test, string label)
|
||||
goto exit;
|
||||
}
|
||||
|
||||
hs = dump_hexstring(dig, emsha::SHA256_HASH_SIZE);
|
||||
dump_hexstring(hs, dig, emsha::SHA256_HASH_SIZE);
|
||||
if (hs != test.output) {
|
||||
cerr << "(comparing single pass function output)\n";
|
||||
res = emsha::EMSHA_TEST_FAILURE;
|
||||
@@ -165,7 +165,7 @@ run_hash_test(struct hash_test test, string label)
|
||||
goto exit;
|
||||
}
|
||||
|
||||
hs = dump_hexstring(dig, emsha::SHA256_HASH_SIZE);
|
||||
dump_hexstring(hs, dig, emsha::SHA256_HASH_SIZE);
|
||||
if (hs != test.output) {
|
||||
res = emsha::EMSHA_TEST_FAILURE;
|
||||
goto exit;
|
||||
@@ -187,7 +187,7 @@ run_hash_test(struct hash_test test, string label)
|
||||
goto exit;
|
||||
}
|
||||
|
||||
hs = dump_hexstring(dig, emsha::SHA256_HASH_SIZE);
|
||||
dump_hexstring(hs, dig, emsha::SHA256_HASH_SIZE);
|
||||
if (hs != test.output) {
|
||||
res = emsha::EMSHA_TEST_FAILURE;
|
||||
goto exit;
|
||||
@@ -203,7 +203,7 @@ run_hash_test(struct hash_test test, string label)
|
||||
goto exit;
|
||||
}
|
||||
|
||||
hs = dump_hexstring(dig, emsha::SHA256_HASH_SIZE);
|
||||
dump_hexstring(hs, dig, emsha::SHA256_HASH_SIZE);
|
||||
if (hs != test.output) {
|
||||
cerr << "(comparing single pass function output)\n";
|
||||
res = emsha::EMSHA_TEST_FAILURE;
|
||||
|
||||
@@ -59,8 +59,8 @@ struct hmac_test {
|
||||
|
||||
|
||||
// General-purpose debuggery.
|
||||
std::string dump_hexstring(std::uint8_t *, std::uint32_t);
|
||||
void dump_pair(std::uint8_t *, std::uint8_t *);
|
||||
void dump_hexstring(std::string&, std::uint8_t *, std::uint32_t);
|
||||
void dump_pair(std::uint8_t *, std::uint8_t *);
|
||||
|
||||
|
||||
// SHA-256 testing functions.
|
||||
|
||||
Reference in New Issue
Block a user