Fix comparison test in hash_equal, release 1.0.1.

The result in the loop was being reset each iteration; only the last
element in the byte array was being checked for equality.
This commit is contained in:
Kyle 2015-12-22 21:41:05 -08:00
parent 54b986f6f6
commit 0cf03528c5
6 changed files with 33 additions and 4 deletions

View File

@ -1,5 +1,11 @@
LIBEMSHA CHANGELOG
==================
1.0.1 (2015-12-22):
Fixed:
+ hash_equal was improperly performing its comparison.
------------------
1.0.0 (2015-12-18):
Initial release.

View File

@ -24,7 +24,7 @@ The source code is available via `Github
git clone https://github.com/kisom/libemsha
git clone git@github.com:kisom/libemsha
The current release is `1.0.0 <https://github.com/kisom/libemsha/archive/1.0.0.zip>`_.
The current release is `1.0.1 <https://github.com/kisom/libemsha/releases/tag/v1.0.1>`_.
The project is built using Autotools and ``make``.

View File

@ -2,7 +2,7 @@
# versions that can be used with Travis right now.
AC_PREREQ([2.68])
AC_INIT([libemsha],
[1.0.0],
[1.0.1],
[coder@kyleisom.net],
[libemsha],
[https://kyleisom.net/projects/libemsha/])

View File

@ -2,7 +2,7 @@
libemsha
========
Version: 1.0.0
Version: 1.0.1
Date: 2015-12-22

View File

@ -55,7 +55,7 @@ hash_equal(const uint8_t *a, const uint8_t *b)
EMSHA_CHECK(b != NULL, false);
for (uint32_t i = 0; i < SHA256_HASH_SIZE; i++) {
res = a[i] ^ b[i];
res += a[i] ^ b[i];
}
return res == 0;

View File

@ -106,6 +106,29 @@ hash_equal_test(void)
exit(1);
}
// This catches the bug in the initial version where the code was
// res = a[i] ^ b[i];
// instead of
// res += a[i] ^ b[i];
for (uint32_t i = 0; i < emsha::SHA256_HASH_SIZE; i++) {
a[i] = static_cast<uint8_t>(i);
b[i] = static_cast<uint8_t>(i+1);
}
b[emsha::SHA256_HASH_SIZE - 1]--;
if (emsha::hash_equal(a, b)) {
string s;
cerr << "FAILED: hash_equal\n";
cerr << "\tREGRESSION: hash_equal should not have succeeded comparing a and b.\n";
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);
}
cout << "PASSED: hash_equal\n";
}