Skip to content

Commit

Permalink
personalisation -> seed
Browse files Browse the repository at this point in the history
  • Loading branch information
jedisct1 committed Apr 4, 2018
1 parent 63ae3e8 commit aa5ef8e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions progressiveHash.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@ import (
"golang.org/x/crypto/blake2b"
)

// Hash - Hash `in` with personalisation `personal`, an initial number of rounds `initialRounds`,
// Hash - Hash `in` with seedisation `seed`, an initial number of rounds `initialRounds`,
// and increase the work factor `progressiveLength` times to eventually produce an `outLength` bit-long digest.
func Hash(in []byte, personal []byte, initialRounds uint64, progressiveLength int, outLength int) ([]byte, error) {
return hash(in, personal, initialRounds, progressiveLength, outLength, nil)
func Hash(in []byte, seed []byte, initialRounds uint64, progressiveLength int, outLength int) ([]byte, error) {
return hash(in, seed, initialRounds, progressiveLength, outLength, nil)
}

// Verify - Verify a previously computed hash `expected` using the input `in`, a personalisation `personal`,
// Verify - Verify a previously computed hash `expected` using the input `in`, a seedisation `seed`,
// increasing the work factor `progressiveLength` times to match the initial hash length `outLength` bits.
func Verify(in []byte, personal []byte, initialRounds uint64, progressiveLength int, outLength int, expected []byte) error {
_, err := hash(in, personal, initialRounds, progressiveLength, outLength, &expected)
func Verify(in []byte, seed []byte, initialRounds uint64, progressiveLength int, outLength int, expected []byte) error {
_, err := hash(in, seed, initialRounds, progressiveLength, outLength, &expected)
return err
}

func hash(in []byte, personal []byte, initialRounds uint64, progressiveLength int, outLength int, expected *[]byte) ([]byte, error) {
func hash(in []byte, seed []byte, initialRounds uint64, progressiveLength int, outLength int, expected *[]byte) ([]byte, error) {
if progressiveLength < 0 || outLength < 1 {
return nil, errors.New("invalid output length")
}
if len(personal) > 127 {
return nil, errors.New("personalization too long")
if len(seed) > 127 {
return nil, errors.New("seed too long")
}
if outLength < progressiveLength {
outLength = progressiveLength
}
xin := make([]byte, 128+len(in))
copy(xin, personal)
copy(xin, seed)
copy(xin[128:], in)
h := blake2b.Sum512(xin)
var out []byte
Expand Down
8 changes: 4 additions & 4 deletions progressiveHash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ package progressiveHash
import "testing"

func testHash(t *testing.T) {
personalisation := []byte("test application")
seed := []byte("test application")
in := []byte("input string")

h, err := Hash(in, personalisation, 50000, 8, 256)
h, err := Hash(in, seed, 50000, 8, 256)
if err != nil {
panic(err)
}

err = Verify(in, personalisation, 50000, 8, 256, h)
err = Verify(in, seed, 50000, 8, 256, h)
if err != nil {
panic(err)
}

err = Verify(in, personalisation, 10000, 8, 256, h)
err = Verify(in, seed, 10000, 8, 256, h)
if err != nil {
panic("verification shouldn't have passed")
}
Expand Down

0 comments on commit aa5ef8e

Please sign in to comment.