X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fsha1.c;h=9d7d44779afff595e51ba6b51b8a39ce73e4d601;hb=fa1db0dd22768f09a507674a30beb5b8a87bb35f;hp=d4c75f91482f9b08350230d27572495d32720a9e;hpb=441aa3044f43e5572f58c354f01e6bc070acd5c7;p=gnulib.git diff --git a/lib/sha1.c b/lib/sha1.c index d4c75f914..9d7d44779 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -1,8 +1,7 @@ /* sha1.c - Functions to compute SHA1 message digest of files or memory blocks according to the NIST specification FIPS-180-1. - Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2008 Free Software - Foundation, Inc. + Copyright (C) 2000-2001, 2003-2006, 2008-2013 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 the @@ -15,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + along with this program; if not, see . */ /* Written by Scott G. Miller Credits: @@ -27,7 +25,8 @@ #include "sha1.h" -#include +#include +#include #include #include @@ -71,7 +70,7 @@ sha1_init_ctx (struct sha1_ctx *ctx) /* Copy the 4 byte value from v into the memory location pointed to by *cp, If your architecture allows unaligned access this is equivalent to * (uint32_t *) cp = v */ -static inline void +static void set_uint32 (char *cp, uint32_t v) { memcpy (cp, &v, sizeof v); @@ -242,8 +241,7 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_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) { @@ -307,13 +305,13 @@ sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx) uint32_t c = ctx->C; uint32_t d = ctx->D; uint32_t e = ctx->E; + uint32_t lolen = len; /* First increment the byte count. RFC 1321 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)) | ((uint32_t) (x) >> (32 - (n))))