summaryrefslogtreecommitdiffstats
path: root/gl/sha1.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/sha1.c')
-rw-r--r--gl/sha1.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/gl/sha1.c b/gl/sha1.c
index 7251ca8..778389a 100644
--- a/gl/sha1.c
+++ b/gl/sha1.c
@@ -1,8 +1,7 @@
1/* sha1.c - Functions to compute SHA1 message digest of files or 1/* sha1.c - Functions to compute SHA1 message digest of files or
2 memory blocks according to the NIST specification FIPS-180-1. 2 memory blocks according to the NIST specification FIPS-180-1.
3 3
4 Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2008, 2009, 2010 Free 4 Copyright (C) 2000-2001, 2003-2006, 2008-2013 Free Software Foundation, Inc.
5 Software Foundation, Inc.
6 5
7 This program is free software; you can redistribute it and/or modify it 6 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the 7 under the terms of the GNU General Public License as published by the
@@ -15,8 +14,7 @@
15 GNU General Public License for more details. 14 GNU General Public License for more details.
16 15
17 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation, 17 along with this program; if not, see <http://www.gnu.org/licenses/>. */
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
20 18
21/* Written by Scott G. Miller 19/* Written by Scott G. Miller
22 Credits: 20 Credits:
@@ -27,7 +25,8 @@
27 25
28#include "sha1.h" 26#include "sha1.h"
29 27
30#include <stddef.h> 28#include <stdalign.h>
29#include <stdint.h>
31#include <stdlib.h> 30#include <stdlib.h>
32#include <string.h> 31#include <string.h>
33 32
@@ -71,7 +70,7 @@ sha1_init_ctx (struct sha1_ctx *ctx)
71/* Copy the 4 byte value from v into the memory location pointed to by *cp, 70/* Copy the 4 byte value from v into the memory location pointed to by *cp,
72 If your architecture allows unaligned access this is equivalent to 71 If your architecture allows unaligned access this is equivalent to
73 * (uint32_t *) cp = v */ 72 * (uint32_t *) cp = v */
74static inline void 73static void
75set_uint32 (char *cp, uint32_t v) 74set_uint32 (char *cp, uint32_t v)
76{ 75{
77 memcpy (cp, &v, sizeof v); 76 memcpy (cp, &v, sizeof v);
@@ -242,8 +241,7 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
242 if (len >= 64) 241 if (len >= 64)
243 { 242 {
244#if !_STRING_ARCH_unaligned 243#if !_STRING_ARCH_unaligned
245# define alignof(type) offsetof (struct { char c; type x; }, x) 244# define UNALIGNED_P(p) ((uintptr_t) (p) % alignof (uint32_t) != 0)
246# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
247 if (UNALIGNED_P (buffer)) 245 if (UNALIGNED_P (buffer))
248 while (len > 64) 246 while (len > 64)
249 { 247 {
@@ -307,13 +305,13 @@ sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
307 uint32_t c = ctx->C; 305 uint32_t c = ctx->C;
308 uint32_t d = ctx->D; 306 uint32_t d = ctx->D;
309 uint32_t e = ctx->E; 307 uint32_t e = ctx->E;
308 uint32_t lolen = len;
310 309
311 /* First increment the byte count. RFC 1321 specifies the possible 310 /* First increment the byte count. RFC 1321 specifies the possible
312 length of the file up to 2^64 bits. Here we only compute the 311 length of the file up to 2^64 bits. Here we only compute the
313 number of bytes. Do a double word increment. */ 312 number of bytes. Do a double word increment. */
314 ctx->total[0] += len; 313 ctx->total[0] += lolen;
315 if (ctx->total[0] < len) 314 ctx->total[1] += (len >> 31 >> 1) + (ctx->total[0] < lolen);
316 ++ctx->total[1];
317 315
318#define rol(x, n) (((x) << (n)) | ((uint32_t) (x) >> (32 - (n)))) 316#define rol(x, n) (((x) << (n)) | ((uint32_t) (x) >> (32 - (n))))
319 317