[DHG_packages] 02/02: cryptonite: fix alignment of memory blocks used by SHA3

Clint Adams clint at moszumanska.debian.org
Tue Oct 25 00:11:43 UTC 2016


This is an automated email from the git hooks/post-receive script.

clint pushed a commit to branch experimental
in repository DHG_packages.

commit 99f54e7b60b591861550589c1e053eb440023b99
Author: Clint Adams <clint at debian.org>
Date:   Mon Oct 24 20:09:29 2016 -0400

    cryptonite: fix alignment of memory blocks used by SHA3
---
 p/haskell-cryptonite/debian/changelog              |  7 +++
 .../debian/patches/crypto-buffer-alignment.patch   | 51 ++++++++++++++++++++++
 p/haskell-cryptonite/debian/patches/series         |  1 +
 3 files changed, 59 insertions(+)

diff --git a/p/haskell-cryptonite/debian/changelog b/p/haskell-cryptonite/debian/changelog
index 38041fa..8d4b64c 100644
--- a/p/haskell-cryptonite/debian/changelog
+++ b/p/haskell-cryptonite/debian/changelog
@@ -1,3 +1,10 @@
+haskell-cryptonite (0.20-3) experimental; urgency=medium
+
+  * Patch from Steve Langasek to fix alignment of blocks
+    in sha3_update().  closes: #841983.
+
+ -- Clint Adams <clint at debian.org>  Mon, 24 Oct 2016 20:08:40 -0400
+
 haskell-cryptonite (0.20-2) experimental; urgency=medium
 
   * Temporarily build-depend on ghc 8.
diff --git a/p/haskell-cryptonite/debian/patches/crypto-buffer-alignment.patch b/p/haskell-cryptonite/debian/patches/crypto-buffer-alignment.patch
new file mode 100644
index 0000000..a5398ed
--- /dev/null
+++ b/p/haskell-cryptonite/debian/patches/crypto-buffer-alignment.patch
@@ -0,0 +1,51 @@
+Author: Steve Langasek <steve.langasek at ubuntu.com>
+Description: fix alignment of memory blocks used by SHA3
+ SHA3 works in 64-bit chunks, but the incoming data pointer can be at any
+ address.  Copy our data to an aligned address, to avoid SIGBUS on certain
+ platforms.
+ .
+ This is not the only alignment issue in the code, but it is the one that
+ manifests as SIGBUS on the most architectures.
+
+Index: haskell-cryptonite-0.20/cbits/cryptonite_sha3.c
+===================================================================
+--- haskell-cryptonite-0.20.orig/cbits/cryptonite_sha3.c
++++ haskell-cryptonite-0.20/cbits/cryptonite_sha3.c
+@@ -23,6 +23,7 @@
+  */
+ 
+ #include <stdint.h>
++#include <stdlib.h>
+ #include <string.h>
+ #include "cryptonite_bitfn.h"
+ #include "cryptonite_sha3.h"
+@@ -107,6 +108,7 @@ void cryptonite_sha3_init(struct sha3_ct
+ void cryptonite_sha3_update(struct sha3_ctx *ctx, const uint8_t *data, uint32_t len)
+ {
+ 	uint32_t to_fill;
++	uint64_t *data_aligned = NULL;
+ 
+ 	to_fill = ctx->bufsz - ctx->bufindex;
+ 
+@@ -124,6 +126,13 @@ void cryptonite_sha3_update(struct sha3_
+ 		ctx->bufindex = 0;
+ 	}
+ 
++	/* fix up alignment if necessary */
++	if (len && (unsigned long) data & 7) {
++		data_aligned = malloc(len);
++		memcpy(data_aligned, data, len);
++		data = (uint8_t *) data_aligned;
++	}
++
+ 	/* process as much ctx->bufsz-block */
+ 	for (; len >= ctx->bufsz; len -= ctx->bufsz, data += ctx->bufsz)
+ 		sha3_do_chunk(ctx->state, (uint64_t *) data, ctx->bufsz / 8);
+@@ -133,6 +142,7 @@ void cryptonite_sha3_update(struct sha3_
+ 		memcpy(ctx->buf + ctx->bufindex, data, len);
+ 		ctx->bufindex += len;
+ 	}
++	free(data_aligned);
+ }
+ 
+ void cryptonite_sha3_finalize(struct sha3_ctx *ctx, uint32_t hashlen, uint8_t *out)
diff --git a/p/haskell-cryptonite/debian/patches/series b/p/haskell-cryptonite/debian/patches/series
new file mode 100644
index 0000000..e4f717e
--- /dev/null
+++ b/p/haskell-cryptonite/debian/patches/series
@@ -0,0 +1 @@
+crypto-buffer-alignment.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-haskell/DHG_packages.git



More information about the Pkg-haskell-commits mailing list