Skip to content

Commit 7801840

Browse files
committed
support empty pbkdf2 password on openssl 1.0.2
1 parent ac27194 commit 7801840

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pbkdf2.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ func PBKDF2(password, salt []byte, iter, keyLen int, h func() hash.Hash) ([]byte
1414
if md == nil {
1515
return nil, errors.New("unsupported hash function")
1616
}
17+
if len(password) == 0 && vMajor == 1 && vMinor == 0 {
18+
// x/crypto/pbkdf2 supports empty passwords, but OpenSSL 1.0.2
19+
// does not. As a workaround, we pass an "empty" password.
20+
password = make([]byte, C.GO_EVP_MAX_MD_SIZE)
21+
}
1722
out := make([]byte, keyLen)
1823
ok := C.go_openssl_PKCS5_PBKDF2_HMAC(sbase(password), C.int(len(password)), base(salt), C.int(len(salt)), C.int(iter), md, C.int(keyLen), base(out))
1924
if ok != 1 {

0 commit comments

Comments
 (0)