Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change PBKDF2 hash from SHA512 to SHA256 (according to specification) #176

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions kdf/kdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package kdf

import (
"crypto/sha512"
"crypto/sha256"

// package is old but corresponds to "golang.org/x/crypto/ssh/internal/bcrypt_pbkdf"
"github.com/dchest/bcrypt_pbkdf"
Expand All @@ -15,7 +15,7 @@ import (
var KDFS = map[string]KDF{
"scrypt": sCrypt{},
"bcrypt": bCrypt{},
"pbkdf2_hmac_sha256": pbkdf2sha512{},
"pbkdf2_hmac_sha256": pbkdf2sha256{},
}

// KDF interface holding "Derive" method.
Expand All @@ -37,9 +37,9 @@ func (bCrypt) Derive(rounds int, password, salt []byte) (derivedKey []byte, err
return bcrypt_pbkdf.Key(password, salt, rounds, chacha20poly1305.KeySize)
}

type pbkdf2sha512 struct {
type pbkdf2sha256 struct {
}

func (pbkdf2sha512) Derive(rounds int, password, salt []byte) (derivedKey []byte, err error) {
return pbkdf2.Key(password, salt, rounds, chacha20poly1305.KeySize, sha512.New), nil
func (pbkdf2sha256) Derive(rounds int, password, salt []byte) (derivedKey []byte, err error) {
return pbkdf2.Key(password, salt, rounds, chacha20poly1305.KeySize, sha256.New), nil
}
2 changes: 1 addition & 1 deletion kdf/kdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestKDF(t *testing.T) {
},
{
name: "pbkdf2_hmac_sha256",
hash: "72bf7d2b4d1f18c97a333e3a89e7f22dc9771b968ddcbc1a494fbbf507059b13",
hash: "dd3352defb9aa734875f7a32b60e4bcf9e3671216d6e0c39f135f0297bf8e121",
},
}
for _, test := range tests {
Expand Down
Loading