2019-07-19 13:11:01 +00:00
|
|
|
package tz
|
|
|
|
|
|
|
|
import (
|
|
|
|
"hash"
|
|
|
|
|
2022-03-09 12:17:18 +00:00
|
|
|
"github.com/nspcc-dev/tzhash/gf127"
|
2019-07-19 13:11:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type digest3 struct {
|
2022-03-09 12:17:18 +00:00
|
|
|
x [2]gf127.GF127x2
|
2019-07-19 13:11:01 +00:00
|
|
|
}
|
|
|
|
|
2019-07-19 14:52:46 +00:00
|
|
|
// type assertion
|
2019-07-19 13:11:01 +00:00
|
|
|
var _ hash.Hash = (*digest3)(nil)
|
|
|
|
|
2019-07-19 14:52:46 +00:00
|
|
|
func newAVX2Inline() *digest3 {
|
2019-07-19 13:11:01 +00:00
|
|
|
d := new(digest3)
|
|
|
|
d.Reset()
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *digest3) Write(data []byte) (n int, err error) {
|
|
|
|
n = len(data)
|
2022-01-10 15:01:15 +00:00
|
|
|
if len(data) != 0 {
|
|
|
|
mulByteSliceRightx2(&d.x[0], &d.x[1], n, &data[0])
|
2019-07-19 13:11:01 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *digest3) Sum(in []byte) []byte {
|
|
|
|
// Make a copy of d so that caller can keep writing and summing.
|
|
|
|
d0 := *d
|
|
|
|
h := d0.checkSum()
|
|
|
|
return append(in, h[:]...)
|
|
|
|
}
|
|
|
|
func (d *digest3) Reset() {
|
2022-03-09 12:17:18 +00:00
|
|
|
d.x[0] = gf127.GF127x2{GF127{1, 0}, GF127{0, 0}}
|
|
|
|
d.x[1] = gf127.GF127x2{GF127{0, 0}, GF127{1, 0}}
|
2019-07-19 13:11:01 +00:00
|
|
|
}
|
2022-02-25 11:48:11 +00:00
|
|
|
func (d *digest3) Size() int { return Size }
|
2019-07-19 13:11:01 +00:00
|
|
|
func (d *digest3) BlockSize() int { return hashBlockSize }
|
2022-02-25 11:48:11 +00:00
|
|
|
func (d *digest3) checkSum() (b [Size]byte) {
|
2019-07-19 13:11:01 +00:00
|
|
|
// Matrix is stored transposed,
|
|
|
|
// but we need to use order consistent with digest.
|
|
|
|
h := d.x[0].ByteArray()
|
|
|
|
copy(b[:], h[:16])
|
|
|
|
copy(b[32:], h[16:])
|
|
|
|
|
|
|
|
h = d.x[1].ByteArray()
|
|
|
|
copy(b[16:], h[:16])
|
|
|
|
copy(b[48:], h[16:])
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-09 12:17:18 +00:00
|
|
|
func mulByteSliceRightx2(c00c10 *gf127.GF127x2, c01c11 *gf127.GF127x2, n int, data *byte)
|