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

*** 21,32 **** /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ - #pragma ident "%Z%%M% %I% %E% SMI" - /* * Blowfish encryption/decryption and keyschedule code. */ #include <sys/types.h> --- 21,30 ----
*** 48,60 **** #else /* !_KERNEL */ #include <strings.h> #include <stdlib.h> #define BLOWFISH_ASSERT(x) - #endif /* _KERNEL */ /* EXPORT DELETE START */ /* * Blowfish initial P box and S boxes, derived from the hex digits of PI. * --- 46,62 ---- #else /* !_KERNEL */ #include <strings.h> #include <stdlib.h> #define BLOWFISH_ASSERT(x) #endif /* _KERNEL */ + #if defined(__i386) || defined(__amd64) + #include <sys/byteorder.h> + #define UNALIGNED_POINTERS_PERMITTED + #endif + /* EXPORT DELETE START */ /* * Blowfish initial P box and S boxes, derived from the hex digits of PI. *
*** 388,413 **** if (IS_P2ALIGNED(block, sizeof (uint32_t))) { /* LINTED: pointer alignment */ b32 = (uint32_t *)block; left = b32[0]; right = b32[1]; ! } else { #endif /* * Read input block and place in left/right in big-endian order. */ left = ((uint32_t)block[0] << 24) | ((uint32_t)block[1] << 16) | ((uint32_t)block[2] << 8) | (uint32_t)block[3]; right = ((uint32_t)block[4] << 24) | ((uint32_t)block[5] << 16) | ((uint32_t)block[6] << 8) | (uint32_t)block[7]; ! #ifdef _BIG_ENDIAN } - #endif ROUND(left, right, 0); ROUND(left, right, 1); ROUND(left, right, 2); ROUND(left, right, 3); --- 390,419 ---- if (IS_P2ALIGNED(block, sizeof (uint32_t))) { /* LINTED: pointer alignment */ b32 = (uint32_t *)block; left = b32[0]; right = b32[1]; ! } else #endif + { /* * Read input block and place in left/right in big-endian order. */ + #ifdef UNALIGNED_POINTERS_PERMITTED + left = htonl(*(uint32_t *)&block[0]); + right = htonl(*(uint32_t *)&block[4]); + #else left = ((uint32_t)block[0] << 24) | ((uint32_t)block[1] << 16) | ((uint32_t)block[2] << 8) | (uint32_t)block[3]; right = ((uint32_t)block[4] << 24) | ((uint32_t)block[5] << 16) | ((uint32_t)block[6] << 8) | (uint32_t)block[7]; ! #endif /* UNALIGNED_POINTERS_PERMITTED */ } ROUND(left, right, 0); ROUND(left, right, 1); ROUND(left, right, 2); ROUND(left, right, 3);
*** 434,457 **** if (IS_P2ALIGNED(out_block, sizeof (uint32_t))) { /* LINTED: pointer alignment */ b32 = (uint32_t *)out_block; b32[0] = left; b32[1] = right; ! } else { #endif /* Put the block back into the user's block with final swap */ out_block[0] = left >> 24; out_block[1] = left >> 16; out_block[2] = left >> 8; out_block[3] = left; out_block[4] = right >> 24; out_block[5] = right >> 16; out_block[6] = right >> 8; out_block[7] = right; ! #ifdef _BIG_ENDIAN } - #endif /* EXPORT DELETE END */ return (CRYPTO_SUCCESS); } /* --- 440,467 ---- if (IS_P2ALIGNED(out_block, sizeof (uint32_t))) { /* LINTED: pointer alignment */ b32 = (uint32_t *)out_block; b32[0] = left; b32[1] = right; ! } else #endif + { /* Put the block back into the user's block with final swap */ + #ifdef UNALIGNED_POINTERS_PERMITTED + *(uint32_t *)&out_block[0] = htonl(left); + *(uint32_t *)&out_block[4] = htonl(right); + #else out_block[0] = left >> 24; out_block[1] = left >> 16; out_block[2] = left >> 8; out_block[3] = left; out_block[4] = right >> 24; out_block[5] = right >> 16; out_block[6] = right >> 8; out_block[7] = right; ! #endif /* UNALIGNED_POINTERS_PERMITTED */ } /* EXPORT DELETE END */ return (CRYPTO_SUCCESS); } /*
*** 477,502 **** if (IS_P2ALIGNED(block, sizeof (uint32_t))) { /* LINTED: pointer alignment */ b32 = (uint32_t *)block; left = b32[0]; right = b32[1]; ! } else { #endif /* * Read input block and place in left/right in big-endian order. */ left = ((uint32_t)block[0] << 24) | ((uint32_t)block[1] << 16) | ((uint32_t)block[2] << 8) | (uint32_t)block[3]; right = ((uint32_t)block[4] << 24) | ((uint32_t)block[5] << 16) | ((uint32_t)block[6] << 8) | (uint32_t)block[7]; ! #ifdef _BIG_ENDIAN } - #endif ROUND(left, right, 17); ROUND(left, right, 16); ROUND(left, right, 15); ROUND(left, right, 14); --- 487,516 ---- if (IS_P2ALIGNED(block, sizeof (uint32_t))) { /* LINTED: pointer alignment */ b32 = (uint32_t *)block; left = b32[0]; right = b32[1]; ! } else #endif + { /* * Read input block and place in left/right in big-endian order. */ + #ifdef UNALIGNED_POINTERS_PERMITTED + left = htonl(*(uint32_t *)&block[0]); + right = htonl(*(uint32_t *)&block[4]); + #else left = ((uint32_t)block[0] << 24) | ((uint32_t)block[1] << 16) | ((uint32_t)block[2] << 8) | (uint32_t)block[3]; right = ((uint32_t)block[4] << 24) | ((uint32_t)block[5] << 16) | ((uint32_t)block[6] << 8) | (uint32_t)block[7]; ! #endif /* UNALIGNED_POINTERS_PERMITTED */ } ROUND(left, right, 17); ROUND(left, right, 16); ROUND(left, right, 15); ROUND(left, right, 14);
*** 523,546 **** if (IS_P2ALIGNED(out_block, sizeof (uint32_t))) { /* LINTED: pointer alignment */ b32 = (uint32_t *)out_block; b32[0] = left; b32[1] = right; ! } else { #endif /* Put the block back into the user's block with final swap */ out_block[0] = left >> 24; out_block[1] = left >> 16; out_block[2] = left >> 8; out_block[3] = left; out_block[4] = right >> 24; out_block[5] = right >> 16; out_block[6] = right >> 8; out_block[7] = right; ! #ifdef _BIG_ENDIAN } - #endif /* EXPORT DELETE END */ return (CRYPTO_SUCCESS); } static void --- 537,564 ---- if (IS_P2ALIGNED(out_block, sizeof (uint32_t))) { /* LINTED: pointer alignment */ b32 = (uint32_t *)out_block; b32[0] = left; b32[1] = right; ! } else #endif + { /* Put the block back into the user's block with final swap */ + #ifdef UNALIGNED_POINTERS_PERMITTED + *(uint32_t *)&out_block[0] = htonl(left); + *(uint32_t *)&out_block[4] = htonl(right); + #else out_block[0] = left >> 24; out_block[1] = left >> 16; out_block[2] = left >> 8; out_block[3] = left; out_block[4] = right >> 24; out_block[5] = right >> 16; out_block[6] = right >> 8; out_block[7] = right; ! #endif /* UNALIGNED_POINTERS_PERMITTED */ } /* EXPORT DELETE END */ return (CRYPTO_SUCCESS); } static void