diff --git a/crypto/subtle.go b/crypto/subtle.go index eca3c30..9a3f078 100644 --- a/crypto/subtle.go +++ b/crypto/subtle.go @@ -25,7 +25,7 @@ func DecryptWithoutIntegrity(key, input, iv []byte) ([]byte, error) { return EncryptWithoutIntegrity(key, input, iv) } -// DeriveKey derives a key from a password using scrypt. -func DeriveKey(password string, salt []byte) ([]byte, error) { - return scrypt.Key([]byte(password), salt, 32768, 8, 1, 32) +// DeriveKey derives a key from a password using scrypt. N should be set to the highest power of 2 you can derive within 100 milliseconds. +func DeriveKey(password string, salt []byte, N int) ([]byte, error) { + return scrypt.Key([]byte(password), salt, N, 8, 1, 32) } diff --git a/crypto/subtle_test.go b/crypto/subtle_test.go index 1c8cbc7..06455dc 100644 --- a/crypto/subtle_test.go +++ b/crypto/subtle_test.go @@ -29,7 +29,7 @@ func TestSubtle_DecryptWithoutIntegrity(t *testing.T) { func TestSubtle_DeriveKey(t *testing.T) { salt, _ := hex.DecodeString("c828f258a76aad7b") - dk, _ := DeriveKey("some password", salt) + dk, _ := DeriveKey("some password", salt, 32768) if hex.EncodeToString(dk) != "9469cccfc8a8d005247f39fa3e5b35a97db456cecf18deac6d84364d0818d763" { t.Fatal("DeriveKey returned unexpected result") }