diff options
author | Jakob Unterwurzacher | 2015-11-29 18:52:58 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2015-11-29 18:53:40 +0100 |
commit | bb116282b7db6a6400586d756c6dfdcc8f85fdab (patch) | |
tree | f06fe917002c004569c84097595a4c5b357a4407 /cryptfs/kdf.go | |
parent | 71bfa1f0fb540790f87faac600e4041052b4d217 (diff) |
Add "-scryptn" option that sets the cost parameter for scryptv0.5-rc1
Use that option to speed up the automated tests by 7 seconds.
Before:
ok github.com/rfjakob/gocryptfs/integration_tests 26.667s
After:
ok github.com/rfjakob/gocryptfs/integration_tests 19.534s
Diffstat (limited to 'cryptfs/kdf.go')
-rw-r--r-- | cryptfs/kdf.go | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/cryptfs/kdf.go b/cryptfs/kdf.go index 32870cd..73be0bb 100644 --- a/cryptfs/kdf.go +++ b/cryptfs/kdf.go @@ -1,6 +1,8 @@ package cryptfs import ( + "os" + "math" "fmt" "golang.org/x/crypto/scrypt" ) @@ -8,7 +10,7 @@ import ( const ( // 1 << 16 uses 64MB of memory, // takes 4 seconds on my Atom Z3735F netbook - SCRYPT_DEFAULT_N = 1 << 16 + SCRYPT_DEFAULT_LOGN = 16 ) type scryptKdf struct { @@ -19,10 +21,18 @@ type scryptKdf struct { KeyLen int } -func NewScryptKdf() scryptKdf { +func NewScryptKdf(logN int) scryptKdf { var s scryptKdf s.Salt = RandBytes(KEY_LEN) - s.N = SCRYPT_DEFAULT_N + if logN <= 0 { + s.N = 1 << SCRYPT_DEFAULT_LOGN + } else { + if logN < 10 { + fmt.Printf("Error: scryptn below 10 is too low to make sense. Aborting.") + os.Exit(1) + } + s.N = 1 << uint32(logN) + } s.R = 8 // Always 8 s.P = 1 // Always 1 s.KeyLen = KEY_LEN @@ -36,3 +46,9 @@ func (s *scryptKdf) DeriveKey(pw string) []byte { } return k } + +// LogN - N is saved as 2^LogN, but LogN is much easier to work with. +// This function gives you LogN = Log2(N). +func (s *scryptKdf) LogN() int { + return int(math.Log2(float64(s.N))+0.5) +} |