From 8e21cab95092b57b546e7f40335719ce3c1d8802 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sat, 14 Mar 2020 00:20:23 +0100 Subject: [PATCH] Simplify integerify() Make offsets 64 bit in the SSE scrypt impl --- .../nosse/pwhash_scryptsalsa208sha256_nosse.c | 4 ++-- .../sse/pwhash_scryptsalsa208sha256_sse.c | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c index 068516bd..40c76fc8 100644 --- a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c +++ b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c @@ -160,9 +160,9 @@ blockmix_salsa8(const uint32_t *Bin, uint32_t *Bout, uint32_t *X, size_t r) static inline uint64_t integerify(const void *B, size_t r) { - const uint32_t *X = (const uint32_t *) ((uintptr_t)(B) + (2 * r - 1) * 64); + const uint32_t *X = ((const uint32_t *) B) + (2 * r - 1) * 16; - return (((uint64_t)(X[1]) << 32) + X[0]); + return ((uint64_t) (X[1]) << 32) + X[0]; } /** diff --git a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c index 8c6c54ab..4540e23d 100644 --- a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +++ b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c @@ -213,10 +213,12 @@ blockmix_salsa8_xor(const __m128i *Bin1, const __m128i *Bin2, __m128i *Bout, * Return the result of parsing B_{2r-1} as a little-endian integer. * Note that B's layout is permuted compared to the generic implementation. */ -static inline uint32_t +static inline uint64_t integerify(const void *B, size_t r) { - return *(const uint32_t *) ((uintptr_t)(B) + (2 * r - 1) * 64); + const uint64_t *X = ((const uint64_t *) B) + (2 * r - 1) * 8; + + return *X; } /** @@ -228,12 +230,12 @@ integerify(const void *B, size_t r) * multiple of 64 bytes. */ static void -smix(uint8_t *B, size_t r, uint32_t N, void *V, void *XY) +smix(uint8_t *B, size_t r, uint64_t N, void *V, void *XY) { size_t s = 128 * r; - __m128i * X = (__m128i *) V, *Y; + __m128i *X = (__m128i *) V, *Y; uint32_t *X32 = (uint32_t *) V; - uint32_t i, j; + uint64_t i, j; size_t k; /* 1: X <-- B */ @@ -388,7 +390,7 @@ escrypt_kdf_sse(escrypt_local_t *local, const uint8_t *passwd, size_t passwdlen, /* 2: for i = 0 to p - 1 do */ for (i = 0; i < p; i++) { /* 3: B_i <-- MF(B_i, N) */ - smix(&B[(size_t) 128 * i * r], r, (uint32_t) N, V, XY); + smix(&B[(size_t) 128 * i * r], r, N, V, XY); } /* 5: DK <-- PBKDF2(P, B, 1, dkLen) */