summaryrefslogtreecommitdiff
path: root/cipher/scrypt.c
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@iki.fi>2013-09-21 13:54:38 +0300
committerJussi Kivilinna <jussi.kivilinna@iki.fi>2013-09-21 14:08:24 +0300
commit9337e03824a5bdd3bbbcb8382cabefe6d6c32e1e (patch)
treecf6f796989327c58327d3178f312d2876f268483 /cipher/scrypt.c
parent7409de7bc28ff8847c9d71d8c3e35e1968d59d60 (diff)
downloadlibgcrypt-9337e03824a5bdd3bbbcb8382cabefe6d6c32e1e.tar.gz
Optimize and cleanup 32-bit and 64-bit endianess transforms
* cipher/bithelp.h (bswap32, bswap64, le_bswap32, be_bswap32) (le_bswap64, be_bswap64): New. * cipher/bufhelp.h (buf_get_be32, buf_get_le32, buf_put_le32) (buf_put_be32, buf_get_be64, buf_get_le64, buf_put_be64) (buf_put_le64): New. * cipher/blowfish.c (do_encrypt_block, do_decrypt_block): Use new endian conversion helpers. (do_bf_setkey): Turn endian specific code to generic. * cipher/camellia.c (GETU32, PUTU32): Use new endian conversion helpers. * cipher/cast5.c (rol): Remove, use rol from bithelp. (F1, F2, F3): Fix to use rol from bithelp. (do_encrypt_block, do_decrypt_block, do_cast_setkey): Use new endian conversion helpers. * cipher/des.c (READ_64BIT_DATA, WRITE_64BIT_DATA): Ditto. * cipher/md4.c (transform, md4_final): Ditto. * cipher/md5.c (transform, md5_final): Ditto. * cipher/rmd160.c (transform, rmd160_final): Ditto. * cipher/salsa20.c (LE_SWAP32, LE_READ_UINT32): Ditto. * cipher/scrypt.c (READ_UINT64, LE_READ_UINT64, LE_SWAP32): Ditto. * cipher/seed.c (GETU32, PUTU32): Ditto. * cipher/serpent.c (byte_swap_32): Remove. (serpent_key_prepare, serpent_encrypt_internal) (serpent_decrypt_internal): Use new endian conversion helpers. * cipher/sha1.c (transform, sha1_final): Ditto. * cipher/sha256.c (transform, sha256_final): Ditto. * cipher/sha512.c (__transform, sha512_final): Ditto. * cipher/stribog.c (transform, stribog_final): Ditto. * cipher/tiger.c (transform, tiger_final): Ditto. * cipher/twofish.c (INPACK, OUTUNPACK): Ditto. * cipher/whirlpool.c (buffer_to_block, block_to_buffer): Ditto. * configure.ac (gcry_cv_have_builtin_bswap32): Check for compiler provided __builtin_bswap32. (gcry_cv_have_builtin_bswap64): Check for compiler provided __builtin_bswap64. -- Patch add helper functions that provide conversions to/from integers and buffers of different endianess. Benefits are code cleanup and optimization for architectures that have byte-swaping instructions and/or can do fast unaligned memory accesses. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher/scrypt.c')
-rw-r--r--cipher/scrypt.c34
1 files changed, 5 insertions, 29 deletions
diff --git a/cipher/scrypt.c b/cipher/scrypt.c
index 9e29288a..6f6a7f11 100644
--- a/cipher/scrypt.c
+++ b/cipher/scrypt.c
@@ -58,38 +58,14 @@
/* Reads a 64-bit integer, in network, big-endian, byte order */
-#define READ_UINT64(p) \
-( (((u64) (p)[0]) << 56) \
- | (((u64) (p)[1]) << 48) \
- | (((u64) (p)[2]) << 40) \
- | (((u64) (p)[3]) << 32) \
- | (((u64) (p)[4]) << 24) \
- | (((u64) (p)[5]) << 16) \
- | (((u64) (p)[6]) << 8) \
- | ((u64) (p)[7]))
-
+#define READ_UINT64(p) buf_get_be64(p)
/* And the other, little-endian, byteorder */
-#define LE_READ_UINT64(p) \
-( (((u64) (p)[7]) << 56) \
- | (((u64) (p)[6]) << 48) \
- | (((u64) (p)[5]) << 40) \
- | (((u64) (p)[4]) << 32) \
- | (((u64) (p)[3]) << 24) \
- | (((u64) (p)[2]) << 16) \
- | (((u64) (p)[1]) << 8) \
- | ((u64) (p)[0]))
-
-
-
-#ifdef WORDS_BIGENDIAN
-#define LE_SWAP32(v) \
- ((ROTL32(8, v) & 0x00FF00FFUL) | \
- (ROTL32(24, v) & 0xFF00FF00UL))
-#else
-#define LE_SWAP32(v) (v)
-#endif
+#define LE_READ_UINT64(p) buf_get_le64(p)
+
+#define LE_SWAP32(v) le_bswap32(v)
+
#define QROUND(x0, x1, x2, x3) do { \
x1 ^= ROTL32(7, x0 + x3); \