Skip to content

Commit

Permalink
fix: add cipher
Browse files Browse the repository at this point in the history
  • Loading branch information
J0 committed Sep 25, 2024
1 parent 235dc06 commit 07ed63d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions internal/crypto/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package crypto

import (
"context"
"crypto/aes"
"crypto/cipher"
"crypto/subtle"
"encoding/base64"
"errors"
Expand Down Expand Up @@ -321,19 +323,21 @@ func compareHashAndPasswordScrypt(ctx context.Context, hash, password string) er
}

func firebaseScrypt(password, salt, signerKey []byte, N, r, p uint64, keyLen int) ([]byte, error) {
// Step 1: Use standard scrypt to derive an intermediate key
intermediateKey, err := scrypt.Key(password, salt, int(N), int(r), int(p), 32)

ck, err := scrypt.Key(password, salt, 1<<N, int(r), int(p), keyLen)
if err != nil {
return nil, err
}

// Step 2: Use the intermediate key to derive the final key
result, err := scrypt.Key(intermediateKey, signerKey, 256, 8, 1, keyLen)
if err != nil {
var block cipher.Block
if block, err = aes.NewCipher(ck); err != nil {
return nil, err
}

return result, nil
cipherText := make([]byte, aes.BlockSize+len(signerKey))
stream := cipher.NewCTR(block, cipherText[:aes.BlockSize])
stream.XORKeyStream(cipherText[aes.BlockSize:], signerKey)
return cipherText[aes.BlockSize:], nil
}

// CompareHashAndPassword compares the hash and
Expand Down

0 comments on commit 07ed63d

Please sign in to comment.