Package: haskell-cryptonite Version: 0.20-1 Severity: normal Tags: patch User: ubuntu-de...@lists.ubuntu.com Usertags: origin-ubuntu zesty ubuntu-patch
Hi Clint, In Ubuntu, we've observed a build failure of haskell-cryptonite on armhf owing to the fact that our armhf builders run on an arm64 kernel which raises SIGBUS on unaligned access. While most of the hash implementations have compatible alignment assumptions, SHA3 uses 64-bit blocks, which triggers this problem. Please consider applying the attached patch to the Debian package. Strangely, it appears that this build failure is unrelated to the build failure seen on sparc64; so this only benefits users who happen to have the same set of kernel settings for armhf on Debian. (It's possible that skipping the unaligned traps is also a performance benefit, but that's probably not true on all architectures and I have not tried to measure the effect.) Thanks, -- Steve Langasek Give me a lever long enough and a Free OS Debian Developer to set it on, and I can move the world. Ubuntu Developer http://www.debian.org/ slanga...@ubuntu.com vor...@debian.org
diff -Nru haskell-cryptonite-0.20/debian/patches/crypto-buffer-alignment.patch haskell-cryptonite-0.20/debian/patches/crypto-buffer-alignment.patch --- haskell-cryptonite-0.20/debian/patches/crypto-buffer-alignment.patch 1969-12-31 16:00:00.000000000 -0800 +++ haskell-cryptonite-0.20/debian/patches/crypto-buffer-alignment.patch 2016-10-24 16:53:07.000000000 -0700 @@ -0,0 +1,51 @@ +Author: Steve Langasek <steve.langa...@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 -Nru haskell-cryptonite-0.20/debian/patches/series haskell-cryptonite-0.20/debian/patches/series --- haskell-cryptonite-0.20/debian/patches/series 1969-12-31 16:00:00.000000000 -0800 +++ haskell-cryptonite-0.20/debian/patches/series 2016-10-24 16:53:06.000000000 -0700 @@ -0,0 +1 @@ +crypto-buffer-alignment.patch