]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Update.
authorSimon Josefsson <simon@josefsson.org>
Thu, 19 Jan 2006 10:20:44 +0000 (10:20 +0000)
committerSimon Josefsson <simon@josefsson.org>
Thu, 19 Jan 2006 10:20:44 +0000 (10:20 +0000)
gl/Makefile.am
gl/m4/gnulib-comp.m4
gl/m4/sys_socket_h.m4 [new file with mode: 0644]
gl/md5.c
gl/md5.h
gl/sha1.c
gl/sha1.h
gl/socket_.h [new file with mode: 0644]

index c2d4a107c02f7b3848d126f3daff83c034e30bfb..0ef215aad3381fd10ada08a86f7826d658b443c3 100644 (file)
@@ -107,6 +107,24 @@ MOSTLYCLEANFILES += stdint.h stdint.h-t
 
 ## end   gnulib module stdint
 
+## begin gnulib module sys_socket
+
+BUILT_SOURCES += $(SYS_SOCKET_H)
+EXTRA_DIST += socket_.h
+
+# We need the following in order to create <sys/socket.h> when the system
+# doesn't have one that works with the given compiler.
+sys/socket.h: socket_.h
+       test -d sys || mkdir sys
+       cp $(srcdir)/socket_.h $@-t
+       mv $@-t $@
+MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t
+
+mostlyclean-local:
+       -rmdir sys 2>/dev/null
+
+## end   gnulib module sys_socket
+
 ## begin gnulib module vasnprintf
 
 libgnu_la_SOURCES += printf-args.h printf-parse.h vasnprintf.h
index ea09cc58d70c21415942a2b46d54e2ab956ca568..b8a4b16d4967046e16f319fbe9a4dd3189a64891 100644 (file)
@@ -55,6 +55,7 @@ AC_DEFUN([gl_INIT],
   gl_TYPE_SOCKLEN_T
   AM_STDBOOL_H
   gl_STDINT_H
+  gl_HEADER_SYS_SOCKET
   gl_FUNC_VASNPRINTF
   gl_XSIZE
 ])
@@ -114,6 +115,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/size_max.h
   lib/snprintf.c
   lib/snprintf.h
+  lib/socket_.h
   lib/stdbool_.h
   lib/stdint_.h
   lib/vasnprintf.c
@@ -170,6 +172,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/stdbool.m4
   m4/stdint.m4
   m4/stdint_h.m4
+  m4/sys_socket_h.m4
   m4/vasnprintf.m4
   m4/wchar_t.m4
   m4/wint_t.m4
