@@ -45,19 +45,29 @@ import (
4545
4646const (
4747 keyHeaderKDF = "scrypt"
48- // 2^18 / 8 / 1 uses 256MB memory and approx 1s CPU time on a modern CPU.
49- scryptN = 1 << 18
50- scryptr = 8
51- scryptp = 1
52- scryptdkLen = 32
48+
49+ // n,r,p = 2^18, 8, 1 uses 256MB memory and approx 1s CPU time on a modern CPU.
50+ StandardScryptN = 1 << 18
51+ StandardScryptP = 1
52+
53+ // n,r,p = 2^12, 8, 6 uses 4MB memory and approx 100ms CPU time on a modern CPU.
54+ LightScryptN = 1 << 12
55+ LightScryptP = 6
56+
57+ scryptR = 8
58+ scryptDKLen = 32
5359)
5460
5561type keyStorePassphrase struct {
5662 keysDirPath string
63+ scryptN int
64+ scryptP int
65+ scryptR int
66+ scryptDKLen int
5767}
5868
59- func NewKeyStorePassphrase (path string ) KeyStore {
60- return & keyStorePassphrase {path }
69+ func NewKeyStorePassphrase (path string , scryptN int , scryptP int ) KeyStore {
70+ return & keyStorePassphrase {path , scryptN , scryptP , scryptR , scryptDKLen }
6171}
6272
6373func (ks keyStorePassphrase ) GenerateNewKey (rand io.Reader , auth string ) (key * Key , err error ) {
@@ -87,11 +97,10 @@ func (ks keyStorePassphrase) GetKeyAddresses() (addresses []common.Address, err
8797func (ks keyStorePassphrase ) StoreKey (key * Key , auth string ) (err error ) {
8898 authArray := []byte (auth )
8999 salt := randentropy .GetEntropyCSPRNG (32 )
90- derivedKey , err := scrypt .Key (authArray , salt , scryptN , scryptr , scryptp , scryptdkLen )
100+ derivedKey , err := scrypt .Key (authArray , salt , ks . scryptN , ks . scryptR , ks . scryptP , ks . scryptDKLen )
91101 if err != nil {
92102 return err
93103 }
94-
95104 encryptKey := derivedKey [:16 ]
96105 keyBytes := FromECDSA (key .PrivateKey )
97106
@@ -104,10 +113,10 @@ func (ks keyStorePassphrase) StoreKey(key *Key, auth string) (err error) {
104113 mac := Sha3 (derivedKey [16 :32 ], cipherText )
105114
106115 scryptParamsJSON := make (map [string ]interface {}, 5 )
107- scryptParamsJSON ["n" ] = scryptN
108- scryptParamsJSON ["r" ] = scryptr
109- scryptParamsJSON ["p" ] = scryptp
110- scryptParamsJSON ["dklen" ] = scryptdkLen
116+ scryptParamsJSON ["n" ] = ks . scryptN
117+ scryptParamsJSON ["r" ] = ks . scryptR
118+ scryptParamsJSON ["p" ] = ks . scryptP
119+ scryptParamsJSON ["dklen" ] = ks . scryptDKLen
111120 scryptParamsJSON ["salt" ] = hex .EncodeToString (salt )
112121
113122 cipherParamsJSON := cipherparamsJSON {
0 commit comments