From 847d27f8a688a3136de45e9560063d237c4e2bff Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 17 Jan 2020 14:23:42 +0100 Subject: [PATCH] macaroons: use fast scrypt options in itest and unit tests --- macaroons/security.go | 13 +++++++++++++ macaroons/security_rpctest.go | 14 ++++++++++++++ macaroons/security_test.go | 12 ++++++++++++ macaroons/store.go | 5 +++-- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 macaroons/security.go create mode 100644 macaroons/security_rpctest.go create mode 100644 macaroons/security_test.go diff --git a/macaroons/security.go b/macaroons/security.go new file mode 100644 index 00000000..814b0d25 --- /dev/null +++ b/macaroons/security.go @@ -0,0 +1,13 @@ +// +build !rpctest + +package macaroons + +import "github.com/btcsuite/btcwallet/snacl" + +var ( + // Below are the default scrypt parameters that are used when creating + // the encryption key for the macaroon database with snacl.NewSecretKey. + scryptN = snacl.DefaultN + scryptR = snacl.DefaultR + scryptP = snacl.DefaultP +) diff --git a/macaroons/security_rpctest.go b/macaroons/security_rpctest.go new file mode 100644 index 00000000..d49819e0 --- /dev/null +++ b/macaroons/security_rpctest.go @@ -0,0 +1,14 @@ +// +build rpctest + +package macaroons + +import "github.com/btcsuite/btcwallet/waddrmgr" + +var ( + // Below are the reduced scrypt parameters that are used when creating + // the encryption key for the macaroon database with snacl.NewSecretKey. + // We use very low values for our itest/rpctest to speed things up. + scryptN = waddrmgr.FastScryptOptions.N + scryptR = waddrmgr.FastScryptOptions.R + scryptP = waddrmgr.FastScryptOptions.P +) diff --git a/macaroons/security_test.go b/macaroons/security_test.go new file mode 100644 index 00000000..48c18e31 --- /dev/null +++ b/macaroons/security_test.go @@ -0,0 +1,12 @@ +package macaroons + +import "github.com/btcsuite/btcwallet/waddrmgr" + +func init() { + // Below are the reduced scrypt parameters that are used when creating + // the encryption key for the macaroon database with snacl.NewSecretKey. + // We use very low values for our itest/rpctest to speed things up. + scryptN = waddrmgr.FastScryptOptions.N + scryptR = waddrmgr.FastScryptOptions.R + scryptP = waddrmgr.FastScryptOptions.P +} diff --git a/macaroons/store.go b/macaroons/store.go index 16ccc9a3..affb0c50 100644 --- a/macaroons/store.go +++ b/macaroons/store.go @@ -106,8 +106,9 @@ func (r *RootKeyStorage) CreateUnlock(password *[]byte) error { } // We haven't yet stored a key, so create a new one. - encKey, err := snacl.NewSecretKey(password, snacl.DefaultN, - snacl.DefaultR, snacl.DefaultP) + encKey, err := snacl.NewSecretKey( + password, scryptN, scryptR, scryptP, + ) if err != nil { return err }