Bug#841983: haskell-cryptonite: Fix alignment of blocks in sha3_update()

2016-10-29 Thread Clint Adams
On Mon, Oct 24, 2016 at 05:14:47PM -0700, Steve Langasek wrote:
> I would think so, yes.

FYI, 
https://github.com/haskell-crypto/cryptonite/issues/108#issuecomment-256877591

___
Pkg-haskell-maintainers mailing list
Pkg-haskell-maintainers@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-haskell-maintainers


Processed: Re: Bug#841983: haskell-cryptonite: Fix alignment of blocks in sha3_update()

2016-10-24 Thread Debian Bug Tracking System
Processing commands for cont...@bugs.debian.org:

> forwarded 841983 https://github.com/haskell-crypto/cryptonite/issues/108
Bug #841983 [haskell-cryptonite] haskell-cryptonite: Fix alignment of blocks in 
sha3_update()
Set Bug forwarded-to-address to 
'https://github.com/haskell-crypto/cryptonite/issues/108'.
> quit
Stopping processing here.

Please contact me if you need assistance.
-- 
841983: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=841983
Debian Bug Tracking System
Contact ow...@bugs.debian.org with problems

___
Pkg-haskell-maintainers mailing list
Pkg-haskell-maintainers@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-haskell-maintainers


Bug#841983: haskell-cryptonite: Fix alignment of blocks in sha3_update()

2016-10-24 Thread Steve Langasek
On Tue, Oct 25, 2016 at 12:08:12AM +, Clint Adams wrote:
> On Mon, Oct 24, 2016 at 05:01:26PM -0700, Steve Langasek wrote:
> > 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.

> Should this go upstream as well?

I would think so, yes.

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 Developerhttp://www.debian.org/
slanga...@ubuntu.com vor...@debian.org


signature.asc
Description: PGP signature
___
Pkg-haskell-maintainers mailing list
Pkg-haskell-maintainers@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-haskell-maintainers

Bug#841983: haskell-cryptonite: Fix alignment of blocks in sha3_update()

2016-10-24 Thread Clint Adams
On Mon, Oct 24, 2016 at 05:01:26PM -0700, Steve Langasek wrote:
> 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.

Should this go upstream as well?

___
Pkg-haskell-maintainers mailing list
Pkg-haskell-maintainers@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-haskell-maintainers


Bug#841983: haskell-cryptonite: Fix alignment of blocks in sha3_update()

2016-10-24 Thread Steve Langasek
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 Developerhttp://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.0 -0800
+++ haskell-cryptonite-0.20/debian/patches/crypto-buffer-alignment.patch	2016-10-24 16:53:07.0 -0700
@@ -0,0 +1,51 @@
+Author: Steve Langasek 
+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 
++#include 
+ #include 
+ #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.0 -0800
+++ haskell-cryptonite-0.20/debian/patches/series	2016-10-24 16:53:06.0 -0700
@@ -0,0 +1 @@
+crypto-buffer-alignment.patch
___
Pkg-haskell-maintainers mailing list
Pkg-haskell-maintainers@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-haskell-maintainers