[PATCH] scrypt: fix for big-endian systems

Jussi Kivilinna jussi.kivilinna at iki.fi
Fri Sep 6 22:57:01 CEST 2013


* cipher/scrypt.c (_salsa20_core): Fix endianess issues.
--

On big-endian systems 'tests/t-kdf' was failing scrypt tests. Patch fixes the
issue.

Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
 cipher/scrypt.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/cipher/scrypt.c b/cipher/scrypt.c
index 06196d6..9e29288 100644
--- a/cipher/scrypt.c
+++ b/cipher/scrypt.c
@@ -107,7 +107,9 @@ _salsa20_core(u32 *dst, const u32 *src, unsigned rounds)
 
   assert ( (rounds & 1) == 0);
 
-  memcpy (x, src, sizeof(x));
+  for (i = 0; i < SALSA20_INPUT_LENGTH; i++)
+    x[i] = LE_SWAP32(src[i]);
+
   for (i = 0; i < rounds;i += 2)
     {
       QROUND(x[0], x[4], x[8], x[12]);
@@ -123,8 +125,8 @@ _salsa20_core(u32 *dst, const u32 *src, unsigned rounds)
 
   for (i = 0; i < SALSA20_INPUT_LENGTH; i++)
     {
-      u32 t = x[i] + src[i];
-      dst[i] = LE_SWAP32 (t);
+      u32 t = x[i] + LE_SWAP32(src[i]);
+      dst[i] = LE_SWAP32(t);
     }
 }
 




More information about the Gcrypt-devel mailing list