Print this page
5007142 Add ntohll and htonll to sys/byteorder.h
6717509 Need to use bswap/bswapq for byte swap of 64-bit integer on x32/x64
PSARC 2008/474

*** 1,12 **** /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ - #pragma ident "%Z%%M% %I% %E% SMI" - /* * The basic framework for this code came from the reference * implementation for MD5. That implementation is Copyright (C) * 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved. * --- 1,10 ----
*** 27,37 **** * * These notices must be retained in any copies of any part of this * documentation and/or software. * * NOTE: Cleaned-up and optimized, version of SHA1, based on the FIPS 180-1 ! * standard, available at http://www.itl.nist.gov/div897/pubs/fip180-1.htm * Not as fast as one would like -- further optimizations are encouraged * and appreciated. */ #include <sys/types.h> --- 25,35 ---- * * These notices must be retained in any copies of any part of this * documentation and/or software. * * NOTE: Cleaned-up and optimized, version of SHA1, based on the FIPS 180-1 ! * standard, available at http://www.itl.nist.gov/fipspubs/fip180-1.htm * Not as fast as one would like -- further optimizations are encouraged * and appreciated. */ #include <sys/types.h>
*** 46,55 **** --- 44,58 ---- #include <stdlib.h> #include <errno.h> #include <sys/systeminfo.h> #endif /* !_KERNEL */ + #ifdef _LITTLE_ENDIAN + #include <sys/byteorder.h> + #define HAVE_HTONL + #endif + static void Encode(uint8_t *, const uint32_t *, size_t); #if defined(__sparc) #define SHA1_TRANSFORM(ctx, in) \
*** 104,125 **** #define ROTATE_LEFT(x, n) \ (((x) << (n)) | ((x) >> ((sizeof (x) * NBBY)-(n)))) #endif - #if defined(__GNUC__) && (defined(__i386) || defined(__amd64)) - #define HAVE_BSWAP - - extern __inline__ uint32_t bswap(uint32_t value) - { - __asm__("bswap %0" : "+r" (value)); - return (value); - } - - #endif - /* * SHA1Init() * * purpose: initializes the sha1 context and begins and sha1 digest operation * input: SHA1_CTX * : the context to initializes. --- 107,117 ----
*** 295,305 **** * Main processing loop - input 8-byte aligned */ for (; i + 63 < input_len; i += 64) { SHA1TransformVIS(X0, /* LINTED E_BAD_PTR_CAST_ALIGN */ ! (uint32_t *)&input[i], &ctx->state[0], VIS); } } #ifdef _KERNEL --- 287,297 ---- * Main processing loop - input 8-byte aligned */ for (; i + 63 < input_len; i += 64) { SHA1TransformVIS(X0, /* LINTED E_BAD_PTR_CAST_ALIGN */ ! (uint32_t *)&input[i], /* CSTYLED */ &ctx->state[0], VIS); } } #ifdef _KERNEL
*** 453,481 **** * in the interest of speed, we don't check to make sure, since * careful programming can guarantee this for us. */ #if defined(_BIG_ENDIAN) - #define LOAD_BIG_32(addr) (*(uint32_t *)(addr)) ! #else /* !defined(_BIG_ENDIAN) */ ! #if defined(HAVE_BSWAP) ! ! #define LOAD_BIG_32(addr) bswap(*((uint32_t *)(addr))) ! ! #else /* !defined(HAVE_BSWAP) */ ! /* little endian -- will work on big endian, but slowly */ #define LOAD_BIG_32(addr) \ (((addr)[0] << 24) | ((addr)[1] << 16) | ((addr)[2] << 8) | (addr)[3]) - #endif /* !defined(HAVE_BSWAP) */ - - #endif /* !defined(_BIG_ENDIAN) */ - /* * SHA1Transform() */ #if defined(W_ARRAY) #define W(n) w[n] --- 445,465 ---- * in the interest of speed, we don't check to make sure, since * careful programming can guarantee this for us. */ #if defined(_BIG_ENDIAN) #define LOAD_BIG_32(addr) (*(uint32_t *)(addr)) ! #elif defined(HAVE_HTONL) ! #define LOAD_BIG_32(addr) htonl(*((uint32_t *)(addr))) ! #else /* little endian -- will work on big endian, but slowly */ #define LOAD_BIG_32(addr) \ (((addr)[0] << 24) | ((addr)[1] << 16) | ((addr)[2] << 8) | (addr)[3]) + #endif /* _BIG_ENDIAN */ /* * SHA1Transform() */ #if defined(W_ARRAY) #define W(n) w[n]
*** 535,552 **** * going to be called from inside multithreaded kernelland, * this is a good safety check. -- `sha1_consts' will end up in * .rodata. * * unfortunately, loading from an array in this manner hurts ! * performance under intel. so, there is a macro, * SHA1_CONST(), used in SHA1Transform(), that either expands to * a reference to this array, or to the actual constant, * depending on what platform this code is compiled for. */ static const uint32_t sha1_consts[] = { ! SHA1_CONST_0, SHA1_CONST_1, SHA1_CONST_2, SHA1_CONST_3, }; /* * general optimization: * --- 519,536 ---- * going to be called from inside multithreaded kernelland, * this is a good safety check. -- `sha1_consts' will end up in * .rodata. * * unfortunately, loading from an array in this manner hurts ! * performance under Intel. So, there is a macro, * SHA1_CONST(), used in SHA1Transform(), that either expands to * a reference to this array, or to the actual constant, * depending on what platform this code is compiled for. */ static const uint32_t sha1_consts[] = { ! SHA1_CONST_0, SHA1_CONST_1, SHA1_CONST_2, SHA1_CONST_3 }; /* * general optimization: *
*** 627,639 **** /*LINTED*/ w_0 = LOAD_BIG_32(blk + 0); } #else /* !defined(__sparc) */ ! void SHA1Transform(SHA1_CTX *ctx, const uint8_t blk[64]) { sha1word a = ctx->state[0]; sha1word b = ctx->state[1]; sha1word c = ctx->state[2]; sha1word d = ctx->state[3]; sha1word e = ctx->state[4]; --- 611,624 ---- /*LINTED*/ w_0 = LOAD_BIG_32(blk + 0); } #else /* !defined(__sparc) */ ! void /* CSTYLED */ SHA1Transform(SHA1_CTX *ctx, const uint8_t blk[64]) { + /* CSTYLED */ sha1word a = ctx->state[0]; sha1word b = ctx->state[1]; sha1word c = ctx->state[2]; sha1word d = ctx->state[3]; sha1word e = ctx->state[4];