diff options
author | Ricardo Catalinas Jiménez <r@untroubled.be> | 2016-02-22 06:05:00 +0800 |
---|---|---|
committer | Ricardo Catalinas Jiménez <r@untroubled.be> | 2016-02-22 06:34:34 +0800 |
commit | e4b138a5931b309805162610870df50165e61a8f (patch) | |
tree | 6f97b16fcffc263dfab7094a07288a0a28a5af6c /crypto/sha3/xor_unaligned.go | |
parent | 0a1da69fac3766b48a116580295f98df93122503 (diff) | |
download | go-tangerine-e4b138a5931b309805162610870df50165e61a8f.tar go-tangerine-e4b138a5931b309805162610870df50165e61a8f.tar.gz go-tangerine-e4b138a5931b309805162610870df50165e61a8f.tar.bz2 go-tangerine-e4b138a5931b309805162610870df50165e61a8f.tar.lz go-tangerine-e4b138a5931b309805162610870df50165e61a8f.tar.xz go-tangerine-e4b138a5931b309805162610870df50165e61a8f.tar.zst go-tangerine-e4b138a5931b309805162610870df50165e61a8f.zip |
crypto/sha3: Copy latest code from "golang.org/x/crypto/sha3"
Revision: 1f22c0103821b9390939b6776727195525381532
Diffstat (limited to 'crypto/sha3/xor_unaligned.go')
-rw-r--r-- | crypto/sha3/xor_unaligned.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/crypto/sha3/xor_unaligned.go b/crypto/sha3/xor_unaligned.go new file mode 100644 index 000000000..c7851a1d8 --- /dev/null +++ b/crypto/sha3/xor_unaligned.go @@ -0,0 +1,58 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build amd64 386 +// +build !appengine + +package sha3 + +import "unsafe" + +func xorInUnaligned(d *state, buf []byte) { + bw := (*[maxRate / 8]uint64)(unsafe.Pointer(&buf[0])) + n := len(buf) + if n >= 72 { + d.a[0] ^= bw[0] + d.a[1] ^= bw[1] + d.a[2] ^= bw[2] + d.a[3] ^= bw[3] + d.a[4] ^= bw[4] + d.a[5] ^= bw[5] + d.a[6] ^= bw[6] + d.a[7] ^= bw[7] + d.a[8] ^= bw[8] + } + if n >= 104 { + d.a[9] ^= bw[9] + d.a[10] ^= bw[10] + d.a[11] ^= bw[11] + d.a[12] ^= bw[12] + } + if n >= 136 { + d.a[13] ^= bw[13] + d.a[14] ^= bw[14] + d.a[15] ^= bw[15] + d.a[16] ^= bw[16] + } + if n >= 144 { + d.a[17] ^= bw[17] + } + if n >= 168 { + d.a[18] ^= bw[18] + d.a[19] ^= bw[19] + d.a[20] ^= bw[20] + } +} + +func copyOutUnaligned(d *state, buf []byte) { + ab := (*[maxRate]uint8)(unsafe.Pointer(&d.a[0])) + copy(buf, ab[:]) +} + +var ( + xorIn = xorInUnaligned + copyOut = copyOutUnaligned +) + +const xorImplementationUnaligned = "unaligned" |