Skip to content

Commit

Permalink
replaced the package with fully qualified github name and moved Xxhas…
Browse files Browse the repository at this point in the history
…h specific functionalities from misleading 'crypto' package to 'hash'
  • Loading branch information
autholykos committed Aug 15, 2019
1 parent b6b1423 commit 29cb812
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 138 deletions.
4 changes: 2 additions & 2 deletions bls/bls.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"io"
"math/big"

"dusk-crypto/bn256"
"dusk-crypto/hash"
"github.com/dusk-network/dusk-crypto/bn256"
"github.com/dusk-network/dusk-crypto/hash"

"github.com/pkg/errors"
"golang.org/x/crypto/sha3"
Expand Down
2 changes: 1 addition & 1 deletion bls/bls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"math/big"
"testing"

"github.com/dusk-network/dusk-crypto/bn256"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"dusk-crypto/bn256"
)

func randomMessage() []byte {
Expand Down
51 changes: 0 additions & 51 deletions crypto.go

This file was deleted.

21 changes: 0 additions & 21 deletions crypto_test.go

This file was deleted.

3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module dusk-crypto
module github.com/dusk-network/dusk-crypto

require (
github.com/OneOfOne/xxhash v1.2.5
github.com/bwesterb/go-ristretto v1.1.0
github.com/pkg/errors v0.8.1
github.com/stretchr/testify v1.3.0
gitlab.dusk.network/dusk-core/dusk-go v0.0.0-20190409155819-76a6a900e485 // indirect
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f
golang.org/x/sys v0.0.0-20190412213103-97732733099d
)
43 changes: 0 additions & 43 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,64 +1,21 @@
github.com/OneOfOne/xxhash v1.2.5 h1:zl/OfRA6nftbBK9qTohYBJ5xvw6C/oNKizR7cZGl3cI=
github.com/OneOfOne/xxhash v1.2.5/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/bwesterb/go-ristretto v1.0.0/go.mod h1:N/KzfPHVf0cM6so9lbr2hamEhlH9xev3NIj+B6p+Eyc=
github.com/bwesterb/go-ristretto v1.1.0 h1:KiOn1eqKcCe5X4Y6OPGS4u3XyVmxUnh/WAHU7bO3XXo=
github.com/bwesterb/go-ristretto v1.1.0/go.mod h1:N/KzfPHVf0cM6so9lbr2hamEhlH9xev3NIj+B6p+Eyc=
github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/zorkian/go-datadog-api v2.19.0+incompatible/go.mod h1:PkXwHX9CUQa/FpB9ZwAD45N1uhCW4MT/Wj7m36PbKss=
gitlab.dusk.network/dusk-core/bn256 v0.0.0-20190123110933-f166bf1226b0/go.mod h1:Y/mEVzzmpfBXeSoqA9Oo5Mbda09kzCpe0mg2yFYM0Bg=
gitlab.dusk.network/dusk-core/dusk-go v0.0.0-20190409155819-76a6a900e485 h1:/wO+ABDw1LKidTrs307FkOuw+CBoACh3fv2fSPzVehM=
gitlab.dusk.network/dusk-core/dusk-go v0.0.0-20190409155819-76a6a900e485/go.mod h1:XIrXpfu85/f/DMV0YCFgxXpU3eedP4lt4RyKg74HqZY=
gitlab.dusk.network/dusk-core/zkproof v0.0.0-20190407000649-4f8f6ba4acd5/go.mod h1:lwJWKZOXYSbGtY9MCslEfuxWkt4tTfLi0uGTMNLFB2U=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f h1:R423Cnkcp5JABoeemiGEPlt9tHXFfw5kvc0yqlxRPWo=
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/zorkian/go-datadog-api.v2 v2.19.0/go.mod h1:kx0CSMRpzEZfx/nFH62GLU4stZjparh/BRpM89t4XCQ=
44 changes: 44 additions & 0 deletions hash/hash.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package hash

import (
"crypto/rand"
"encoding/binary"
"errors"
"hash"
"strconv"

"github.com/OneOfOne/xxhash"
"golang.org/x/crypto/sha3"
)

// Hash is a convenient alias of hash.Hash
type Hash = hash.Hash

// Sha3256 takes a byte slice
Expand All @@ -30,6 +35,45 @@ func Sha3512(bs []byte) ([]byte, error) {
return PerformHash(sha3.New512(), bs)
}

// Xxhash uses 64 bit xxhashing. It is not meant as a trapdoor, but as a fast collision resistant hashing for performant equal check and store retrieval
func Xxhash(bs []byte) ([]byte, error) {
return PerformHash(xxhash.New64(), bs)
}

// RandEntropy takes a uint32 argument n and populates a byte slice of
// size n with random input.
func RandEntropy(n uint32) ([]byte, error) {

b := make([]byte, n)
a, err := rand.Read(b)

if err != nil {
return nil, errors.New("Error generating entropy " + err.Error())
}
if uint32(a) != n {
return nil, errors.New("Error expected to read" + strconv.Itoa(int(n)) + " bytes instead read " + strconv.Itoa(a) + " bytes")
}
return b, nil
}

// Checksum hashes the data with Xxhash
// and returns the first four bytes
func Checksum(data []byte) (uint32, error) {
hash, err := Xxhash(data)
if err != nil {
return 0, err
}
checksum := binary.BigEndian.Uint32(hash[:4])
return checksum, err
}

//CompareChecksum takes data and an expected checksum
// Returns true if the checksum of the given data is
// equal to the expected checksum
func CompareChecksum(data []byte, want uint32) bool {
got, err := Checksum(data)
if err != nil {
return false
}
return got != want
}
16 changes: 15 additions & 1 deletion hash/hash_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package hash

import (
"crypto/rand"
"math/rand"
"testing"

"github.com/stretchr/testify/assert"
)

func randomMessage(size int) []byte {
Expand All @@ -28,3 +30,15 @@ func BenchmarkSha3(b *testing.B) {
_, _ = Sha3256(testBytes)
}
}

func TestRandEntropy(t *testing.T) {

for i := 0; i < 100; i++ {
n := uint32(rand.Intn(1e3))
en, err := RandEntropy(n)

assert.Equal(t, nil, err)
assert.Equal(t, uint32(len(en)), uint32(n))

}
}
2 changes: 1 addition & 1 deletion merkletree/merkletree.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"errors"

"dusk-crypto/hash"
"github.com/dusk-network/dusk-crypto/hash"
)

