mirror of
https://github.com/fumiama/blake2b-simd.git
synced 2026-06-05 02:00:26 +08:00
internal: use arrays instead of make for simple values. (#22)
Fixes #16
This commit is contained in:
@@ -27,11 +27,11 @@ import (
|
||||
|
||||
func benchmarkHash(b *testing.B, hash func() hash.Hash) {
|
||||
b.SetBytes(1024 * 1024)
|
||||
data := make([]byte, 1024)
|
||||
var data [1024]byte
|
||||
for i := 0; i < b.N; i++ {
|
||||
h := hash()
|
||||
for j := 0; j < 1024; j++ {
|
||||
h.Write(data)
|
||||
h.Write(data[:])
|
||||
}
|
||||
h.Sum(nil)
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func BenchmarkComparisonBlake2B(b *testing.B) {
|
||||
|
||||
// Benchmark blake2b implementation.
|
||||
var bench = New512()
|
||||
var buf = make([]byte, 128*1024)
|
||||
var buf [128 * 1024]byte
|
||||
|
||||
func benchmarkSize(b *testing.B, size int) {
|
||||
b.SetBytes(int64(size))
|
||||
|
||||
@@ -23,11 +23,12 @@ package blake2b
|
||||
func compressAVX2Loop(p []uint8, in, iv, t, f, shffle, out []uint64)
|
||||
|
||||
func compressAVX2(d *digest, p []uint8) {
|
||||
var (
|
||||
in [8]uint64
|
||||
out [8]uint64
|
||||
shffle [8]uint64
|
||||
)
|
||||
|
||||
in := make([]uint64, 8, 8)
|
||||
out := make([]uint64, 8, 8)
|
||||
|
||||
shffle := make([]uint64, 8, 8)
|
||||
// vector for PSHUFB instruction
|
||||
shffle[0] = 0x0201000706050403
|
||||
shffle[1] = 0x0a09080f0e0d0c0b
|
||||
@@ -40,7 +41,7 @@ func compressAVX2(d *digest, p []uint8) {
|
||||
|
||||
in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7] = d.h[0], d.h[1], d.h[2], d.h[3], d.h[4], d.h[5], d.h[6], d.h[7]
|
||||
|
||||
compressAVX2Loop(p, in, iv[:], d.t[:], d.f[:], shffle, out)
|
||||
compressAVX2Loop(p, in[:], iv[:], d.t[:], d.f[:], shffle[:], out[:])
|
||||
|
||||
d.h[0], d.h[1], d.h[2], d.h[3], d.h[4], d.h[5], d.h[6], d.h[7] = out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]
|
||||
}
|
||||
|
||||
@@ -23,18 +23,19 @@ package blake2b
|
||||
func blockAVXLoop(p []uint8, in, iv, t, f, shffle, out []uint64)
|
||||
|
||||
func compressAVX(d *digest, p []uint8) {
|
||||
var (
|
||||
in [8]uint64
|
||||
out [8]uint64
|
||||
shffle [2]uint64
|
||||
)
|
||||
|
||||
in := make([]uint64, 8, 8)
|
||||
out := make([]uint64, 8, 8)
|
||||
|
||||
shffle := make([]uint64, 2, 2)
|
||||
// vector for PSHUFB instruction
|
||||
shffle[0] = 0x0201000706050403
|
||||
shffle[1] = 0x0a09080f0e0d0c0b
|
||||
|
||||
in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7] = d.h[0], d.h[1], d.h[2], d.h[3], d.h[4], d.h[5], d.h[6], d.h[7]
|
||||
|
||||
blockAVXLoop(p, in, iv[:], d.t[:], d.f[:], shffle, out)
|
||||
blockAVXLoop(p, in[:], iv[:], d.t[:], d.f[:], shffle[:], out[:])
|
||||
|
||||
d.h[0], d.h[1], d.h[2], d.h[3], d.h[4], d.h[5], d.h[6], d.h[7] = out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]
|
||||
}
|
||||
|
||||
@@ -23,18 +23,19 @@ package blake2b
|
||||
func blockSSELoop(p []uint8, in, iv, t, f, shffle, out []uint64)
|
||||
|
||||
func compressSSE(d *digest, p []uint8) {
|
||||
var (
|
||||
in [8]uint64
|
||||
out [8]uint64
|
||||
shffle [2]uint64
|
||||
)
|
||||
|
||||
in := make([]uint64, 8, 8)
|
||||
out := make([]uint64, 8, 8)
|
||||
|
||||
shffle := make([]uint64, 2, 2)
|
||||
// vector for PSHUFB instruction
|
||||
shffle[0] = 0x0201000706050403
|
||||
shffle[1] = 0x0a09080f0e0d0c0b
|
||||
|
||||
in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7] = d.h[0], d.h[1], d.h[2], d.h[3], d.h[4], d.h[5], d.h[6], d.h[7]
|
||||
|
||||
blockSSELoop(p, in, iv[:], d.t[:], d.f[:], shffle, out)
|
||||
blockSSELoop(p, in[:], iv[:], d.t[:], d.f[:], shffle[:], out[:])
|
||||
|
||||
d.h[0], d.h[1], d.h[2], d.h[3], d.h[4], d.h[5], d.h[6], d.h[7] = out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]
|
||||
}
|
||||
|
||||
@@ -26,12 +26,13 @@ func compressGeneric(d *digest, p []uint8) {
|
||||
v13 := iv[5] ^ d.t[1]
|
||||
v14 := iv[6] ^ d.f[0]
|
||||
v15 := iv[7] ^ d.f[1]
|
||||
var m [16]uint64
|
||||
|
||||
j := 0
|
||||
for i := 0; i < 16; i++ {
|
||||
m[i] = uint64(p[j]) | uint64(p[j+1])<<8 | uint64(p[j+2])<<16 | uint64(p[j+3])<<24 |
|
||||
uint64(p[j+4])<<32 | uint64(p[j+5])<<40 | uint64(p[j+6])<<48 | uint64(p[j+7])<<56
|
||||
var m [16]uint64
|
||||
for i := range m {
|
||||
m[i] = uint64(p[j]) | uint64(p[j+1])<<8 | uint64(p[j+2])<<16 |
|
||||
uint64(p[j+3])<<24 | uint64(p[j+4])<<32 | uint64(p[j+5])<<40 |
|
||||
uint64(p[j+6])<<48 | uint64(p[j+7])<<56
|
||||
j += 8
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user