mirror of
https://github.com/fumiama/blake2b-simd.git
synced 2026-06-12 22:40:54 +08:00
Removed functionality/code for comparing (during dev) to reference code
This commit is contained in:
27
blake2b.go
27
blake2b.go
@@ -34,7 +34,6 @@ type digest struct {
|
|||||||
isKeyed bool // indicates whether hash was keyed
|
isKeyed bool // indicates whether hash was keyed
|
||||||
size uint8 // digest size in bytes
|
size uint8 // digest size in bytes
|
||||||
isLastNode bool // indicates processing of the last node in tree hashing
|
isLastNode bool // indicates processing of the last node in tree hashing
|
||||||
sseOptimized bool // temp bool to indicate use of SSE (during dev only)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialization values.
|
// Initialization values.
|
||||||
@@ -163,12 +162,9 @@ func (d *digest) initialize(c *Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New512 returns a new hash.Hash computing the BLAKE2b 64-byte checksum.
|
// New512 returns a new hash.Hash computing the BLAKE2b 64-byte checksum.
|
||||||
func New512(enableSSE bool) hash.Hash {
|
func New512() hash.Hash {
|
||||||
d := new(digest)
|
d := new(digest)
|
||||||
d.initialize(defaultConfig)
|
d.initialize(defaultConfig)
|
||||||
if enableSSE {
|
|
||||||
d.EnableSSE()
|
|
||||||
}
|
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,9 +206,6 @@ func (d *digest) Size() int { return int(d.size) }
|
|||||||
// BlockSize returns the algorithm block size in bytes.
|
// BlockSize returns the algorithm block size in bytes.
|
||||||
func (d *digest) BlockSize() int { return BlockSize }
|
func (d *digest) BlockSize() int { return BlockSize }
|
||||||
|
|
||||||
// Enable SSE
|
|
||||||
func (d *digest) EnableSSE() { d.sseOptimized = true }
|
|
||||||
|
|
||||||
func (d *digest) Write(p []byte) (nn int, err error) {
|
func (d *digest) Write(p []byte) (nn int, err error) {
|
||||||
nn = len(p)
|
nn = len(p)
|
||||||
left := BlockSize - d.nx
|
left := BlockSize - d.nx
|
||||||
@@ -220,11 +213,7 @@ func (d *digest) Write(p []byte) (nn int, err error) {
|
|||||||
// Process buffer.
|
// Process buffer.
|
||||||
copy(d.x[d.nx:], p[:left])
|
copy(d.x[d.nx:], p[:left])
|
||||||
p = p[left:]
|
p = p[left:]
|
||||||
if d.sseOptimized {
|
compress(d, d.x[:])
|
||||||
compress(d, d.x[:])
|
|
||||||
} else {
|
|
||||||
blocks(d, d.x[:])
|
|
||||||
}
|
|
||||||
d.nx = 0
|
d.nx = 0
|
||||||
}
|
}
|
||||||
// Process full blocks except for the last one.
|
// Process full blocks except for the last one.
|
||||||
@@ -233,11 +222,7 @@ func (d *digest) Write(p []byte) (nn int, err error) {
|
|||||||
if n == len(p) {
|
if n == len(p) {
|
||||||
n -= BlockSize
|
n -= BlockSize
|
||||||
}
|
}
|
||||||
if d.sseOptimized {
|
compress(d, p[:n])
|
||||||
compress(d, p[:n])
|
|
||||||
} else {
|
|
||||||
blocks(d, p[:n])
|
|
||||||
}
|
|
||||||
p = p[n:]
|
p = p[n:]
|
||||||
}
|
}
|
||||||
// Fill buffer.
|
// Fill buffer.
|
||||||
@@ -277,11 +262,7 @@ func (d *digest) checkSum() [Size]byte {
|
|||||||
d.f[1] = 0xffffffffffffffff
|
d.f[1] = 0xffffffffffffffff
|
||||||
}
|
}
|
||||||
// Compress last block.
|
// Compress last block.
|
||||||
if d.sseOptimized {
|
compress(d, d.x[:])
|
||||||
compress(d, d.x[:])
|
|
||||||
} else {
|
|
||||||
blocks(d, d.x[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
var out [Size]byte
|
var out [Size]byte
|
||||||
j := 0
|
j := 0
|
||||||
|
|||||||
@@ -21,33 +21,12 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCompress(t *testing.T) {
|
|
||||||
|
|
||||||
in := make([]byte, 128)
|
|
||||||
for i := range in {
|
|
||||||
in[i] = byte(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
hGo := New512(false)
|
|
||||||
hSSE := New512(true)
|
|
||||||
|
|
||||||
hGo.Write(in)
|
|
||||||
sumGo := fmt.Sprintf("%x", hGo.Sum(nil))
|
|
||||||
|
|
||||||
hSSE.Write(in)
|
|
||||||
sumSSE := fmt.Sprintf("%x", hSSE.Sum(nil))
|
|
||||||
|
|
||||||
if sumGo != sumSSE {
|
|
||||||
t.Errorf("expected %s\ngot %s", sumGo, sumSSE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSum(t *testing.T) {
|
func TestSum(t *testing.T) {
|
||||||
buf := make([]byte, len(golden))
|
buf := make([]byte, len(golden))
|
||||||
for i := range buf {
|
for i := range buf {
|
||||||
buf[i] = byte(i)
|
buf[i] = byte(i)
|
||||||
}
|
}
|
||||||
h := New512(true)
|
h := New512()
|
||||||
for i, v := range golden {
|
for i, v := range golden {
|
||||||
if v != fmt.Sprintf("%x", Sum512(buf[:i])) {
|
if v != fmt.Sprintf("%x", Sum512(buf[:i])) {
|
||||||
t.Errorf("%d: Sum512(): \nexpected %s\ngot %x", i, v, Sum512(buf[:i]))
|
t.Errorf("%d: Sum512(): \nexpected %s\ngot %x", i, v, Sum512(buf[:i]))
|
||||||
|
|||||||
Reference in New Issue
Block a user