diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2012-05-26 16:14:36 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2012-05-26 16:14:36 -0700 |
commit | caf8a9b2b301aba06735d403317b75b41df59bfe (patch) | |
tree | bfafb3cc0cf8a2f2394b4ed721e7c3d4891b78ab /lib/sha256.c | |
parent | fe453991eafc32a890297a2003ac532b9f579f92 (diff) | |
download | emacs-caf8a9b2b301aba06735d403317b75b41df59bfe.tar.gz |
Merge from gnulib.
Fixes: debbugs:11527
Diffstat (limited to 'lib/sha256.c')
-rw-r--r-- | lib/sha256.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/sha256.c b/lib/sha256.c index 4dbb5e91291..a8d29da18dd 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -1,7 +1,7 @@ /* sha256.c - Functions to compute SHA256 and SHA224 message digest of files or memory blocks according to the NIST specification FIPS-180-2. - Copyright (C) 2005-2006, 2008-2011 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2008-2012 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,7 +24,8 @@ #include "sha256.h" -#include <stddef.h> +#include <stdalign.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> @@ -373,8 +374,7 @@ sha256_process_bytes (const void *buffer, size_t len, struct sha256_ctx *ctx) if (len >= 64) { #if !_STRING_ARCH_unaligned -# define alignof(type) offsetof (struct { char c; type x; }, x) -# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0) +# define UNALIGNED_P(p) ((uintptr_t) (p) % alignof (uint32_t) != 0) if (UNALIGNED_P (buffer)) while (len > 64) { @@ -454,13 +454,13 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) uint32_t f = ctx->state[5]; uint32_t g = ctx->state[6]; uint32_t h = ctx->state[7]; + uint32_t lolen = len; /* First increment the byte count. FIPS PUB 180-2 specifies the possible length of the file up to 2^64 bits. Here we only compute the number of bytes. Do a double word increment. */ - ctx->total[0] += len; - if (ctx->total[0] < len) - ++ctx->total[1]; + ctx->total[0] += lolen; + ctx->total[1] += (len >> 31 >> 1) + (ctx->total[0] < lolen); #define rol(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) #define S0(x) (rol(x,25)^rol(x,14)^(x>>3)) |