// Payload is data that can be stored and checked in the Merkletree.
Expand Down
2 changes: 1 addition & 1 deletion merkletree/merkletree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"testing"

"dusk-crypto/hash"
"github.com/dusk-network/dusk-crypto/hash"
)

type TestPayload struct {
Expand Down
2 changes: 1 addition & 1 deletion rangeproof/bitCommitment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math/big"
"testing"

"dusk-crypto/rangeproof"
"github.com/dusk-network/dusk-crypto/rangeproof"

"github.com/stretchr/testify/assert"
)
Expand Down
4 changes: 2 additions & 2 deletions rangeproof/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (

"github.com/pkg/errors"

"dusk-crypto/rangeproof/vector"
"github.com/dusk-network/dusk-crypto/rangeproof/vector"

ristretto "github.com/bwesterb/go-ristretto"

"dusk-crypto/rangeproof/pedersen"
"github.com/dusk-network/dusk-crypto/rangeproof/pedersen"
)

// Put all debug functions here
Expand Down
2 changes: 1 addition & 1 deletion rangeproof/generators/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

ristretto "github.com/bwesterb/go-ristretto"
"github.com/stretchr/testify/assert"
generator "dusk-crypto/rangeproof/generators"
generator "github.com/dusk-network/dusk-crypto/rangeproof/generators"
)

func TestGeneratorsLen(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions rangeproof/innerproduct/innerproduct.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"errors"
"math/bits"

"dusk-crypto/rangeproof/fiatshamir"
"dusk-crypto/rangeproof/vector"
"github.com/dusk-network/dusk-crypto/rangeproof/fiatshamir"
"github.com/dusk-network/dusk-crypto/rangeproof/vector"

ristretto "github.com/bwesterb/go-ristretto"
)
Expand Down
4 changes: 2 additions & 2 deletions rangeproof/innerproduct/innerproduct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package innerproduct
import (
"testing"

"dusk-crypto/rangeproof/pedersen"
"dusk-crypto/rangeproof/vector"
"github.com/dusk-network/dusk-crypto/rangeproof/pedersen"
"github.com/dusk-network/dusk-crypto/rangeproof/vector"

ristretto "github.com/bwesterb/go-ristretto"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion rangeproof/pedersen/pedersen.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pedersen

import (
generator "dusk-crypto/rangeproof/generators"
generator "github.com/dusk-network/dusk-crypto/rangeproof/generators"

ristretto "github.com/bwesterb/go-ristretto"
)
Expand Down
2 changes: 1 addition & 1 deletion rangeproof/pedersen/pedersen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math/big"
"testing"

"dusk-crypto/rangeproof/pedersen"
"github.com/dusk-network/dusk-crypto/rangeproof/pedersen"

ristretto "github.com/bwesterb/go-ristretto"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion rangeproof/poly.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/pkg/errors"

"dusk-crypto/rangeproof/vector"
"github.com/dusk-network/dusk-crypto/rangeproof/vector"

ristretto "github.com/bwesterb/go-ristretto"
)
Expand Down
8 changes: 4 additions & 4 deletions rangeproof/rangeproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (

"github.com/pkg/errors"

"dusk-crypto/rangeproof/fiatshamir"
"dusk-crypto/rangeproof/innerproduct"
"dusk-crypto/rangeproof/pedersen"
"dusk-crypto/rangeproof/vector"
"github.com/dusk-network/dusk-crypto/rangeproof/fiatshamir"
"github.com/dusk-network/dusk-crypto/rangeproof/innerproduct"
"github.com/dusk-network/dusk-crypto/rangeproof/pedersen"
"github.com/dusk-network/dusk-crypto/rangeproof/vector"

ristretto "github.com/bwesterb/go-ristretto"
)
Expand Down

0 comments on commit 29cb812

Please sign in to comment.