diff --git a/gl/m4/sys_socket_h.m4 b/gl/m4/sys_socket_h.m4
new file mode 100644 (file)
index 0000000..10d042c
--- /dev/null
@@ -0,0 +1,19 @@
+# sys_socket_h.m4 serial 1
+dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Simon Josefsson.
+
+AC_DEFUN([gl_HEADER_SYS_SOCKET],
+[
+  AC_CHECK_HEADERS_ONCE([sys/socket.h])
+  if test $ac_cv_header_sys_socket_h = yes; then
+    SYS_SOCKET_H=''
+  else
+    AC_CHECK_HEADERS_ONCE([winsock2.h ws2tcpip.h])
+    SYS_SOCKET_H='sys/socket.h'
+  fi
+  AC_SUBST(SYS_SOCKET_H)
+])
index 35ecbd135c9010e67927afbc1b446e3401ba3968..5e7695c5f6b9d2f9ecf272fec191b7a26d813baa 100644 (file)
--- a/gl/md5.c
+++ b/gl/md5.c
@@ -1,6 +1,6 @@
 /* Functions to compute MD5 message digest of files or memory blocks.
    according to the definition of MD5 in RFC 1321 from April 1992.
-   Copyright (C) 1995,1996,1997,1999,2000,2001,2005
+   Copyright (C) 1995,1996,1997,1999,2000,2001,2005,2006
        Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -86,7 +86,7 @@ md5_init_ctx (struct md5_ctx *ctx)
    must be in little endian byte order.
 
    IMPORTANT: On some systems it is required that RESBUF is correctly
-   aligned for a 32 bits value.  */
+   aligned for a 32-bit value.  */
 void *
 md5_read_ctx (const struct md5_ctx *ctx, void *resbuf)
 {
@@ -102,7 +102,7 @@ md5_read_ctx (const struct md5_ctx *ctx, void *resbuf)
    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 bits value.  */
+   aligned for a 32-bit value.  */
 void *
 md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
 {
@@ -245,14 +245,8 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
   if (len >= 64)
     {
 #if !_STRING_ARCH_unaligned
-/* To check alignment gcc has an appropriate operator.  Other
-   compilers don't.  */
-# if __GNUC__ >= 2
-#  define UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint32_t) != 0)
-# else
-#  define alignof(type) offsetof (struct { char c; type x; }, x)
-#  define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
-# endif
+# define alignof(type) offsetof (struct { char c; type x; }, x)
+# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
       if (UNALIGNED_P (buffer))
        while (len > 64)
          {
@@ -382,7 +376,7 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
          argument specifying the function to use.  */
 #undef OP
 #define OP(f, a, b, c, d, k, s, T)                                     \
-      do                                                               \
+      do                                                               \
        {                                                               \
          a += f (b, c, d) + correct_words[k] + T;                      \
          CYCLIC (a, s);                                                \
index c03bb2902de4fa732a87365e77236b42599307e1..6018a6f6d56b99e371c2af0ba8d3ffc4268efaaf 100644 (file)
--- a/gl/md5.h
+++ b/gl/md5.h
@@ -1,6 +1,6 @@
 /* Declaration of functions and data types used for MD5 sum computing
    library functions.
-   Copyright (C) 1995-1997,1999,2000,2001,2004,2005
+   Copyright (C) 1995-1997,1999,2000,2001,2004,2005,2006
       Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
 # endif
 #endif
 
-#ifndef __attribute__
-# if ! __GNUC_PREREQ (2,8) || __STRICT_ANSI__
-#  define __attribute__(x)
-# endif
-#endif
-
 #ifndef _LIBC
 # define __md5_buffer md5_buffer
 # define __md5_finish_ctx md5_finish_ctx
index 7bc0ba9c45813195c6c53d2c189882baba9ab633..5472340351512137ec8a803832f98ba89ee669e3 100644 (file)
--- a/gl/sha1.c
+++ b/gl/sha1.c
@@ -1,7 +1,8 @@
 /* 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 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006 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
@@ -35,9 +36,6 @@
 # include "unlocked-io.h"
 #endif
 
-/* SWAP does an endian swap on architectures that are little-endian,
-   as SHA1 needs some data in a big-endian form.  */
-
 #ifdef WORDS_BIGENDIAN
 # define SWAP(n) (n)
 #else
 static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ...  */ };
 
 
-/*
-  Takes a pointer to a 160 bit block of data (five 32 bit ints) and
-  intializes it to the start constants of the SHA1 algorithm.  This
-  must be called before using hash in the call to sha1_hash.
-*/
+/* Take a pointer to a 160 bit block of data (five 32 bit ints) and
+   initialize it to the start constants of the SHA1 algorithm.  This
+   must be called before using hash in the call to sha1_hash.  */
 void
 sha1_init_ctx (struct sha1_ctx *ctx)
 {
@@ -100,23 +96,21 @@ sha1_finish_ctx (struct sha1_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 + 4] = SWAP (ctx->total[0] << 3);
-  *(uint32_t *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) |
-                                                   (ctx->total[0] >> 29));
+  ctx->buffer[size - 2] = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29));
+  ctx->buffer[size - 1] = SWAP (ctx->total[0] << 3);
+
+  memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes);
 
   /* Process last bytes.  */
-  sha1_process_block (ctx->buffer, bytes + pad + 8, ctx);
+  sha1_process_block (ctx->buffer, size * 4, ctx);
 
   return sha1_read_ctx (ctx, resbuf);
 }
@@ -216,7 +210,7 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_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)
@@ -225,7 +219,8 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_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);
        }
 
@@ -260,13 +255,13 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_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)
        {
          sha1_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;
     }
index fc6982dfe307aeb0edbc612acea58595b200df0a..ed0de2b4e809fe6b1cc1e7e6a899ad3a2475748d 100644 (file)
--- a/gl/sha1.h
+++ b/gl/sha1.h
@@ -1,6 +1,6 @@
 /* Declarations of functions and data types used for SHA1 sum
    library functions.
-   Copyright (C) 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2003, 2005, 2006 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
@@ -33,7 +33,7 @@ struct sha1_ctx
 
   uint32_t total[2];
   uint32_t buflen;
-  char buffer[128] __attribute__ ((__aligned__ (__alignof__ (uint32_t))));
+  uint32_t buffer[32];
 };
 
 
diff --git a/gl/socket_.h b/gl/socket_.h
new file mode 100644 (file)
index 0000000..8d3c077
--- /dev/null
@@ -0,0 +1,48 @@
+/* Provide a sys/socket header file for systems lacking it (read: mingw32).
+   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+   Written by Simon Josefsson.
+
+   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.  */
+
+#ifndef _SYS_SOCKET_H
+#define _SYS_SOCKET_H
+
+/* This file is supposed to be used on platforms that lack
+   sys/socket.h.  It is intended to provide definitions and prototypes
+   needed by an application.
+
+   Currently only mingw32 is supported, which has the header files
+   winsock2.h and ws2tcpip.h that declare the sys/socket.h definitions
+   we need. */
+
+#if HAVE_WINSOCK2_H
+# include <winsock2.h>
+#endif
+#if HAVE_WS2TCPIP_H
+# include <ws2tcpip.h>
+#endif
+
+/* For shutdown(). */
+#ifndef SHUT_RD
+# define SHUT_RD 0
+#endif
+#ifndef SHUT_WR
+# define SHUT_WR 1
+#endif
+#ifndef SHUT_RDWR
+# define SHUT_RDWR 2
+#endif
+
+#endif /* _SYS_SOCKET_H */