xgethostbyname: more readable
[oweals/busybox.git] / libbb / sha1.c
index 4b28266af12faaf952a880228d65d2866705c570..34813e24a2634fefcdc773e9d996e4e77102657b 100644 (file)
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
 /*
  *  Based on shasum from http://www.netsw.org/crypto/hash/
  *  Majorly hacked up to use Dr Brian Gladman's sha1 code
@@ -5,31 +6,9 @@
  *  Copyright (C) 2002 Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK.
  *  Copyright (C) 2003 Glenn L. McGrath
  *  Copyright (C) 2003 Erik Andersen
- *  
- *  LICENSE TERMS
  *
- *  The free distribution and use of this software in both source and binary
- *  form is allowed (with or without changes) provided that:
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  *
- *    1. distributions of this source code include the above copyright
- *       notice, this list of conditions and the following disclaimer;
- *
- *    2. distributions in binary form include the above copyright
- *       notice, this list of conditions and the following disclaimer
- *       in the documentation and/or other associated materials;
- *
- *    3. the copyright holder's name is not used to endorse products
- *       built using this software without specific written permission.
- *
- *  ALTERNATIVELY, provided that this notice is retained in full, this product
- *  may be distributed under the terms of the GNU General Public License (GPL),
- *  in which case the provisions of the GPL apply INSTEAD OF those given above.
- *
- *  DISCLAIMER
- *
- *  This software is provided 'as is' with no explicit or implied warranties
- *  in respect of its properties, including, but not limited to, correctness
- *  and/or fitness for purpose.
  *  ---------------------------------------------------------------------------
  *  Issue Date: 10/11/2002
  *
 
 #include "libbb.h"
 
-# define SHA1_BLOCK_SIZE  64
-# define SHA1_DIGEST_SIZE 20
-# define SHA1_HASH_SIZE   SHA1_DIGEST_SIZE
-# define SHA2_GOOD        0
-# define SHA2_BAD         1
+#define SHA1_BLOCK_SIZE  64
+#define SHA1_DIGEST_SIZE 20
+#define SHA1_HASH_SIZE   SHA1_DIGEST_SIZE
+#define SHA2_GOOD        0
+#define SHA2_BAD         1
 
-# define rotl32(x,n) (((x) << n) | ((x) >> (32 - n)))
+#define rotl32(x,n)      (((x) << n) | ((x) >> (32 - n)))
 
-# define SHA1_MASK   (SHA1_BLOCK_SIZE - 1)
+#define SHA1_MASK        (SHA1_BLOCK_SIZE - 1)
 
 /* reverse byte order in 32-bit words   */
-#define ch(x,y,z)       ((z) ^ ((x) & ((y) ^ (z))))
-#define parity(x,y,z)   ((x) ^ (y) ^ (z))
-#define maj(x,y,z)      (((x) & (y)) | ((z) & ((x) | (y))))
+#define ch(x,y,z)        ((z) ^ ((x) & ((y) ^ (z))))
+#define parity(x,y,z)    ((x) ^ (y) ^ (z))
+#define maj(x,y,z)       (((x) & (y)) | ((z) & ((x) | (y))))
 
 /* A normal version as set out in the FIPS. This version uses   */
 /* partial loop unrolling and is optimised for the Pentium 4    */
-# define rnd(f,k)    \
-    t = a; a = rotl32(a,5) + f(b,c,d) + e + k + w[i]; \
-    e = d; d = c; c = rotl32(b, 30); b = t
-
+#define rnd(f,k) \
+       do { \
+               t = a; a = rotl32(a,5) + f(b,c,d) + e + k + w[i]; \
+               e = d; d = c; c = rotl32(b, 30); b = t; \
+       } while(0)
 
 static void sha1_compile(sha1_ctx_t *ctx)
 {
@@ -153,7 +133,7 @@ void *sha1_end(void *resbuf, sha1_ctx_t *ctx)
 #else
        static uint32_t mask[4] = { 0x00000000, 0x000000ff, 0x0000ffff, 0x00ffffff };
        static uint32_t bits[4] = { 0x00000080, 0x00008000, 0x00800000, 0x80000000 };
-#endif /* __BYTE_ORDER */
+#endif
 
        uint8_t *hval = resbuf;
        uint32_t i, cnt = (uint32_t) (ctx->count[0] & SHA1_MASK);
@@ -181,7 +161,7 @@ void *sha1_end(void *resbuf, sha1_ctx_t *ctx)
                ctx->wbuf[cnt++] = 0;
 
        /* assemble the eight byte counter in the buffer in big-endian  */
-       /* format                                                      */
+       /* format                                                       */
 
        ctx->wbuf[14] = htonl((ctx->count[1] << 3) | (ctx->count[0] >> 29));
        ctx->wbuf[15] = htonl(ctx->count[0] << 3);
@@ -193,8 +173,6 @@ void *sha1_end(void *resbuf, sha1_ctx_t *ctx)
 
        for (i = 0; i < SHA1_DIGEST_SIZE; ++i)
                hval[i] = (unsigned char) (ctx->hash[i >> 2] >> 8 * (~i & 3));
-       
+
        return resbuf;
 }
-
-