diff --git a/hash/shake/hashes_generic.go b/hash/shake/hashes_generic.go deleted file mode 100644 index c6da68a..0000000 --- a/hash/shake/hashes_generic.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2017 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 gccgo appengine !s390x - -package shake - -import ( - "hash" -) - -// new224Asm returns an assembly implementation of SHA3-224 if available, -// otherwise it returns nil. -func new224Asm() hash.Hash { return nil } - -// new256Asm returns an assembly implementation of SHA3-256 if available, -// otherwise it returns nil. -func new256Asm() hash.Hash { return nil } - -// new384Asm returns an assembly implementation of SHA3-384 if available, -// otherwise it returns nil. -func new384Asm() hash.Hash { return nil } - -// new512Asm returns an assembly implementation of SHA3-512 if available, -// otherwise it returns nil. -func new512Asm() hash.Hash { return nil } diff --git a/hash/shake/sha3.go b/hash/shake/sha3.go index 2c01bb8..8c8a945 100644 --- a/hash/shake/sha3.go +++ b/hash/shake/sha3.go @@ -83,7 +83,7 @@ func (d *state) permute() { case spongeAbsorbing: // If we're absorbing, we need to xor the input into the state // before applying the permutation. - xorIn(d, d.buf) + xorInUnaligned(d, d.buf) d.buf = d.storage[:0] keccakF1600(&d.a) case spongeSqueezing: @@ -91,7 +91,7 @@ func (d *state) permute() { // copying more output. keccakF1600(&d.a) d.buf = d.storage[:d.rate] - copyOut(d, d.buf) + copyOutUnaligned(d, d.buf) } } @@ -119,7 +119,7 @@ func (d *state) padAndPermute(dsbyte byte) { d.permute() d.state = spongeSqueezing d.buf = d.storage[:d.rate] - copyOut(d, d.buf) + copyOutUnaligned(d, d.buf) } // Write absorbs more data into the hash's state. It produces an error @@ -136,7 +136,7 @@ func (d *state) Write(p []byte) (written int, err error) { for len(p) > 0 { if len(d.buf) == 0 && len(p) >= d.rate { // The fast path; absorb a full "rate" bytes of input and apply the permutation. - xorIn(d, p[:d.rate]) + xorInUnaligned(d, p[:d.rate]) p = p[d.rate:] keccakF1600(&d.a) } else { diff --git a/hash/shake/sha3_test.go b/hash/shake/sha3_test.go index 9176a20..a649e19 100644 --- a/hash/shake/sha3_test.go +++ b/hash/shake/sha3_test.go @@ -22,6 +22,11 @@ import ( "testing" ) +var ( + xorIn = xorInUnaligned + copyOut = copyOutUnaligned +) + const ( testString = "brekeccakkeccak koax koax" katFilename = "testdata/keccakKats.json.deflate" @@ -68,7 +73,7 @@ func testUnalignedAndGeneric(t *testing.T, testf func(impl string)) { xorIn, copyOut = xorInGeneric, copyOutGeneric testf("generic") if xorImplementationUnaligned != "generic" { - xorIn, copyOut = xorInUnaligned, copyOutUnaligned + xorIn, copyOut = xorInGeneric, copyOutGeneric testf("unaligned") } xorIn, copyOut = xorInOrig, copyOutOrig @@ -336,7 +341,7 @@ func benchmarkShake(b *testing.B, h *CShake, size, num int) { b.StopTimer() h.Reset() data := sequentialBytes(size) - d := make([]byte, 32) + var d [32]byte b.SetBytes(int64(size * num)) b.StartTimer() @@ -346,7 +351,7 @@ func benchmarkShake(b *testing.B, h *CShake, size, num int) { for j := 0; j < num; j++ { h.Write(data) } - h.Read(d) + h.Read(d[:]) } } @@ -354,6 +359,18 @@ func BenchmarkShake128_MTU(b *testing.B) { benchmarkShake(b, NewShake128(), 135 func BenchmarkShake256_MTU(b *testing.B) { benchmarkShake(b, NewShake256(), 1350, 1) } func BenchmarkShake256_16x(b *testing.B) { benchmarkShake(b, NewShake256(), 16, 1024) } func BenchmarkShake256_1MiB(b *testing.B) { benchmarkShake(b, NewShake256(), 1024, 1024) } +func BenchmarkCShake128_448_16x(b *testing.B) { + benchmarkShake(b, NewCShake128([]byte("ABC"), []byte("DEF")), 448, 16) +} +func BenchmarkCShake128_1MiB(b *testing.B) { + benchmarkShake(b, NewCShake128([]byte("ABC"), []byte("DEF")), 1024, 1024) +} +func BenchmarkCShake256_448_16x(b *testing.B) { + benchmarkShake(b, NewCShake256([]byte("ABC"), []byte("DEF")), 448, 16) +} +func BenchmarkCShake256_1MiB(b *testing.B) { + benchmarkShake(b, NewCShake256([]byte("ABC"), []byte("DEF")), 1024, 1024) +} func Example_sum() { buf := []byte("some data to hash") diff --git a/hash/shake/xor.go b/hash/shake/xor.go deleted file mode 100644 index b6b4370..0000000 --- a/hash/shake/xor.go +++ /dev/null @@ -1,16 +0,0 @@ -// 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,!ppc64le appengine - -package shake - -var ( - xorIn = xorInGeneric - copyOut = copyOutGeneric - xorInUnaligned = xorInGeneric - copyOutUnaligned = copyOutGeneric -) - -const xorImplementationUnaligned = "generic" diff --git a/hash/shake/xor_generic.go b/hash/shake/xor_generic.go index d198554..9292820 100644 --- a/hash/shake/xor_generic.go +++ b/hash/shake/xor_generic.go @@ -26,3 +26,5 @@ func copyOutGeneric(d *state, b []byte) { b = b[8:] } } + +const xorImplementationGeneric = "generic" diff --git a/hash/shake/xor_unaligned.go b/hash/shake/xor_unaligned.go index d5dd014..972966b 100644 --- a/hash/shake/xor_unaligned.go +++ b/hash/shake/xor_unaligned.go @@ -50,9 +50,4 @@ func copyOutUnaligned(d *state, buf []byte) { copy(buf, ab[:]) } -var ( - xorIn = xorInUnaligned - copyOut = copyOutUnaligned -) - const xorImplementationUnaligned = "unaligned"