X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fsha1.c;h=9c6c7ae3933d7b45a945a2404414b01bd2e4e95d;hb=cb9819cbb9261bd50c3466cf0a4cd873f0d7ebd7;hp=dadf97361e90a5cfec73590613809520f4edcc8b;hpb=5912e24cb503d5238ab9180b98f0215e871a6abc;p=gnulib.git diff --git a/lib/sha1.c b/lib/sha1.c index dadf97361..9c6c7ae39 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -1,7 +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 Free Software + Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2008 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it @@ -23,9 +23,7 @@ Robert Klep -- Expansion function fix */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include "sha1.h" @@ -69,28 +67,32 @@ sha1_init_ctx (struct sha1_ctx *ctx) ctx->buflen = 0; } -/* Put result from CTX in first 20 bytes following RESBUF. The result - must be in little endian byte order. +/* 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 +set_uint32 (char *cp, uint32_t v) +{ + memcpy (cp, &v, sizeof v); +} - IMPORTANT: On some systems it is required that RESBUF is correctly - aligned for a 32-bit value. */ +/* Put result from CTX in first 20 bytes following RESBUF. The result + must be in little endian byte order. */ void * sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf) { - ((uint32_t *) resbuf)[0] = SWAP (ctx->A); - ((uint32_t *) resbuf)[1] = SWAP (ctx->B); - ((uint32_t *) resbuf)[2] = SWAP (ctx->C); - ((uint32_t *) resbuf)[3] = SWAP (ctx->D); - ((uint32_t *) resbuf)[4] = SWAP (ctx->E); + char *r = resbuf; + set_uint32 (r + 0 * sizeof ctx->A, SWAP (ctx->A)); + set_uint32 (r + 1 * sizeof ctx->B, SWAP (ctx->B)); + set_uint32 (r + 2 * sizeof ctx->C, SWAP (ctx->C)); + set_uint32 (r + 3 * sizeof ctx->D, SWAP (ctx->D)); + set_uint32 (r + 4 * sizeof ctx->E, SWAP (ctx->E)); return resbuf; } /* Process the remaining bytes in the internal buffer and the usual - prolog according to the standard and write the result to RESBUF. - - IMPORTANT: On some systems it is required that RESBUF is correctly - aligned for a 32-bit value. */ + prolog according to the standard and write the result to RESBUF. */ void * sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf) {