Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Mar 6, 2024
1 parent 51bc733 commit ded2ee1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions kdf/bcrypt_pbkdf/bcrypt_pbkdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ func Key(password, salt []byte, rounds, keyLen int) ([]byte, error) {
}

var shapass, shasalt [sha512.Size]byte

out, tmp := make([]byte, 32), make([]byte, 32)
cnt := make([]byte, 4)
var out, tmp [32]byte
var cnt [4]byte

numBlocks := (keyLen + len(out) - 1) / len(out)
key := make([]byte, numBlocks*len(out))
Expand All @@ -43,18 +42,18 @@ func Key(password, salt []byte, rounds, keyLen int) ([]byte, error) {
h.Reset()
h.Write(salt)

binary.BigEndian.PutUint32(cnt, uint32(block))
h.Write(cnt)
binary.BigEndian.PutUint32(cnt[:], uint32(block))
h.Write(cnt[:])

bcryptHash(tmp, shapass[:], h.Sum(shasalt[:0]))
copy(out, tmp)
bcryptHash(tmp[:], shapass[:], h.Sum(shasalt[:0]))
copy(out[:], tmp[:])

for i := 2; i <= rounds; i++ {
h.Reset()
h.Write(tmp)
bcryptHash(tmp, shapass[:], h.Sum(shasalt[:0]))
h.Write(tmp[:])
bcryptHash(tmp[:], shapass[:], h.Sum(shasalt[:0]))

subtle.XORBytes(out, out, tmp)
subtle.XORBytes(out[:], out[:], tmp[:])
}

for i, v := range out {
Expand Down
2 changes: 1 addition & 1 deletion kdf/bcrypt_pbkdf/bcrypt_pbkdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
)

func Test_Kdf(t *testing.T) {
func Test_Pbkdf(t *testing.T) {
type args struct {
password []byte
salt []byte
Expand Down

0 comments on commit ded2ee1

Please sign in to comment.