From 4beda3a49d22af890ce1aacb0f7c114767c8a17b Mon Sep 17 00:00:00 2001 From: Edmund Grimley Evans Date: Thu, 27 Aug 2015 14:50:57 +0200 Subject: [PATCH 1/2] Avoid endianess problems in integerify() This fixes a build failure in KDF/Scrypt. Fixes #30. --- cbits/cryptonite_scrypt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cbits/cryptonite_scrypt.c b/cbits/cryptonite_scrypt.c index fc3fd04..eaf28ac 100644 --- a/cbits/cryptonite_scrypt.c +++ b/cbits/cryptonite_scrypt.c @@ -46,7 +46,7 @@ static void blockmix_salsa8(uint32_t *in, uint32_t *out, uint32_t *X, const uint static inline uint64_t integerify(uint32_t *B, const uint32_t r) { - return le64_to_cpu(*((uint64_t *) (B + (2*r-1) * 16))); + return B[(2*r-1) * 16] | (uint64_t)B[(2*r-1) * 16 + 1] << 32; } static inline uint32_t load32(const uint8_t *p) From 507a8f8cea28b77dbbc3834c868debed6c38d195 Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Thu, 27 Aug 2015 14:51:30 +0200 Subject: [PATCH 2/2] Use mkLE, not LE to make sure the conversion to little endian is actually happening. This fixes a test failure in ChaChaPoly1305. Fixes #31. --- Crypto/Cipher/ChaChaPoly1305.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Crypto/Cipher/ChaChaPoly1305.hs b/Crypto/Cipher/ChaChaPoly1305.hs index a2db972..cb16929 100644 --- a/Crypto/Cipher/ChaChaPoly1305.hs +++ b/Crypto/Cipher/ChaChaPoly1305.hs @@ -117,5 +117,5 @@ finalize :: State -> Poly1305.Auth finalize (State _ macState aadLength plainLength) = Poly1305.finalize $ Poly1305.updates macState [ pad16 plainLength - , either (error "finalize: internal error") id $ P.fill 16 (P.putStorable (LE aadLength) >> P.putStorable (LE plainLength)) + , either (error "finalize: internal error") id $ P.fill 16 (P.putStorable (toLE aadLength) >> P.putStorable (toLE plainLength)) ]