forked from TrueCloudLab/tzhash
*: rename ByteArray
to Bytes
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
0e0d28e82f
commit
0d764a51b7
5 changed files with 21 additions and 26 deletions
|
@ -142,7 +142,7 @@ func Random() *GF127 {
|
|||
|
||||
// String returns hex-encoded representation, starting with MSB.
|
||||
func (c *GF127) String() string {
|
||||
buf := c.ByteArray()
|
||||
buf := c.Bytes()
|
||||
return hex.EncodeToString(buf[:])
|
||||
}
|
||||
|
||||
|
@ -151,9 +151,9 @@ func (c *GF127) Equals(b *GF127) bool {
|
|||
return c[0] == b[0] && c[1] == b[1]
|
||||
}
|
||||
|
||||
// ByteArray represents element of GF(2^127) as byte array of length 16.
|
||||
func (c *GF127) ByteArray() []byte {
|
||||
buf := make([]byte, 16)
|
||||
// Bytes represents element of GF(2^127) as byte array of length 16.
|
||||
func (c *GF127) Bytes() [16]byte {
|
||||
var buf [16]byte
|
||||
binary.BigEndian.PutUint64(buf[:8], c[1])
|
||||
binary.BigEndian.PutUint64(buf[8:], c[0])
|
||||
return buf
|
||||
|
@ -161,7 +161,7 @@ func (c *GF127) ByteArray() []byte {
|
|||
|
||||
// MarshalBinary implements encoding.BinaryMarshaler.
|
||||
func (c *GF127) MarshalBinary() (data []byte, err error) {
|
||||
buf := c.ByteArray()
|
||||
buf := c.Bytes()
|
||||
return buf[:], nil
|
||||
}
|
||||
|
||||
|
|
|
@ -37,14 +37,13 @@ func (a *GF127x2) Equal(b *GF127x2) bool {
|
|||
// String returns hex-encoded representation, starting with MSB.
|
||||
// Elements of pair are separated by comma.
|
||||
func (a *GF127x2) String() string {
|
||||
b := a.ByteArray()
|
||||
b := a.Bytes()
|
||||
return hex.EncodeToString(b[:16]) + " , " + hex.EncodeToString(b[16:])
|
||||
}
|
||||
|
||||
// ByteArray represents element of GF(2^127) as byte array of length 32.
|
||||
func (a *GF127x2) ByteArray() (buf []byte) {
|
||||
buf = make([]byte, 32)
|
||||
binary.BigEndian.PutUint64(buf, a[0][1])
|
||||
// Bytes represents element of GF(2^127) as byte array of length 32.
|
||||
func (a *GF127x2) Bytes() (buf [32]byte) {
|
||||
binary.BigEndian.PutUint64(buf[:], a[0][1])
|
||||
binary.BigEndian.PutUint64(buf[8:], a[0][0])
|
||||
binary.BigEndian.PutUint64(buf[16:], a[1][1])
|
||||
binary.BigEndian.PutUint64(buf[24:], a[1][0])
|
||||
|
|
14
tz/digest.go
14
tz/digest.go
|
@ -40,21 +40,17 @@ func (d *digest) Sum(in []byte) []byte {
|
|||
return append(in, h[:]...)
|
||||
}
|
||||
|
||||
func (d *digest) checkSum() [Size]byte {
|
||||
return d.byteArray()
|
||||
}
|
||||
|
||||
func (d *digest) byteArray() (b [Size]byte) {
|
||||
t := d.x[0].ByteArray()
|
||||
func (d *digest) checkSum() (b [Size]byte) {
|
||||
t := d.x[0].Bytes()
|
||||
copy(b[:], t[:])
|
||||
|
||||
t = d.x[2].ByteArray()
|
||||
t = d.x[2].Bytes()
|
||||
copy(b[16:], t[:])
|
||||
|
||||
t = d.x[1].ByteArray()
|
||||
t = d.x[1].Bytes()
|
||||
copy(b[32:], t[:])
|
||||
|
||||
t = d.x[3].ByteArray()
|
||||
t = d.x[3].Bytes()
|
||||
copy(b[48:], t[:])
|
||||
|
||||
return
|
||||
|
|
|
@ -160,7 +160,7 @@ func TestHomomorphism(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
c1.Mul(&c1, &c2)
|
||||
require.Equal(t, h, c1.ByteArray())
|
||||
require.Equal(t, h, c1.Bytes())
|
||||
}
|
||||
|
||||
var testCasesConcat = []struct {
|
||||
|
|
12
tz/sl2.go
12
tz/sl2.go
|
@ -19,7 +19,7 @@ var id = sl2{
|
|||
|
||||
// MarshalBinary implements encoding.BinaryMarshaler.
|
||||
func (c *sl2) MarshalBinary() (data []byte, err error) {
|
||||
s := c.ByteArray()
|
||||
s := c.Bytes()
|
||||
return s[:], nil
|
||||
}
|
||||
|
||||
|
@ -159,17 +159,17 @@ func (c *sl2) String() string {
|
|||
c[1][0].String() + c[1][1].String()
|
||||
}
|
||||
|
||||
func (c *sl2) ByteArray() (b [Size]byte) {
|
||||
t := c[0][0].ByteArray()
|
||||
func (c *sl2) Bytes() (b [Size]byte) {
|
||||
t := c[0][0].Bytes()
|
||||
copy(b[:], t[:])
|
||||
|
||||
t = c[0][1].ByteArray()
|
||||
t = c[0][1].Bytes()
|
||||
copy(b[16:], t[:])
|
||||
|
||||
t = c[1][0].ByteArray()
|
||||
t = c[1][0].Bytes()
|
||||
copy(b[32:], t[:])
|
||||
|
||||
t = c[1][1].ByteArray()
|
||||
t = c[1][1].Bytes()
|
||||
copy(b[48:], t[:])
|
||||
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue