]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Small skein256 tweaks.
authorNiels Möller <nisse@lysator.liu.se>
Mon, 1 Jan 2018 22:20:51 +0000 (23:20 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Mon, 1 Jan 2018 22:20:51 +0000 (23:20 +0100)
* configure.ac: Don't use skein512-internal.asm, it brings no real
speedup.

* skein.h (_SKEIN256_NKEYS): Reduce from 6 to 5 (repeated subkeys
no longer used).
* skein256.c (_skein256_expand): Update accordingly.
(skein256_process_block): Use uint64_t rather than unsigned long
long in cast.
* skein256-internal.c (_skein256_block): Micro optimization of subkey rotation.

ChangeLog
skein.h
skein256-internal.c
skein256.c

index 1361b99d2e52f9446885d6693a0a856a98dacc90..cfe411a34bf4241f1b9d353f1b169f836c2e00f0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2018-01-01  Niels Möller  <nisse@lysator.liu.se>
 
+       * skein.h (_SKEIN256_NKEYS): Reduce from 6 to 5 (repeated subkeys
+       no longer used).
+       * skein256.c (_skein256_expand): Update accordingly.
+       (skein256_process_block): Use uint64_t rather than unsigned long
+       long in cast.
+       * skein256-internal.c (_skein256_block): Micro optimization of subkey rotation.
+
        * configure.ac: Don't use skein512-internal.asm, it brings no real
        speedup.
 
diff --git a/skein.h b/skein.h
index 9d388af525c4db72ace455ab5ff1da7ec41b67d7..706702ea5f85d1819ef111c87d9cce02cad82135 100644 (file)
--- a/skein.h
+++ b/skein.h
@@ -51,18 +51,18 @@ extern "C" {
 #define SKEIN256_BLOCK_SIZE 32
 #define SKEIN256_DIGEST_SIZE 32
 
-/* Internal lengths, as 64-bit words. We use *two* redundant words for
-   the key, to reduce the number of index mod operations. On the other
-   hand, tweak words are expanded on the fly. */
+/* Internal lengths, as 64-bit words. We store the redundant xor sum
+   of the subkeys as an extra subkey. On the other hand, tweak words
+   are expanded on the fly. */
 #define _SKEIN256_LENGTH 4
-#define _SKEIN256_NKEYS 6
+#define _SKEIN256_NKEYS 5
 #define _SKEIN_NTWEAK 2
 
 struct skein256_ctx {
   uint64_t state[_SKEIN256_NKEYS];
 
   /* Current implementation limited to message size <= 2^69 - 32 bytes,
-     while the specification allows up to 2^96 -1 bytes.*/
+     while the specification allows up to 2^96 - 1 bytes.*/
   uint64_t count;               /* Block count */
   uint8_t block[SKEIN256_BLOCK_SIZE];
   unsigned index;
index c0e8709a1cb285c095dd4218f58b38100a8591b4..425c5ec07ebdc70fa6a78e0632140cd8b2ed33be 100644 (file)
@@ -127,19 +127,18 @@ _skein256_block (uint64_t dst[_SKEIN256_LENGTH],
       ROUND(w0, w1, w2, w3, 23, 40);
       ROUND(w0, w3, w2, w1, 5, 37);
 
-      w0 += k1 - t0; /* Right-hand side equal to new k4, below. */
+      tmp = k1 - t0; // New k4.
+      w0 += tmp;
       w1 += k2;
       t0 ^= t1;
-      w2 += k3 + t0; /* Right-hand side equal to new k1, below. */
-      w3 += k4 + i + 1;
-
-      tmp = k1;
       k1 = k3 + t0;
+      w2 += k1;
+      w3 += k4 + i + 1;
       k3 = k0;
       k0 = k2 - t1;
       t1 ^= t0;
       k2 = k4 + t1;
-      k4 = tmp - t1;
+      k4 = tmp;
 
       ROUND(w0, w1, w2, w3, 25, 33);
       ROUND(w0, w3, w2, w1, 46, 12);
index 078ed1c24ca5337e0eb75c2cff5aee1feb0288ac..49815c16fb9e6acadfda9ff1ce45b675c48ba209 100644 (file)
@@ -49,7 +49,6 @@ _skein256_expand(uint64_t keys[_SKEIN256_NKEYS])
   for (i = 0, sum = _SKEIN_C240; i < _SKEIN256_LENGTH; i++)
     sum ^= keys[i];
   keys[_SKEIN256_LENGTH] = sum;
-  keys[_SKEIN256_LENGTH + 1] = keys[0];
 }
 
 void
@@ -77,7 +76,7 @@ skein256_process_block(struct skein256_ctx *ctx,
   tag |= ((ctx->count == 0) << 6);
 
   tweak[0] = (ctx->count << 5) + length;
-  tweak[1] = (ctx->count >> 59) | ((unsigned long long) tag << 56);
+  tweak[1] = (ctx->count >> 59) | ((uint64_t) tag << 56);
   _skein256_expand(ctx->state);
 
   _skein256_block(ctx->state, ctx->state, tweak, data);