tz: export checksum size
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
0078ce6e1d
commit
337819d130
8 changed files with 20 additions and 19 deletions
|
@ -33,11 +33,11 @@ func (d *digest) Sum(in []byte) []byte {
|
|||
return append(in, h[:]...)
|
||||
}
|
||||
|
||||
func (d *digest) checkSum() [hashSize]byte {
|
||||
func (d *digest) checkSum() [Size]byte {
|
||||
return d.byteArray()
|
||||
}
|
||||
|
||||
func (d *digest) byteArray() (b [hashSize]byte) {
|
||||
func (d *digest) byteArray() (b [Size]byte) {
|
||||
copy(b[:], d.x[0].ByteArray())
|
||||
copy(b[16:], d.x[1].ByteArray())
|
||||
copy(b[32:], d.x[2].ByteArray())
|
||||
|
@ -68,7 +68,7 @@ func (d *digest) Write(data []byte) (n int, err error) {
|
|||
}
|
||||
|
||||
func (d *digest) Size() int {
|
||||
return hashSize
|
||||
return Size
|
||||
}
|
||||
|
||||
func (d *digest) BlockSize() int {
|
||||
|
|
|
@ -47,9 +47,9 @@ func (d *digest2) Reset() {
|
|||
d.x[0] = avx2.GF127x2{GF127{1, 0}, GF127{0, 0}}
|
||||
d.x[1] = avx2.GF127x2{GF127{0, 0}, GF127{1, 0}}
|
||||
}
|
||||
func (d *digest2) Size() int { return hashSize }
|
||||
func (d *digest2) Size() int { return Size }
|
||||
func (d *digest2) BlockSize() int { return hashBlockSize }
|
||||
func (d *digest2) checkSum() (b [hashSize]byte) {
|
||||
func (d *digest2) checkSum() (b [Size]byte) {
|
||||
// Matrix is stored transposed,
|
||||
// but we need to use order consistent with digest.
|
||||
h := d.x[0].ByteArray()
|
||||
|
|
|
@ -41,9 +41,9 @@ func (d *digest3) Reset() {
|
|||
d.x[0] = avx2.GF127x2{GF127{1, 0}, GF127{0, 0}}
|
||||
d.x[1] = avx2.GF127x2{GF127{0, 0}, GF127{1, 0}}
|
||||
}
|
||||
func (d *digest3) Size() int { return hashSize }
|
||||
func (d *digest3) Size() int { return Size }
|
||||
func (d *digest3) BlockSize() int { return hashBlockSize }
|
||||
func (d *digest3) checkSum() (b [hashSize]byte) {
|
||||
func (d *digest3) checkSum() (b [Size]byte) {
|
||||
// Matrix is stored transposed,
|
||||
// but we need to use order consistent with digest.
|
||||
h := d.x[0].ByteArray()
|
||||
|
|
|
@ -27,11 +27,11 @@ func (d *digest4) Sum(in []byte) []byte {
|
|||
return append(in, h[:]...)
|
||||
}
|
||||
|
||||
func (d *digest4) checkSum() [hashSize]byte {
|
||||
func (d *digest4) checkSum() [Size]byte {
|
||||
return d.byteArray()
|
||||
}
|
||||
|
||||
func (d *digest4) byteArray() (b [hashSize]byte) {
|
||||
func (d *digest4) byteArray() (b [Size]byte) {
|
||||
copy(b[:], d.x[0].ByteArray())
|
||||
copy(b[16:], d.x[1].ByteArray())
|
||||
copy(b[32:], d.x[2].ByteArray())
|
||||
|
@ -55,7 +55,7 @@ func (d *digest4) Write(data []byte) (n int, err error) {
|
|||
}
|
||||
|
||||
func (d *digest4) Size() int {
|
||||
return hashSize
|
||||
return Size
|
||||
}
|
||||
|
||||
func (d *digest4) BlockSize() int {
|
||||
|
|
|
@ -13,7 +13,8 @@ import (
|
|||
type Implementation int
|
||||
|
||||
const (
|
||||
hashSize = 64
|
||||
// Size is the size of a Tillich-Zemor hash sum in bytes.
|
||||
Size = 64
|
||||
hashBlockSize = 128
|
||||
|
||||
_ Implementation = iota
|
||||
|
@ -77,7 +78,7 @@ func New() hash.Hash {
|
|||
}
|
||||
|
||||
// Sum returns Tillich-Zémor checksum of data.
|
||||
func Sum(data []byte) [hashSize]byte {
|
||||
func Sum(data []byte) [Size]byte {
|
||||
if hasAVX2 {
|
||||
d := newAVX2Inline()
|
||||
_, _ = d.Write(data) // no errors
|
||||
|
@ -111,11 +112,11 @@ func Concat(hs [][]byte) ([]byte, error) {
|
|||
func Validate(h []byte, hs [][]byte) (bool, error) {
|
||||
var (
|
||||
b []byte
|
||||
got, expected [hashSize]byte
|
||||
got, expected [Size]byte
|
||||
err error
|
||||
)
|
||||
|
||||
if len(h) != hashSize {
|
||||
if len(h) != Size {
|
||||
return false, errors.New("invalid hash")
|
||||
} else if len(hs) == 0 {
|
||||
return false, errors.New("empty slice")
|
||||
|
|
|
@ -133,7 +133,7 @@ func TestHomomorphism(t *testing.T) {
|
|||
c1, c2 sl2
|
||||
n int
|
||||
err error
|
||||
h, h1, h2 [hashSize]byte
|
||||
h, h1, h2 [Size]byte
|
||||
b []byte
|
||||
)
|
||||
|
||||
|
|
|
@ -22,11 +22,11 @@ func (d *digestp) Sum(in []byte) []byte {
|
|||
return append(in, h[:]...)
|
||||
}
|
||||
|
||||
func (d *digestp) checkSum() [hashSize]byte {
|
||||
func (d *digestp) checkSum() [Size]byte {
|
||||
return d.byteArray()
|
||||
}
|
||||
|
||||
func (d *digestp) byteArray() (b [hashSize]byte) {
|
||||
func (d *digestp) byteArray() (b [Size]byte) {
|
||||
for i := 0; i < 4; i++ {
|
||||
t := d.x[i].ByteArray()
|
||||
copy(b[i*16:], t[:])
|
||||
|
@ -58,7 +58,7 @@ func (d *digestp) Write(data []byte) (n int, err error) {
|
|||
}
|
||||
|
||||
func (d *digestp) Size() int {
|
||||
return hashSize
|
||||
return Size
|
||||
}
|
||||
|
||||
func (d *digestp) BlockSize() int {
|
||||
|
|
|
@ -185,7 +185,7 @@ func (c *sl2) String() string {
|
|||
c[1][0].String() + c[1][1].String()
|
||||
}
|
||||
|
||||
func (c *sl2) ByteArray() (b [hashSize]byte) {
|
||||
func (c *sl2) ByteArray() (b [Size]byte) {
|
||||
t := c[0][0].ByteArray()
|
||||
copy(b[:], t)
|
||||
|
||||
|
|
Loading…
Reference in a new issue