mirror of
https://github.com/henrydcase/nobs.git
synced 2024-11-27 01:21:21 +00:00
Henry Case
49bf0db8fd
* xorIn and copyOut function pointers cause input and output data to be moved to heap. This degrades performance of calling code. * This change removes usage of those function pointers. We will always use unaligned implementation as it's faster (but may crash on some systems) * Benchmark compares generic vs unaligned xorIn and copyOut benchmark old ns/op new ns/op delta BenchmarkPermutationFunction-4 463 815 +76.03% BenchmarkShake128_MTU-4 4443 8180 +84.11% BenchmarkShake256_MTU-4 4739 9060 +91.18% BenchmarkShake256_16x-4 71886 132629 +84.50% BenchmarkShake256_1MiB-4 3695138 6649012 +79.94% BenchmarkCShake128_448_16x-4 21210 24611 +16.03% BenchmarkCShake128_1MiB-4 3009342 3396496 +12.87% BenchmarkCShake256_448_16x-4 26034 27785 +6.73% BenchmarkCShake256_1MiB-4 3654713 3829404 +4.78%
31 lines
725 B
Go
31 lines
725 B
Go
// 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.
|
|
|
|
package shake
|
|
|
|
import "encoding/binary"
|
|
|
|
// xorInGeneric xors the bytes in buf into the state; it
|
|
// makes no non-portable assumptions about memory layout
|
|
// or alignment.
|
|
func xorInGeneric(d *state, buf []byte) {
|
|
n := len(buf) / 8
|
|
|
|
for i := 0; i < n; i++ {
|
|
a := binary.LittleEndian.Uint64(buf)
|
|
d.a[i] ^= a
|
|
buf = buf[8:]
|
|
}
|
|
}
|
|
|
|
// copyOutGeneric copies ulint64s to a byte buffer.
|
|
func copyOutGeneric(d *state, b []byte) {
|
|
for i := 0; len(b) >= 8; i++ {
|
|
binary.LittleEndian.PutUint64(b, d.a[i])
|
|
b = b[8:]
|
|
}
|
|
}
|
|
|
|
const xorImplementationGeneric = "generic"
|