2014-10-23 Niels Möller <nisse@lysator.liu.se>
+ * memxor-internal.h (READ_PARTIAL): New macro.
* memxor.c (memxor_different_alignment): Avoid out-of-bounds
- reads, corresponding to valgrind's --partial-loads-ok.
+ reads, corresponding to valgrind's --partial-loads-ok. Use
+ READ_PARTIAL.
* configure.ac (asm_replace_list): Deleted memxor.asm, now
incompatible with the memxor/memxor3 split.
(((w0) << (sh_1)) | ((w1) >> (sh_2)))
#endif
+#ifndef WORDS_BIGENDIAN
+#define READ_PARTIAL(r,p,n) do { \
+ word_t _rp_x; \
+ unsigned _rp_i; \
+ for (_rp_i = (n), _rp_x = (p)[--_rp_i]; _rp_i > 0;) \
+ _rp_x = (_rp_x << CHAR_BIT) | (p)[--_rp_i]; \
+ (r) = _rp_x; \
+ } while (0)
+#else
+#define READ_PARTIAL(r,p,n) do { \
+ word_t _rp_x; \
+ unsigned _rp_i; \
+ for (_rp_x = (p)[0], _rp_i = 1; _rp_i < (n); _rp_i++) \
+ _rp_x = (_rp_x << CHAR_BIT) | (p)[_rp_i]; \
+ (r) = _rp_x; \
+ } while (0)
+#endif
+
#endif /* NETTLE_MEMXOR_INTERNAL_H_INCLUDED */
const word_t *src_word;
unsigned offset = ALIGN_OFFSET (src);
word_t s0, s1;
- const unsigned char *part;
- unsigned i;
assert (n > 0);
shl = CHAR_BIT * offset;
src_word = (const word_t *) ((uintptr_t) src & -sizeof(word_t));
/* Read top offset bytes, in native byte order. */
- part = src + n*sizeof(word_t) - offset;
-#if WORDS_BIGENDIAN
- for (s0 = part[0], i = 1; i < offset; i++)
- s0 = (s0 << CHAR_BIT) | part[i];
+ READ_PARTIAL (s0, (unsigned char *) &src_word[n], offset);
+#ifdef WORDS_BIGENDIAN
s0 <<= shr; /* FIXME: Eliminate this shift? */
-#else /* !WORDS_BIGENDIAN */
- for (i = offset, s0 = part[--i]; i > 0 ; )
- s0 = (s0 << CHAR_BIT) | part[--i];
-#endif /* !WORDS_BIGENDIAN */
+#endif
/* Do n-1 regular iterations */
if (n & 1)
}
assert (n == 1);
/* Read low wordsize - offset bytes */
-#if WORDS_BIGENDIAN
- for (s0 = src[0], i = 1; i < sizeof(word_t) - offset; i++)
- s0 = (s0 << CHAR_BIT) | src[i];
-#else /* !WORDS_BIGENDIAN */
- for (i = sizeof(word_t) - offset, s0 = src[--i]; i > 0 ; )
- s0 = (s0 << CHAR_BIT) | src[--i];
+ READ_PARTIAL (s0, src, sizeof(word_t) - offset);
+#ifndef WORDS_BIGENDIAN
s0 <<= shl; /* FIXME: eliminate shift? */
#endif /* !WORDS_BIGENDIAN */
+
dst[0] ^= MERGE(s0, shl, s1, shr);
}