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 SHA2, based on the FIPS 180-2 ! * standard, available at http://www.itl.nist.gov/div897/pubs/fip180-2.htm * Not as fast as one would like -- further optimizations are encouraged * and appreciated. */ #include <sys/types.h> --- 25,36 ---- * * These notices must be retained in any copies of any part of this * documentation and/or software. * * NOTE: Cleaned-up and optimized, version of SHA2, based on the FIPS 180-2 ! * standard, available at ! * http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf * Not as fast as one would like -- further optimizations are encouraged * and appreciated. */ #include <sys/types.h>
*** 58,67 **** --- 57,71 ---- #pragma weak SHA384Final = SHA2Final #pragma weak SHA512Final = SHA2Final #endif /* _KERNEL */ + #ifdef _LITTLE_ENDIAN + #include <sys/byteorder.h> + #define HAVE_HTONL + #endif + static void Encode(uint8_t *, uint32_t *, size_t); static void Encode64(uint8_t *, uint64_t *, size_t); #if defined(__amd64) #define SHA512Transform(ctx, in) SHA512TransformBlocks((ctx), (in), 1)
*** 119,150 **** * 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 /* 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 - - - #if defined(_BIG_ENDIAN) - - #define LOAD_BIG_64(addr) (*(uint64_t *)(addr)) - - #else /* little endian -- will work on big endian, but slowly */ - #define LOAD_BIG_64(addr) \ (((uint64_t)(addr)[0] << 56) | ((uint64_t)(addr)[1] << 48) | \ ((uint64_t)(addr)[2] << 40) | ((uint64_t)(addr)[3] << 32) | \ ((uint64_t)(addr)[4] << 24) | ((uint64_t)(addr)[5] << 16) | \ ((uint64_t)(addr)[6] << 8) | (uint64_t)(addr)[7]) ! #endif #if !defined(__amd64) /* SHA256 Transform */ --- 123,149 ---- * 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)) + #define LOAD_BIG_64(addr) (*(uint64_t *)(addr)) ! #elif defined(HAVE_HTONL) ! #define LOAD_BIG_32(addr) htonl(*((uint32_t *)(addr))) ! #define LOAD_BIG_64(addr) htonll(*((uint64_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]) #define LOAD_BIG_64(addr) \ (((uint64_t)(addr)[0] << 56) | ((uint64_t)(addr)[1] << 48) | \ ((uint64_t)(addr)[2] << 40) | ((uint64_t)(addr)[3] << 32) | \ ((uint64_t)(addr)[4] << 24) | ((uint64_t)(addr)[5] << 16) | \ ((uint64_t)(addr)[6] << 8) | (uint64_t)(addr)[7]) ! #endif /* _BIG_ENDIAN */ #if !defined(__amd64) /* SHA256 Transform */
*** 713,724 **** ctx->state.s64[6] = 0x1f83d9abfb41bd6bULL; ctx->state.s64[7] = 0x5be0cd19137e2179ULL; break; #ifdef _KERNEL default: ! cmn_err(CE_PANIC, "sha2_init: " ! "failed to find a supported algorithm: 0x%x", (uint32_t)mech); #endif /* _KERNEL */ } --- 712,723 ---- ctx->state.s64[6] = 0x1f83d9abfb41bd6bULL; ctx->state.s64[7] = 0x5be0cd19137e2179ULL; break; #ifdef _KERNEL default: ! cmn_err(CE_PANIC, ! "sha2_init: failed to find a supported algorithm: 0x%x", (uint32_t)mech); #endif /* _KERNEL */ }