summaryrefslogtreecommitdiff
path: root/gcm.c
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2019-08-26 21:20:21 +0300
committerNiels Möller <nisse@lysator.liu.se>2019-09-03 18:41:05 +0200
commitfaed9ae6b49e2002c499f1f0551b65ed1a1d8bd4 (patch)
treeeda6f1374680180154a0d234b093a3db280c39ab /gcm.c
parent7aa7ae63487c064b9b1eedfaaf6bbaf4868992f1 (diff)
downloadnettle-faed9ae6b49e2002c499f1f0551b65ed1a1d8bd4.tar.gz
gcm: use uint64_t member of nettle_block16
Remove last usage of unsigned long member of nettle_block16. Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Diffstat (limited to 'gcm.c')
-rw-r--r--gcm.c47
1 files changed, 12 insertions, 35 deletions
diff --git a/gcm.c b/gcm.c
index a55f603f..627097b2 100644
--- a/gcm.c
+++ b/gcm.c
@@ -133,45 +133,22 @@ shift_table[0x10] = {
static void
gcm_gf_shift_4(union nettle_block16 *x)
{
- unsigned long *w = x->w;
- unsigned long reduce;
+ uint64_t *u64 = x->u64;
+ uint64_t reduce;
/* Shift uses big-endian representation. */
#if WORDS_BIGENDIAN
-# if SIZEOF_LONG == 4
- reduce = shift_table[w[3] & 0xf];
- w[3] = (w[3] >> 4) | ((w[2] & 0xf) << 28);
- w[2] = (w[2] >> 4) | ((w[1] & 0xf) << 28);
- w[1] = (w[1] >> 4) | ((w[0] & 0xf) << 28);
- w[0] = (w[0] >> 4) ^ (reduce << 16);
-# elif SIZEOF_LONG == 8
- reduce = shift_table[w[1] & 0xf];
- w[1] = (w[1] >> 4) | ((w[0] & 0xf) << 60);
- w[0] = (w[0] >> 4) ^ (reduce << 48);
-# else
-# error Unsupported word size. */
-#endif
+ reduce = shift_table[u64[1] & 0xf];
+ u64[1] = (u64[1] >> 4) | ((u64[0] & 0xf) << 60);
+ u64[0] = (u64[0] >> 4) ^ (reduce << 48);
#else /* ! WORDS_BIGENDIAN */
-# if SIZEOF_LONG == 4
-#define RSHIFT_WORD(x) \
- ((((x) & 0xf0f0f0f0UL) >> 4) \
- | (((x) & 0x000f0f0f) << 12))
- reduce = shift_table[(w[3] >> 24) & 0xf];
- w[3] = RSHIFT_WORD(w[3]) | ((w[2] >> 20) & 0xf0);
- w[2] = RSHIFT_WORD(w[2]) | ((w[1] >> 20) & 0xf0);
- w[1] = RSHIFT_WORD(w[1]) | ((w[0] >> 20) & 0xf0);
- w[0] = RSHIFT_WORD(w[0]) ^ reduce;
-# elif SIZEOF_LONG == 8
-#define RSHIFT_WORD(x) \
- ((((x) & 0xf0f0f0f0f0f0f0f0UL) >> 4) \
- | (((x) & 0x000f0f0f0f0f0f0fUL) << 12))
- reduce = shift_table[(w[1] >> 56) & 0xf];
- w[1] = RSHIFT_WORD(w[1]) | ((w[0] >> 52) & 0xf0);
- w[0] = RSHIFT_WORD(w[0]) ^ reduce;
-# else
-# error Unsupported word size. */
-# endif
-# undef RSHIFT_WORD
+#define RSHIFT_WORD_4(x) \
+ ((((x) & UINT64_C(0xf0f0f0f0f0f0f0f0)) >> 4) \
+ | (((x) & UINT64_C(0x000f0f0f0f0f0f0f)) << 12))
+ reduce = shift_table[(u64[1] >> 56) & 0xf];
+ u64[1] = RSHIFT_WORD_4(u64[1]) | ((u64[0] >> 52) & 0xf0);
+ u64[0] = RSHIFT_WORD_4(u64[0]) ^ reduce;
+# undef RSHIFT_WORD_4
#endif /* ! WORDS_BIGENDIAN */
}