diff --git a/hash/hash.go b/hash/hash.go index f0f9a2f..a7dbbde 100644 --- a/hash/hash.go +++ b/hash/hash.go @@ -8,12 +8,31 @@ import ( "strconv" "github.com/OneOfOne/xxhash" + "golang.org/x/crypto/blake2b" "golang.org/x/crypto/sha3" ) // Hash is a convenient alias of hash.Hash type Hash = hash.Hash +// Blake2b256 performs a Blake2 hashing of a binary payload +func Blake2b256(bs []byte) ([]byte, error) { + h, err := blake2b.New256(nil) + if err != nil { + return nil, err + } + return PerformHash(h, bs) +} + +// Blake2b512 performs a Blake2 hashing of a binary payload +func Blake2b512(bs []byte) ([]byte, error) { + h, err := blake2b.New512(nil) + if err != nil { + return nil, err + } + return PerformHash(h, bs) +} + // Sha3256 takes a byte slice // and returns the SHA3-256 hash func Sha3256(bs []byte) ([]byte, error) { diff --git a/rangeproof/innerproduct/innerproduct.go b/rangeproof/innerproduct/innerproduct.go index d6f9cc8..f9ef448 100644 --- a/rangeproof/innerproduct/innerproduct.go +++ b/rangeproof/innerproduct/innerproduct.go @@ -390,7 +390,7 @@ func (proof *Proof) Verify(G, H, L, R []ristretto.Point, HprimeFactor []ristrett return have.Equals(&P) } -// Encode a proof +// Encode a Proof func (proof *Proof) Encode(w io.Writer) error { err := binary.Write(w, binary.BigEndian, proof.A.Bytes()) @@ -416,7 +416,7 @@ func (proof *Proof) Encode(w io.Writer) error { return nil } -// Decode a proof +// Decode a Proof func (proof *Proof) Decode(r io.Reader) error { if proof == nil { return errors.New("struct is nil") @@ -465,31 +465,27 @@ func (proof *Proof) Decode(r io.Reader) error { return nil } -// Equals tests for Equality two proofs +// Equals test another proof for equality func (proof *Proof) Equals(other Proof) bool { - ok := proof.A.Equals(&other.A) - if !ok { - return ok + if ok := proof.A.Equals(&other.A); !ok { + return false } - ok = proof.B.Equals(&other.B) - if !ok { - return ok + if ok := proof.B.Equals(&other.B); !ok { + return false } for i := range proof.L { - ok := proof.L[i].Equals(&other.L[i]) - if !ok { - return ok + if ok := proof.L[i].Equals(&other.L[i]); !ok { + return false } - ok = proof.R[i].Equals(&other.R[i]) - if !ok { - return ok + if ok := proof.R[i].Equals(&other.R[i]); !ok { + return false } } - return ok + return true } func nextPow2(n uint) uint { @@ -506,8 +502,8 @@ func isPower2(n uint32) bool { return (n & (n - 1)) == 0 } -// DiffNextPow2 returns the difference between a given number and the next -// power of two +// DiffNextPow2 checks the closest next pow2 and returns the necessary padding +// amount to get to the that func DiffNextPow2(n uint32) uint32 { pow2 := nextPow2(uint(n)) padAmount := uint32(pow2) - n + 1 diff --git a/rangeproof/rangeproof.go b/rangeproof/rangeproof.go index 5de3984..129dbeb 100644 --- a/rangeproof/rangeproof.go +++ b/rangeproof/rangeproof.go @@ -580,7 +580,7 @@ func (p *Proof) Decode(r io.Reader, includeCommits bool) error { return p.IPProof.Decode(r) } -// Equals tests proof for equality +// Equals returns proof equality with commitments func (p *Proof) Equals(other Proof, includeCommits bool) bool { if len(p.V) != len(other.V) && includeCommits { return false @@ -622,7 +622,7 @@ func (p *Proof) Equals(other Proof, includeCommits bool) bool { return ok } return true - //return p.IPProof.Equals(*other.IPProof) + // return p.IPProof.Equals(*other.IPProof) } func readerToPoint(r io.Reader, p *ristretto.Point) error {