macaroons: use fast scrypt options in itest and unit tests

This commit is contained in:
Oliver Gugger 2020-01-17 14:23:42 +01:00
parent 466294ed4c
commit 847d27f8a6
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
4 changed files with 42 additions and 2 deletions

13
macaroons/security.go Normal file

@ -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
)

@ -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
)

@ -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
}

@ -106,8 +106,9 @@ func (r *RootKeyStorage) CreateUnlock(password *[]byte) error {
} }
// We haven't yet stored a key, so create a new one. // We haven't yet stored a key, so create a new one.
encKey, err := snacl.NewSecretKey(password, snacl.DefaultN, encKey, err := snacl.NewSecretKey(
snacl.DefaultR, snacl.DefaultP) password, scryptN, scryptR, scryptP,
)
if err != nil { if err != nil {
return err return err
} }