summaryrefslogtreecommitdiff
path: root/gl
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2005-10-24 23:33:28 +0000
committerSimon Josefsson <simon@josefsson.org>2005-10-24 23:33:28 +0000
commitab28b8dd19e91a799683ba3b6daa0a89a1f9820d (patch)
treed10428283a000986edc0d5994323449be8f11623 /gl
parent0e99dbd6d874160fb18d292c766e0da52848efeb (diff)
downloadgnutls-ab28b8dd19e91a799683ba3b6daa0a89a1f9820d.tar.gz
Update.
Diffstat (limited to 'gl')
-rw-r--r--gl/gc-gnulib.c275
-rw-r--r--gl/inet_ntop.c258
-rw-r--r--gl/inet_ntop.h11
-rw-r--r--gl/m4/inet_ntop.m42
-rw-r--r--gl/md4.h2
-rw-r--r--gl/md5.c137
-rw-r--r--gl/md5.h2
7 files changed, 395 insertions, 292 deletions
diff --git a/gl/gc-gnulib.c b/gl/gc-gnulib.c
index 68dcc76884..d1f960e131 100644
--- a/gl/gc-gnulib.c
+++ b/gl/gc-gnulib.c
@@ -537,203 +537,268 @@ gc_cipher_close (gc_cipher_handle handle)
/* Hashes. */
+#define MAX_DIGEST_SIZE 20
+
+typedef struct _gc_hash_ctx {
+ Gc_hash alg;
+ Gc_hash_mode mode;
+ char hash[MAX_DIGEST_SIZE];
+#ifdef GC_USE_MD5
+ struct md5_ctx md5Context;
+#endif
+#ifdef GC_USE_MD4
+ struct md4_ctx md4Context;
+#endif
+#ifdef GC_USE_SHA1
+ struct sha1_ctx sha1Context;
+#endif
+} _gc_hash_ctx;
+
Gc_rc
-gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf)
+gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle)
{
+ _gc_hash_ctx *ctx;
+ Gc_rc rc = GC_OK;
+
+ ctx = calloc (sizeof (*ctx), 1);
+
+ ctx->alg = hash;
+ ctx->mode = mode;
+
switch (hash)
{
#ifdef GC_USE_MD4
case GC_MD4:
- md4_buffer (in, inlen, resbuf);
+ md4_init_ctx (&ctx->md4Context);
break;
#endif
#ifdef GC_USE_MD5
case GC_MD5:
- md5_buffer (in, inlen, resbuf);
+ md5_init_ctx (&ctx->md5Context);
break;
#endif
#ifdef GC_USE_SHA1
case GC_SHA1:
- sha1_buffer (in, inlen, resbuf);
+ sha1_init_ctx (&ctx->sha1Context);
break;
#endif
default:
- return GC_INVALID_HASH;
+ rc = GC_INVALID_HASH;
+ break;
}
- return GC_OK;
-}
+ switch (mode)
+ {
+ case 0:
+ break;
-#ifdef GC_USE_MD4
-Gc_rc
-gc_md4 (const void *in, size_t inlen, void *resbuf)
-{
- md4_buffer (in, inlen, resbuf);
- return GC_OK;
-}
-#endif
+ default:
+ rc = GC_INVALID_HASH;
+ break;
+ }
-#ifdef GC_USE_MD5
-Gc_rc
-gc_md5 (const void *in, size_t inlen, void *resbuf)
-{
- md5_buffer (in, inlen, resbuf);
- return GC_OK;
-}
-#endif
+ if (rc == GC_OK)
+ *outhandle = ctx;
+ else
+ free (ctx);
-#ifdef GC_USE_SHA1
-Gc_rc
-gc_sha1 (const void *in, size_t inlen, void *resbuf)
-{
- sha1_buffer (in, inlen, resbuf);
return GC_OK;
}
-#endif
-#ifdef GC_USE_HMAC_MD5
Gc_rc
-gc_hmac_md5 (const void *key, size_t keylen,
- const void *in, size_t inlen, char *resbuf)
+gc_hash_clone (gc_hash_handle handle, gc_hash_handle * outhandle)
{
- hmac_md5 (key, keylen, in, inlen, resbuf);
- return GC_OK;
-}
-#endif
+ _gc_hash_ctx *in = handle;
+ _gc_hash_ctx *out;
+ Gc_rc rc = GC_OK;
-#ifdef GC_USE_HMAC_SHA1
-Gc_rc
-gc_hmac_sha1 (const void *key, size_t keylen,
- const void *in, size_t inlen, char *resbuf)
-{
- hmac_sha1 (key, keylen, in, inlen, resbuf);
- return GC_OK;
-}
-#endif
+ *outhandle = out = calloc (sizeof (*out), 1);
+ if (!out)
+ return GC_MALLOC_ERROR;
-#include <gcrypt.h>
+ memcpy (out, in, sizeof (*out));
-/* Hashes. */
+ return GC_OK;
+}
-Gc_rc
-gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle)
+size_t
+gc_hash_digest_length (Gc_hash hash)
{
- int gcryalg, gcrymode;
- gcry_error_t err;
+ size_t len;
switch (hash)
{
case GC_MD4:
- gcryalg = GCRY_MD_MD4;
+ len = GC_MD4_DIGEST_SIZE;
break;
case GC_MD5:
- gcryalg = GCRY_MD_MD5;
+ len = GC_MD5_DIGEST_SIZE;
break;
case GC_SHA1:
- gcryalg = GCRY_MD_SHA1;
+ len = GC_SHA1_DIGEST_SIZE;
+ break;
+
+ default:
+ return 0;
+ }
+
+ return len;
+}
+
+void
+gc_hash_write (gc_hash_handle handle, size_t len, const char *data)
+{
+ _gc_hash_ctx *ctx = handle;
+ Gc_rc rc = GC_OK;
+
+ switch (ctx->alg)
+ {
+#ifdef GC_USE_MD4
+ case GC_MD4:
+ md4_process_bytes (data, len, &ctx->md4Context);
+ break;
+#endif
+
+#ifdef GC_USE_MD5
+ case GC_MD5:
+ md5_process_bytes (data, len, &ctx->md5Context);
break;
+#endif
- case GC_RMD160:
- gcryalg = GCRY_MD_RMD160;
+#ifdef GC_USE_SHA1
+ case GC_SHA1:
+ sha1_process_bytes (data, len, &ctx->sha1Context);
break;
+#endif
default:
- return GC_INVALID_HASH;
+ break;
}
+}
- switch (mode)
+const char *
+gc_hash_read (gc_hash_handle handle)
+{
+ _gc_hash_ctx *ctx = handle;
+ const char *ret = NULL;
+ Gc_rc rc;
+
+ switch (ctx->alg)
{
- case 0:
- gcrymode = 0;
+#ifdef GC_USE_MD4
+ case GC_MD4:
+ md4_finish_ctx (&ctx->md4Context, ctx->hash);
+ ret = ctx->hash;
+ break;
+#endif
+
+#ifdef GC_USE_MD5
+ case GC_MD5:
+ md5_finish_ctx (&ctx->md5Context, ctx->hash);
+ ret = ctx->hash;
break;
+#endif
- case GC_HMAC:
- gcrymode = GCRY_MD_FLAG_HMAC;
+#ifdef GC_USE_SHA1
+ case GC_SHA1:
+ sha1_finish_ctx (&ctx->sha1Context, ctx->hash);
+ ret = ctx->hash;
break;
+#endif
default:
- return GC_INVALID_HASH;
+ return NULL;
}
- err = gcry_md_open ((gcry_md_hd_t *) outhandle, gcryalg, gcrymode);
- if (gcry_err_code (err))
- return GC_INVALID_HASH;
-
- return GC_OK;
+ return ret;
}
-Gc_rc
-gc_hash_clone (gc_hash_handle handle, gc_hash_handle * outhandle)
+void
+gc_hash_close (gc_hash_handle handle)
{
- int err;
-
- err = gcry_md_copy ((gcry_md_hd_t *) outhandle, (gcry_md_hd_t) handle);
- if (err)
- return GC_INVALID_HASH;
+ _gc_hash_ctx *ctx = handle;
- return GC_OK;
+ free (ctx);
}
-size_t
-gc_hash_digest_length (Gc_hash hash)
+Gc_rc
+gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf)
{
- int gcryalg;
-
switch (hash)
{
+#ifdef GC_USE_MD4
case GC_MD4:
- gcryalg = GCRY_MD_MD4;
+ md4_buffer (in, inlen, resbuf);
break;
+#endif
+#ifdef GC_USE_MD5
case GC_MD5:
- gcryalg = GCRY_MD_MD5;
+ md5_buffer (in, inlen, resbuf);
break;
+#endif
+#ifdef GC_USE_SHA1
case GC_SHA1:
- gcryalg = GCRY_MD_SHA1;
- break;
-
- case GC_RMD160:
- gcryalg = GCRY_MD_RMD160;
+ sha1_buffer (in, inlen, resbuf);
break;
+#endif
default:
- return 0;
+ return GC_INVALID_HASH;
}
- return gcry_md_get_algo_dlen (gcryalg);
+ return GC_OK;
}
-void
-gc_hash_hmac_setkey (gc_hash_handle handle, size_t len, const char *key)
+#ifdef GC_USE_MD4
+Gc_rc
+gc_md4 (const void *in, size_t inlen, void *resbuf)
{
- gcry_md_setkey ((gcry_md_hd_t) handle, key, len);
+ md4_buffer (in, inlen, resbuf);
+ return GC_OK;
}
+#endif
-void
-gc_hash_write (gc_hash_handle handle, size_t len, const char *data)
+#ifdef GC_USE_MD5
+Gc_rc
+gc_md5 (const void *in, size_t inlen, void *resbuf)
{
- gcry_md_write ((gcry_md_hd_t) handle, data, len);
+ md5_buffer (in, inlen, resbuf);
+ return GC_OK;
}
+#endif
-const char *
-gc_hash_read (gc_hash_handle handle)
+#ifdef GC_USE_SHA1
+Gc_rc
+gc_sha1 (const void *in, size_t inlen, void *resbuf)
{
- const char *digest;
-
- gcry_md_final ((gcry_md_hd_t) handle);
- digest = gcry_md_read ((gcry_md_hd_t) handle, 0);
+ sha1_buffer (in, inlen, resbuf);
+ return GC_OK;
+}
+#endif
- return digest;
+#ifdef GC_USE_HMAC_MD5
+Gc_rc
+gc_hmac_md5 (const void *key, size_t keylen,
+ const void *in, size_t inlen, char *resbuf)
+{
+ hmac_md5 (key, keylen, in, inlen, resbuf);
+ return GC_OK;
}
+#endif
-void
-gc_hash_close (gc_hash_handle handle)
+#ifdef GC_USE_HMAC_SHA1
+Gc_rc
+gc_hmac_sha1 (const void *key, size_t keylen,
+ const void *in, size_t inlen, char *resbuf)
{
- gcry_md_close ((gcry_md_hd_t) handle);
+ hmac_sha1 (key, keylen, in, inlen, resbuf);
+ return GC_OK;
}
+#endif
diff --git a/gl/inet_ntop.c b/gl/inet_ntop.c
index 752f063874..a6b17265dc 100644
--- a/gl/inet_ntop.c
+++ b/gl/inet_ntop.c
@@ -1,6 +1,22 @@
+/* inet_ntop.c -- convert IPv4 and IPv6 addresses from binary to text form
+ Copyright (c) 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser 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. */
+
/*
* Copyright (c) 1996-1999 by Internet Software Consortium.
- * Copyright (c) 2005 Free Software Foundation, Inc.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -27,6 +43,10 @@
#include <string.h>
#include <errno.h>
+#ifndef EAFNOSUPPORT
+# define EAFNOSUPPORT EINVAL
+#endif
+
#define NS_IN6ADDRSZ 16
#define NS_INT16SZ 2
@@ -34,7 +54,7 @@
* WARNING: Don't even consider trying to compile this on a system where
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
*/
-typedef int verify_int_size[2 * sizeof(int) - 7];
+typedef int verify_int_size[2 * sizeof (int) - 7];
#if HAVE_IPV4
static const char *inet_ntop4 (const unsigned char *src, char *dst, socklen_t size);
@@ -53,28 +73,26 @@ static const char *inet_ntop6 (const unsigned char *src, char *dst, socklen_t si
* Paul Vixie, 1996.
*/
const char *
-inet_ntop(af, src, dst, size)
- int af;
- const void *src;
- char *dst;
- socklen_t size;
+inet_ntop (int af, const void *restrict src,
+ char *restrict dst, socklen_t cnt)
{
- switch (af) {
-
+ switch (af)
+ {
#if HAVE_IPV4
- case AF_INET:
- return (inet_ntop4(src, dst, size));
+ case AF_INET:
+ return (inet_ntop4 (src, dst, size));
#endif
#if HAVE_IPV6
- case AF_INET6:
- return (inet_ntop6(src, dst, size));
+ case AF_INET6:
+ return (inet_ntop6 (src, dst, size));
#endif
- default:
- errno = EAFNOSUPPORT;
- return (NULL);
- }
- /* NOTREACHED */
+
+ default:
+ errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+ /* NOTREACHED */
}
#if HAVE_IPV4
@@ -91,19 +109,22 @@ inet_ntop(af, src, dst, size)
* Paul Vixie, 1996.
*/
static const char *
-inet_ntop4(src, dst, size)
- const unsigned char *src;
- char *dst;
- socklen_t size;
+inet_ntop4 (const unsigned char *src, char *dst, socklen_t size)
{
- static const char fmt[] = "%u.%u.%u.%u";
- char tmp[sizeof "255.255.255.255"];
+ char tmp[sizeof "255.255.255.255"];
+ int len;
- if (sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) > size) {
- errno = ENOSPC;
- return (NULL);
- }
- return strcpy(dst, tmp);
+ len = sprintf (tmp, "%u.%u.%u.%u", src[0], src[1], src[2], src[3]);
+ if (len < 0)
+ return NULL;
+
+ if (len > size)
+ {
+ errno = ENOSPC;
+ return NULL;
+ }
+
+ return strcpy (dst, tmp);
}
#endif
@@ -117,93 +138,108 @@ inet_ntop4(src, dst, size)
* Paul Vixie, 1996.
*/
static const char *
-inet_ntop6(src, dst, size)
- const unsigned char *src;
- char *dst;
- socklen_t size;
+inet_ntop6 (const unsigned char *src, char *dst, socklen_t size)
{
- /*
- * Note that int32_t and int16_t need only be "at least" large enough
- * to contain a value of the specified size. On some systems, like
- * Crays, there is no such thing as an integer variable with 16 bits.
- * Keep this in mind if you think this function should have been coded
- * to use pointer overlays. All the world's not a VAX.
- */
- char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
- struct { int base, len; } best, cur;
- unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
- int i;
-
- /*
- * Preprocess:
- * Copy the input (bytewise) array into a wordwise array.
- * Find the longest run of 0x00's in src[] for :: shorthanding.
- */
- memset(words, '\0', sizeof words);
- for (i = 0; i < NS_IN6ADDRSZ; i += 2)
- words[i / 2] = (src[i] << 8) | src[i + 1];
- best.base = -1;
- cur.base = -1;
- for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
- if (words[i] == 0) {
- if (cur.base == -1)
- cur.base = i, cur.len = 1;
- else
- cur.len++;
- } else {
- if (cur.base != -1) {
- if (best.base == -1 || cur.len > best.len)
- best = cur;
- cur.base = -1;
- }
- }
+ /*
+ * Note that int32_t and int16_t need only be "at least" large enough
+ * to contain a value of the specified size. On some systems, like
+ * Crays, there is no such thing as an integer variable with 16 bits.
+ * Keep this in mind if you think this function should have been coded
+ * to use pointer overlays. All the world's not a VAX.
+ */
+ char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
+ struct
+ {
+ int base, len;
+ } best, cur;
+ unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
+ int i;
+
+ /*
+ * Preprocess:
+ * Copy the input (bytewise) array into a wordwise array.
+ * Find the longest run of 0x00's in src[] for :: shorthanding.
+ */
+ memset (words, '\0', sizeof words);
+ for (i = 0; i < NS_IN6ADDRSZ; i += 2)
+ words[i / 2] = (src[i] << 8) | src[i + 1];
+ best.base = -1;
+ cur.base = -1;
+ for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
+ {
+ if (words[i] == 0)
+ {
+ if (cur.base == -1)
+ cur.base = i, cur.len = 1;
+ else
+ cur.len++;
}
- if (cur.base != -1) {
- if (best.base == -1 || cur.len > best.len)
- best = cur;
+ else
+ {
+ if (cur.base != -1)
+ {
+ if (best.base == -1 || cur.len > best.len)
+ best = cur;
+ cur.base = -1;
+ }
}
- if (best.base != -1 && best.len < 2)
- best.base = -1;
-
- /*
- * Format the result.
- */
- tp = tmp;
- for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
- /* Are we inside the best run of 0x00's? */
- if (best.base != -1 && i >= best.base &&
- i < (best.base + best.len)) {
- if (i == best.base)
- *tp++ = ':';
- continue;
- }
- /* Are we following an initial run of 0x00s or any real hex? */
- if (i != 0)
- *tp++ = ':';
- /* Is this address an encapsulated IPv4? */
- if (i == 6 && best.base == 0 &&
- (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
- if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
- return (NULL);
- tp += strlen(tp);
- break;
- }
- tp += sprintf(tp, "%x", words[i]);
+ }
+ if (cur.base != -1)
+ {
+ if (best.base == -1 || cur.len > best.len)
+ best = cur;
+ }
+ if (best.base != -1 && best.len < 2)
+ best.base = -1;
+
+ /*
+ * Format the result.
+ */
+ tp = tmp;
+ for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
+ {
+ /* Are we inside the best run of 0x00's? */
+ if (best.base != -1 && i >= best.base && i < (best.base + best.len))
+ {
+ if (i == best.base)
+ *tp++ = ':';
+ continue;
}
- /* Was it a trailing run of 0x00's? */
- if (best.base != -1 && (best.base + best.len) ==
- (NS_IN6ADDRSZ / NS_INT16SZ))
- *tp++ = ':';
- *tp++ = '\0';
-
- /*
- * Check for overflow, copy, and we're done.
- */
- if ((socklen_t)(tp - tmp) > size) {
- errno = ENOSPC;
- return (NULL);
+ /* Are we following an initial run of 0x00s or any real hex? */
+ if (i != 0)
+ *tp++ = ':';
+ /* Is this address an encapsulated IPv4? */
+ if (i == 6 && best.base == 0 &&
+ (best.len == 6 || (best.len == 5 && words[5] == 0xffff)))
+ {
+ if (!inet_ntop4 (src + 12, tp, sizeof tmp - (tp - tmp)))
+ return (NULL);
+ tp += strlen (tp);
+ break;
}
- return strcpy(dst, tmp);
+ {
+ int len = sprintf (tp, "%x", words[i]);
+ if (len < 0)
+ return NULL;
+ tp += len;
+ }
+ }
+ /* Was it a trailing run of 0x00's? */
+ if (best.base != -1 && (best.base + best.len) ==
+ (NS_IN6ADDRSZ / NS_INT16SZ))
+ *tp++ = ':';
+ *tp++ = '\0';
+
+ /*
+ * Check for overflow, copy, and we're done.
+ */
+ if ((socklen_t) (tp - tmp) > size)
+ {
+ errno = ENOSPC;
+ return NULL;
+ }
+
+ return strcpy (dst, tmp);
}
#endif
diff --git a/gl/inet_ntop.h b/gl/inet_ntop.h
index 30b9f4c996..6565f0bade 100644
--- a/gl/inet_ntop.h
+++ b/gl/inet_ntop.h
@@ -16,9 +16,9 @@
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+#ifdef HAVE_ARPA_INET_H
+# include <arpa/inet.h>
+#endif
/* Converts an internet address from internal format to a printable,
presentable format.
@@ -36,6 +36,7 @@
For more details, see the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/inet_ntop.html>. */
-#if !HAVE_INET_NTOP /* not already defined and declared in <arpa/inet.h> ? */
-extern const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt);
+#ifndef HAVE_DECL_INET_NTOP
+extern const char *inet_ntop (int af, const void *restrict src,
+ char *restrict dst, socklen_t cnt);
#endif
diff --git a/gl/m4/inet_ntop.m4 b/gl/m4/inet_ntop.m4
index fea429e74b..7ffbbda45b 100644
--- a/gl/m4/inet_ntop.m4
+++ b/gl/m4/inet_ntop.m4
@@ -12,5 +12,7 @@ AC_DEFUN([gl_INET_NTOP],
# Prerequisites of lib/inet_ntop.h and lib/inet_ntop.c.
AC_DEFUN([gl_PREREQ_INET_NTOP], [
+ AC_CHECK_HEADERS_ONCE(sys/types.h arpa/inet.h)
+ AC_CHECK_DECLS([inet_ntop],,,[#include <arpa/inet.h>])
AC_REQUIRE([gl_SOCKET_FAMILIES])
])
diff --git a/gl/md4.h b/gl/md4.h
index d94907e6c3..8450664774 100644
--- a/gl/md4.h
+++ b/gl/md4.h
@@ -34,7 +34,7 @@ struct md4_ctx
uint32_t total[2];
uint32_t buflen;
- uint32_t buffer[128];
+ uint32_t buffer[32];
};
diff --git a/gl/md5.c b/gl/md5.c
index eb2ff8c87a..35ecbd135c 100644
--- a/gl/md5.c
+++ b/gl/md5.c
@@ -108,23 +108,21 @@ md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
{
/* Take yet unprocessed bytes into account. */
uint32_t bytes = ctx->buflen;
- size_t pad;
+ size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;
/* Now count remaining bytes. */
ctx->total[0] += bytes;
if (ctx->total[0] < bytes)
++ctx->total[1];
- pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
- memcpy (&ctx->buffer[bytes], fillbuf, pad);
-
/* Put the 64-bit file length in *bits* at the end of the buffer. */
- *(uint32_t *) &ctx->buffer[bytes + pad] = SWAP (ctx->total[0] << 3);
- *(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP ((ctx->total[1] << 3) |
- (ctx->total[0] >> 29));
+ ctx->buffer[size - 2] = SWAP (ctx->total[0] << 3);
+ ctx->buffer[size - 1] = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29));
+
+ memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes);
/* Process last bytes. */
- md5_process_block (ctx->buffer, bytes + pad + 8, ctx);
+ md5_process_block (ctx->buffer, size * 4, ctx);
return md5_read_ctx (ctx, resbuf);
}
@@ -146,8 +144,8 @@ md5_stream (FILE *stream, void *resblock)
while (1)
{
/* We read the file in blocks of BLOCKSIZE bytes. One call of the
- computation function processes the whole buffer so that with the
- next round of the loop another block can be read. */
+ computation function processes the whole buffer so that with the
+ next round of the loop another block can be read. */
size_t n;
sum = 0;
@@ -164,8 +162,8 @@ md5_stream (FILE *stream, void *resblock)
if (n == 0)
{
/* Check for the error flag IFF N == 0, so that we don't
- exit the loop after a partial read due to e.g., EAGAIN
- or EWOULDBLOCK. */
+ exit the loop after a partial read due to e.g., EAGAIN
+ or EWOULDBLOCK. */
if (ferror (stream))
return 1;
goto process_partial_block;
@@ -179,12 +177,12 @@ md5_stream (FILE *stream, void *resblock)
}
/* Process buffer with BLOCKSIZE bytes. Note that
- BLOCKSIZE % 64 == 0
+ BLOCKSIZE % 64 == 0
*/
md5_process_block (buffer, BLOCKSIZE, &ctx);
}
- process_partial_block:;
+process_partial_block:
/* Process any remaining bytes. */
if (sum > 0)
@@ -225,7 +223,7 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
size_t left_over = ctx->buflen;
size_t add = 128 - left_over > len ? len : 128 - left_over;
- memcpy (&ctx->buffer[left_over], buffer, add);
+ memcpy (&((char *) ctx->buffer)[left_over], buffer, add);
ctx->buflen += add;
if (ctx->buflen > 64)
@@ -234,7 +232,8 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
ctx->buflen &= 63;
/* The regions in the following copy operation cannot overlap. */
- memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
+ memcpy (ctx->buffer,
+ &((char *) ctx->buffer)[(left_over + add) & ~63],
ctx->buflen);
}
@@ -275,13 +274,13 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
{
size_t left_over = ctx->buflen;
- memcpy (&ctx->buffer[left_over], buffer, len);
+ memcpy (&((char *) ctx->buffer)[left_over], buffer, len);
left_over += len;
if (left_over >= 64)
{
md5_process_block (ctx->buffer, 64, ctx);
left_over -= 64;
- memcpy (ctx->buffer, &ctx->buffer[64], left_over);
+ memcpy (ctx->buffer, &ctx->buffer[16], left_over);
}
ctx->buflen = left_over;
}
@@ -330,11 +329,11 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
uint32_t D_save = D;
/* First round: using the given function, the context and a constant
- the next context is computed. Because the algorithms processing
- unit is a 32-bit word and it is determined to work on words in
- little endian byte order we perhaps have to change the byte order
- before the computation. To reduce the work for the next steps
- we store the swapped words in the array CORRECT_WORDS. */
+ the next context is computed. Because the algorithms processing
+ unit is a 32-bit word and it is determined to work on words in
+ little endian byte order we perhaps have to change the byte order
+ before the computation. To reduce the work for the next steps
+ we store the swapped words in the array CORRECT_WORDS. */
#define OP(a, b, c, d, s, T) \
do \
@@ -347,40 +346,40 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
while (0)
/* It is unfortunate that C does not provide an operator for
- cyclic rotation. Hope the C compiler is smart enough. */
+ cyclic rotation. Hope the C compiler is smart enough. */
#define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))
/* Before we start, one word to the strange constants.
- They are defined in RFC 1321 as
+ They are defined in RFC 1321 as
- T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64
+ T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64
- Here is an equivalent invocation using Perl:
+ Here is an equivalent invocation using Perl:
- perl -e 'foreach(1..64){printf "0x%08x\n", int (4294967296 * abs (sin $_))}'
+ perl -e 'foreach(1..64){printf "0x%08x\n", int (4294967296 * abs (sin $_))}'
*/
/* Round 1. */
- OP (A, B, C, D, 7, 0xd76aa478);
+ OP (A, B, C, D, 7, 0xd76aa478);
OP (D, A, B, C, 12, 0xe8c7b756);
OP (C, D, A, B, 17, 0x242070db);
OP (B, C, D, A, 22, 0xc1bdceee);
- OP (A, B, C, D, 7, 0xf57c0faf);
+ OP (A, B, C, D, 7, 0xf57c0faf);
OP (D, A, B, C, 12, 0x4787c62a);
OP (C, D, A, B, 17, 0xa8304613);
OP (B, C, D, A, 22, 0xfd469501);
- OP (A, B, C, D, 7, 0x698098d8);
+ OP (A, B, C, D, 7, 0x698098d8);
OP (D, A, B, C, 12, 0x8b44f7af);
OP (C, D, A, B, 17, 0xffff5bb1);
OP (B, C, D, A, 22, 0x895cd7be);
- OP (A, B, C, D, 7, 0x6b901122);
+ OP (A, B, C, D, 7, 0x6b901122);
OP (D, A, B, C, 12, 0xfd987193);
OP (C, D, A, B, 17, 0xa679438e);
OP (B, C, D, A, 22, 0x49b40821);
/* For the second to fourth round we have the possibly swapped words
- in CORRECT_WORDS. Redefine the macro to take an additional first
- argument specifying the function to use. */
+ in CORRECT_WORDS. Redefine the macro to take an additional first
+ argument specifying the function to use. */
#undef OP
#define OP(f, a, b, c, d, k, s, T) \
do \
@@ -392,58 +391,58 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
while (0)
/* Round 2. */
- OP (FG, A, B, C, D, 1, 5, 0xf61e2562);
- OP (FG, D, A, B, C, 6, 9, 0xc040b340);
+ OP (FG, A, B, C, D, 1, 5, 0xf61e2562);
+ OP (FG, D, A, B, C, 6, 9, 0xc040b340);
OP (FG, C, D, A, B, 11, 14, 0x265e5a51);
- OP (FG, B, C, D, A, 0, 20, 0xe9b6c7aa);
- OP (FG, A, B, C, D, 5, 5, 0xd62f105d);
- OP (FG, D, A, B, C, 10, 9, 0x02441453);
+ OP (FG, B, C, D, A, 0, 20, 0xe9b6c7aa);
+ OP (FG, A, B, C, D, 5, 5, 0xd62f105d);
+ OP (FG, D, A, B, C, 10, 9, 0x02441453);
OP (FG, C, D, A, B, 15, 14, 0xd8a1e681);
- OP (FG, B, C, D, A, 4, 20, 0xe7d3fbc8);
- OP (FG, A, B, C, D, 9, 5, 0x21e1cde6);
- OP (FG, D, A, B, C, 14, 9, 0xc33707d6);
- OP (FG, C, D, A, B, 3, 14, 0xf4d50d87);
- OP (FG, B, C, D, A, 8, 20, 0x455a14ed);
- OP (FG, A, B, C, D, 13, 5, 0xa9e3e905);
- OP (FG, D, A, B, C, 2, 9, 0xfcefa3f8);
- OP (FG, C, D, A, B, 7, 14, 0x676f02d9);
+ OP (FG, B, C, D, A, 4, 20, 0xe7d3fbc8);
+ OP (FG, A, B, C, D, 9, 5, 0x21e1cde6);
+ OP (FG, D, A, B, C, 14, 9, 0xc33707d6);
+ OP (FG, C, D, A, B, 3, 14, 0xf4d50d87);
+ OP (FG, B, C, D, A, 8, 20, 0x455a14ed);
+ OP (FG, A, B, C, D, 13, 5, 0xa9e3e905);
+ OP (FG, D, A, B, C, 2, 9, 0xfcefa3f8);
+ OP (FG, C, D, A, B, 7, 14, 0x676f02d9);
OP (FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
/* Round 3. */
- OP (FH, A, B, C, D, 5, 4, 0xfffa3942);
- OP (FH, D, A, B, C, 8, 11, 0x8771f681);
+ OP (FH, A, B, C, D, 5, 4, 0xfffa3942);
+ OP (FH, D, A, B, C, 8, 11, 0x8771f681);
OP (FH, C, D, A, B, 11, 16, 0x6d9d6122);
OP (FH, B, C, D, A, 14, 23, 0xfde5380c);
- OP (FH, A, B, C, D, 1, 4, 0xa4beea44);
- OP (FH, D, A, B, C, 4, 11, 0x4bdecfa9);
- OP (FH, C, D, A, B, 7, 16, 0xf6bb4b60);
+ OP (FH, A, B, C, D, 1, 4, 0xa4beea44);
+ OP (FH, D, A, B, C, 4, 11, 0x4bdecfa9);
+ OP (FH, C, D, A, B, 7, 16, 0xf6bb4b60);
OP (FH, B, C, D, A, 10, 23, 0xbebfbc70);
- OP (FH, A, B, C, D, 13, 4, 0x289b7ec6);
- OP (FH, D, A, B, C, 0, 11, 0xeaa127fa);
- OP (FH, C, D, A, B, 3, 16, 0xd4ef3085);
- OP (FH, B, C, D, A, 6, 23, 0x04881d05);
- OP (FH, A, B, C, D, 9, 4, 0xd9d4d039);
+ OP (FH, A, B, C, D, 13, 4, 0x289b7ec6);
+ OP (FH, D, A, B, C, 0, 11, 0xeaa127fa);
+ OP (FH, C, D, A, B, 3, 16, 0xd4ef3085);
+ OP (FH, B, C, D, A, 6, 23, 0x04881d05);
+ OP (FH, A, B, C, D, 9, 4, 0xd9d4d039);
OP (FH, D, A, B, C, 12, 11, 0xe6db99e5);
OP (FH, C, D, A, B, 15, 16, 0x1fa27cf8);
- OP (FH, B, C, D, A, 2, 23, 0xc4ac5665);
+ OP (FH, B, C, D, A, 2, 23, 0xc4ac5665);
/* Round 4. */
- OP (FI, A, B, C, D, 0, 6, 0xf4292244);
- OP (FI, D, A, B, C, 7, 10, 0x432aff97);
+ OP (FI, A, B, C, D, 0, 6, 0xf4292244);
+ OP (FI, D, A, B, C, 7, 10, 0x432aff97);
OP (FI, C, D, A, B, 14, 15, 0xab9423a7);
- OP (FI, B, C, D, A, 5, 21, 0xfc93a039);
- OP (FI, A, B, C, D, 12, 6, 0x655b59c3);
- OP (FI, D, A, B, C, 3, 10, 0x8f0ccc92);
+ OP (FI, B, C, D, A, 5, 21, 0xfc93a039);
+ OP (FI, A, B, C, D, 12, 6, 0x655b59c3);
+ OP (FI, D, A, B, C, 3, 10, 0x8f0ccc92);
OP (FI, C, D, A, B, 10, 15, 0xffeff47d);
- OP (FI, B, C, D, A, 1, 21, 0x85845dd1);
- OP (FI, A, B, C, D, 8, 6, 0x6fa87e4f);
+ OP (FI, B, C, D, A, 1, 21, 0x85845dd1);
+ OP (FI, A, B, C, D, 8, 6, 0x6fa87e4f);
OP (FI, D, A, B, C, 15, 10, 0xfe2ce6e0);
- OP (FI, C, D, A, B, 6, 15, 0xa3014314);
+ OP (FI, C, D, A, B, 6, 15, 0xa3014314);
OP (FI, B, C, D, A, 13, 21, 0x4e0811a1);
- OP (FI, A, B, C, D, 4, 6, 0xf7537e82);
+ OP (FI, A, B, C, D, 4, 6, 0xf7537e82);
OP (FI, D, A, B, C, 11, 10, 0xbd3af235);
- OP (FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
- OP (FI, B, C, D, A, 9, 21, 0xeb86d391);
+ OP (FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
+ OP (FI, B, C, D, A, 9, 21, 0xeb86d391);
/* Add the starting values of the context. */
A += A_save;
diff --git a/gl/md5.h b/gl/md5.h
index 56026c2931..c03bb2902d 100644
--- a/gl/md5.h
+++ b/gl/md5.h
@@ -70,7 +70,7 @@ struct md5_ctx
uint32_t total[2];
uint32_t buflen;
- char buffer[128] __attribute__ ((__aligned__ (__alignof__ (uint32_t))));
+ uint32_t buffer[32];
};
/*