summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWan-Teh Chang <wtc@google.com>2015-10-05 14:55:55 -0700
committerWan-Teh Chang <wtc@google.com>2015-10-05 14:55:55 -0700
commitf7de71911ffa9b76dd2ebb7dbf24910d0b1c9a0e (patch)
tree76b1be2348f596e288c1b5a270915cf3425f56c5 /lib
parent097da839383b2ac6fced2d797682b18b5360f4f4 (diff)
downloadnss-hg-f7de71911ffa9b76dd2ebb7dbf24910d0b1c9a0e.tar.gz
Bug 1180096: Add comments about the unaligned memory access, and add the
feature-test macro HAVE_UNALIGNED_ACCESS. r=twsmith,ryan.sleevi.
Diffstat (limited to 'lib')
-rw-r--r--lib/freebl/des.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/freebl/des.c b/lib/freebl/des.c
index 63a56acba..bcfcaba60 100644
--- a/lib/freebl/des.c
+++ b/lib/freebl/des.c
@@ -13,6 +13,13 @@
#include <stddef.h> /* for ptrdiff_t */
/* #define USE_INDEXING 1 */
+/* Some processors automatically fix up unaligned memory access, so they can
+ * read or write a HALF (4 bytes) at a time whether the address is 4-byte
+ * aligned or not. */
+#if defined(NSS_X86_OR_X64)
+#define HAVE_UNALIGNED_ACCESS 1
+#endif
+
/*
* The tables below are the 8 sbox functions, with the 6-bit input permutation
* and the 32-bit output permutation pre-computed.
@@ -421,11 +428,13 @@ DES_MakeSchedule( HALF * ks, const BYTE * key, DESDirection direction)
int delta;
unsigned int ls;
-#if defined(NSS_X86_OR_X64)
+#if defined(HAVE_UNALIGNED_ACCESS)
left = HALFPTR(key)[0];
right = HALFPTR(key)[1];
+#if defined(IS_LITTLE_ENDIAN)
BYTESWAP(left, temp);
BYTESWAP(right, temp);
+#endif
#else
if (((ptrdiff_t)key & 0x03) == 0) {
left = HALFPTR(key)[0];
@@ -572,11 +581,13 @@ DES_Do1Block(HALF * ks, const BYTE * inbuf, BYTE * outbuf)
register HALF left, right;
register HALF temp;
-#if defined(NSS_X86_OR_X64)
+#if defined(HAVE_UNALIGNED_ACCESS)
left = HALFPTR(inbuf)[0];
right = HALFPTR(inbuf)[1];
+#if defined(IS_LITTLE_ENDIAN)
BYTESWAP(left, temp);
BYTESWAP(right, temp);
+#endif
#else
if (((ptrdiff_t)inbuf & 0x03) == 0) {
left = HALFPTR(inbuf)[0];
@@ -643,9 +654,11 @@ DES_Do1Block(HALF * ks, const BYTE * inbuf, BYTE * outbuf)
FP(left, right, temp);
-#if defined(NSS_X86_OR_X64)
+#if defined(HAVE_UNALIGNED_ACCESS)
+#if defined(IS_LITTLE_ENDIAN)
BYTESWAP(left, temp);
BYTESWAP(right, temp);
+#endif
HALFPTR(outbuf)[0] = left;
HALFPTR(outbuf)[1] = right;
#else