From 64beccc9b279a87dc6c4688a6e3e51489d909e3a Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sat, 28 Sep 2024 06:35:25 -0300 Subject: src/scrypt.go: Remove "scrypt" prefix from consts --- src/scrypt.go | 26 ++++++++++++-------------- tests/scrypt.go | 4 ++-- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/scrypt.go b/src/scrypt.go index 103ae66..267cb08 100644 --- a/src/scrypt.go +++ b/src/scrypt.go @@ -18,16 +18,14 @@ import ( const ( + saltMinLength = 32 + desiredLength = 32 maxInt = int((^uint(0)) >> 1) MinimumPasswordLength = 16 -) -const ( - scrypt_N = 1 << 15 - scrypt_r = 8 - scrypt_p = 1 - scryptSaltMinLength = 32 - scryptDesiredLength = 32 + _N = 1 << 15 + r = 8 + p = 1 ) @@ -346,8 +344,8 @@ func scrypt( } func SaltFrom(r io.Reader) ([]byte, error) { - buffer := make([]byte, scryptSaltMinLength) - _, err := io.ReadFull(rand.Reader, buffer) + buffer := make([]byte, saltMinLength) + _, err := io.ReadFull(r, buffer) if err != nil { return nil, err } @@ -355,17 +353,17 @@ func SaltFrom(r io.Reader) ([]byte, error) { } func HashFrom(password []byte, salt []byte) ([]byte, error) { - if len(salt) < scryptSaltMinLength { + if len(salt) < saltMinLength { return nil, SaltTooSmallError } hash, err := scrypt( password, salt, - scrypt_N, - scrypt_r, - scrypt_p, - scryptDesiredLength, + _N, + r, + p, + desiredLength, ) if err != nil { return nil, err diff --git a/tests/scrypt.go b/tests/scrypt.go index d6d59c3..b7d87f1 100644 --- a/tests/scrypt.go +++ b/tests/scrypt.go @@ -431,9 +431,9 @@ func test_Salt() { testing("we generate a random salt of a fixed size", func() { salt := Salt() - assertEq(len(salt), scryptSaltMinLength) + assertEq(len(salt), saltMinLength) - var buffer [scryptSaltMinLength * 2]byte + var buffer [saltMinLength * 2]byte hex.Encode(buffer[:], salt) fmt.Fprintf(os.Stderr, "%s ", string(buffer[:])) }) -- cgit v1.2.3