summaryrefslogtreecommitdiff
path: root/memxor-internal.h
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2014-10-23 15:26:38 +0200
committerNiels Möller <nisse@lysator.liu.se>2014-10-23 15:26:38 +0200
commit77f8c34cbf8f8ad826fce3f412b67f05f78c68d5 (patch)
treec8867c078500a08459652880d295bb32e2f4a669 /memxor-internal.h
parent57122465ccc89996f9f8f71e7607ee67a2860e1c (diff)
downloadnettle-77f8c34cbf8f8ad826fce3f412b67f05f78c68d5.tar.gz
Simplify unaligned memxor using READ_PARTIAL macro.
Diffstat (limited to 'memxor-internal.h')
-rw-r--r--memxor-internal.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/memxor-internal.h b/memxor-internal.h
index e868c181..dbb5e990 100644
--- a/memxor-internal.h
+++ b/memxor-internal.h
@@ -52,4 +52,22 @@ typedef unsigned long int word_t;
(((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 */