]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
* sha512.c: (sha512_digest): Simplified handling of any final
authorNiels Möller <nisse@lysator.liu.se>
Wed, 24 Mar 2010 21:44:16 +0000 (22:44 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Wed, 24 Mar 2010 21:44:16 +0000 (22:44 +0100)
partial word of the digest.

Rev: nettle/ChangeLog:1.58
Rev: nettle/sha512.c:1.3

ChangeLog
sha512.c

index a445477916f9566e6c61f17b33cfc2d6bcd27964..86699f654c27d8072ed38217d389f800106450c0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2010-03-24  Niels Möller  <nisse@lysator.liu.se>
 
+       * sha512.c: (sha512_digest): Simplified handling of any final
+       partial word of the digest.
+
        * sha512.c: Reorganized to use _nettle_sha512_compress.
 
        * sha512-compress.c (_nettle_sha512_compress): Compression
index 0a7b6585afd6eb255f6719a5abdf6963081c404f..ec3c12fdc98ada5c929b5d3cd59a08011f37aa07 100644 (file)
--- a/sha512.c
+++ b/sha512.c
@@ -237,37 +237,14 @@ sha512_digest(struct sha512_ctx *ctx,
 
   if (leftover)
     {
-      uint64_t word;
-      unsigned j = leftover;
-      
-      assert(i < _SHA512_DIGEST_LENGTH);
-      
-      word = ctx->state[i];
-      
-      switch (leftover)
-       {
-       default:
-         abort();
-       case 7:
-         digest[--j] = (word >> 8) & 0xff;
-         /* Fall through */
-       case 6:
-         digest[--j] = (word >> 16) & 0xff;
-         /* Fall through */
-       case 5:
-         digest[--j] = (word >> 24) & 0xff;
-         /* Fall through */
-       case 4:
-         digest[--j] = (word >> 32) & 0xff;
-       case 3:
-         digest[--j] = (word >> 40) & 0xff;
-         /* Fall through */
-       case 2:
-         digest[--j] = (word >> 48) & 0xff;
-         /* Fall through */
-       case 1:
-         digest[--j] = (word >> 56) & 0xff;
-       }
+      /* Truncate to the right size */
+      uint64_t word = ctx->state[i] >> (8*(8 - leftover));
+
+      do {
+       digest[--leftover] = word & 0xff;
+       word >>= 8;
+      } while (leftover);
     }
+
   sha512_init(ctx);
 }