aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-11-11 21:15:18 +0100
committerMattias Andrée <maandree@operamail.com>2014-11-11 21:15:18 +0100
commit4642d27c2733171638753885fccab6556b589903 (patch)
treeb71a52904e40395218149106d5f3a87d8f8da57e
parentsomething seems to be wrong in libkeccak_f_round (not libkeccak_f_round64), but I have not figured out what (diff)
downloadlibkeccak-4642d27c2733171638753885fccab6556b589903.tar.gz
libkeccak-4642d27c2733171638753885fccab6556b589903.tar.bz2
libkeccak-4642d27c2733171638753885fccab6556b589903.tar.xz
bug fixed, but found that large outputs does not work correctly
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/libkeccak/digest.c14
-rw-r--r--src/test.c32
2 files changed, 39 insertions, 7 deletions
diff --git a/src/libkeccak/digest.c b/src/libkeccak/digest.c
index fa2aa8a..0b3005d 100644
--- a/src/libkeccak/digest.c
+++ b/src/libkeccak/digest.c
@@ -71,7 +71,7 @@ static const uint_fast64_t RC[] =
* Rotate a word
*
* @param x:int_fast64_t The value to rotate
- * @param n:long Rotation steps, may not be zero
+ * @param n:long Rotation steps, may be zero mod `w`
* @param w:long `state->w`
* @param wmod:int_fast64_t `state->wmod`
* @return :int_fast64_t The value rotated
@@ -86,7 +86,7 @@ static const uint_fast64_t RC[] =
* @param n:long Rotation steps, may not be zero
* @return :int_fast64_t The value rotated
*/
-#define rotate64(x, n) ((int_fast64_t)(((uint64_t)(x) >> (64L - (n))) + ((uint64_t)(x) << (n))))
+#define rotate64(x, n) ((int_fast64_t)(((uint64_t)(x) >> (64L - (n))) | ((uint64_t)(x) << (n))))
/**
@@ -112,11 +112,11 @@ void libkeccak_f_round(register libkeccak_state_t* restrict state, register int_
#undef X
/* θ step (step 2 of 3). */
- da = C[4] ^ rotate64(C[1], 1);
- dd = C[2] ^ rotate64(C[4], 1);
- db = C[0] ^ rotate64(C[2], 1);
- de = C[3] ^ rotate64(C[0], 1);
- dc = C[1] ^ rotate64(C[3], 1);
+ da = C[4] ^ rotate(C[1], 1, w, wmod);
+ dd = C[2] ^ rotate(C[4], 1, w, wmod);
+ db = C[0] ^ rotate(C[2], 1, w, wmod);
+ de = C[3] ^ rotate(C[0], 1, w, wmod);
+ dc = C[1] ^ rotate(C[3], 1, w, wmod);
/* ρ and π steps, with last two part of θ. */
#define X(bi, ai, dv, r) B[bi] = rotate(A[ai] ^ dv, r, w, wmod)
diff --git a/src/test.c b/src/test.c
index c2e8a9c..4b17a79 100644
--- a/src/test.c
+++ b/src/test.c
@@ -290,6 +290,38 @@ static int test_digest(void)
if (shake(256, 128, "")) return -1;
+ answer = "65070cdd6f91c0aadcfc470895a2606c828bce7ce3fa723418c9013de92253515713cce8"
+ "d2098be1c82df40b40e375549c0eeb655f92d718f01f147ba1c7c67844c7ba8b11492cd6";
+ if (keccak_g(1024, 1600 - 1024, 576, "capitol's kvistfri broadly raping")) return -1;
+
+ answer = "65070cdd6f91c0aadcfc470895a2606c828bce7ce3fa723418c9013de92253515713cce8"
+ "d2098be1c82df40b40e375549c0eeb655f92d718f01f147ba1c7c67844c7ba8b11492cd6"
+ "143466958504c110522f772fe746573b1dc905f943ed1ec6ecf858575798596beeca4eb6"
+ "bb7bea635bcea6331315728fb57866370bf1ad5d";
+ if (keccak_g(1024, 1600 - 1024, 1024, "capitol's kvistfri broadly raping")) return -1;
+
+ answer = "65070cdd6f91c0aadcfc470895a2606c828bce7ce3fa723418c9013de92253515713cce8"
+ "d2098be1c82df40b40e375549c0eeb655f92d718f01f147ba1c7c67844c7ba8b11492cd6"
+ "143466958504c110522f772fe746573b1dc905f943ed1ec6ecf858575798596beeca4eb6"
+ "bb7bea635bcea6331315728fb57866370bf1ad5decbc56d28d47ce53f18376d9f5531551"
+ "7a976d52dd3f98b7025e0b3c513c6d17d40462cddb5406d693bbe859a136af5375b5dd6e"
+ "3478934b00aa6cd44aa7ae2cd0271d83fbab699b";
+ if (keccak_g(1024, 1600 - 1024, 1600, "capitol's kvistfri broadly raping")) return -1;
+
+ answer = "65070cdd6f91c0aadcfc470895a2606c828bce7ce3fa723418c9013de92253515713cce8"
+ "d2098be1c82df40b40e375549c0eeb655f92d718f01f147ba1c7c67844c7ba8b11492cd6"
+ "143466958504c110522f772fe746573b1dc905f943ed1ec6ecf858575798596beeca4eb6"
+ "bb7bea635bcea6331315728fb57866370bf1ad5decbc56d28d47ce53f18376d9f5531551"
+ "7a976d52dd3f98b7025e0b3c513c6d17d40462cddb5406d693bbe859a136af5375b5dd6e"
+ "3478934b00aa6cd44aa7ae2cd0271d83fbab699b9c58351bf7d26586b9c32282f1ac6356"
+ "1981b79791d7ab2b6e01f5b8e6cf0cab8b2076fd82bd99df015a602cdda5684162fea982"
+ "0f5a441c4620f549fbaf4e818201f292dbf4f6c9f82af8aa80b4124984da6f65b2874e0e"
+ "f01d042c08e9aedbb6ce4c10526e38c1a4e8b108c4f14b066f9d42640687b55124b081da"
+ "a9f9ae4232f313740b4fb787545dc19e7778f7082b3fa5824d2400c012be1a6c5ade7149"
+ "e452d310752fa9ebb964ab36fde0c8f46f47a0e2c9b20f24e3cca904bbedaa7ea176f662"
+ "33cd2d95";
+ if (keccak_g(1024, 1600 - 1024, 3200, "capitol's kvistfri broadly raping")) return -1;
+
answer = "65070cdd6f91c0aadcfc470895a2606c828bce7ce3fa723418c9013de9225351";
if (keccak_g(1024, 1600 - 1024, 256, "capitol's kvistfri broadly raping")) return -1;