1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-23 12:05:11 -07:00

Test crypto_hash() with an input longer than the block size

This commit is contained in:
Frank Denis 2014-09-23 13:40:08 -07:00
parent dcbc538cd9
commit d511c43ca9
2 changed files with 20 additions and 0 deletions

View File

@ -3,6 +3,7 @@
#include "cmptest.h"
unsigned char x[] = "testing\n";
unsigned char x2[] = "The Conscience of a Hacker is a small essay written January 8, 1986 by a computer security hacker who went by the handle of The Mentor, who belonged to the 2nd generation of Legion of Doom.";
unsigned char h[crypto_hash_BYTES];
int main(void)
@ -14,10 +15,26 @@ int main(void)
printf("%02x", (unsigned int)h[i]);
}
printf("\n");
crypto_hash(h, x2, sizeof x2 - 1U);
for (i = 0; i < crypto_hash_BYTES; ++i) {
printf("%02x", (unsigned int)h[i]);
}
printf("\n");
crypto_hash_sha256(h, x, sizeof x - 1U);
for (i = 0; i < crypto_hash_sha256_BYTES; ++i) {
printf("%02x", (unsigned int)h[i]);
}
printf("\n");
crypto_hash_sha256(h, x2, sizeof x2 - 1U);
for (i = 0; i < crypto_hash_sha256_BYTES; ++i) {
printf("%02x", (unsigned int)h[i]);
}
printf("\n");
assert(crypto_hash_bytes() > 0U);
assert(strcmp(crypto_hash_primitive(), "sha512") == 0);
assert(crypto_hash_sha256_bytes() > 0U);
assert(crypto_hash_sha512_bytes() >= crypto_hash_sha256_bytes());
assert(crypto_hash_sha512_bytes() == crypto_hash_bytes());
return 0;

View File

@ -1 +1,4 @@
24f950aac7b9ea9b3cb728228a0c82b67c39e96b4b344798870d5daee93e3ae5931baae8c7cacfea4b629452c38026a81d138bc7aad1af3ef7bfd5ec646d6c28
a77abe1ccf8f5497e228fbc0acd73a521ededb21b89726684a6ebbc3baa32361aca5a244daa84f24bf19c68baf78e6907625a659b15479eb7bd426fc62aafa73
12a61f4e173fb3a11c05d6471f74728f76231b4a5fcd9667cef3af87a3ae4dc2
71cc8123fef8c236e451d3c3ddf1adae9aa6cd9521e7041769d737024900a03a