Skip to content

Commit

Permalink
Merge pull request #20 from dusk-network/feature-19
Browse files Browse the repository at this point in the history
Add Blake2b256 and Blake2b512 hashing
  • Loading branch information
autholykos committed May 26, 2020
2 parents 6e4a110 + e0d6c50 commit deb12e0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
19 changes: 19 additions & 0 deletions hash/hash.go
Expand Up @@ -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) {
Expand Down
32 changes: 14 additions & 18 deletions rangeproof/innerproduct/innerproduct.go
Expand Up @@ -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())
Expand All @@ -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")
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions rangeproof/rangeproof.go
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit deb12e0

Please sign in to comment.