aboutsummaryrefslogtreecommitdiff
path: root/keys.go
diff options
context:
space:
mode:
Diffstat (limited to 'keys.go')
-rw-r--r--keys.go20
1 files changed, 10 insertions, 10 deletions
diff --git a/keys.go b/keys.go
index dae2661..f299a64 100644
--- a/keys.go
+++ b/keys.go
@@ -94,19 +94,19 @@ func (v *EncKey) Check() error {
return nil
}
-func (e *EncKey) Kdf(pass string, rounds int) {
- if rounds == 0 {
- return
+func (e *EncKey) Kdf(ask func() (string, error)) error {
+ if e.KDFRounds == 0 {
+ return nil
}
- xorkey := bhash.Pbkdf([]byte(pass), e.Salt[:], rounds, len(e.SecKey))
+ pass, err := ask()
+ if err != nil {
+ return err
+ }
+ xorkey := bhash.Pbkdf([]byte(pass), e.Salt[:], int(e.KDFRounds), len(e.SecKey))
for i := range xorkey {
e.SecKey[i] ^= xorkey[i]
}
- e.KDFRounds = uint32(rounds)
-}
-
-func (e *EncKey) Rounds() int {
- return int(e.KDFRounds)
+ return nil
}
func Unmarshal(b []byte, v interface{}) error {
@@ -132,7 +132,7 @@ func NewKey() (PubKey, EncKey, error) {
}
pubKey := PubKey{PKAlg: pkAlg}
- encKey := EncKey{PKAlg: pkAlg, KDFAlg: kdfAlg}
+ encKey := EncKey{PKAlg: pkAlg, KDFAlg: kdfAlg, KDFRounds: DefaultRounds}
copy(pubKey.PubKey[:], pub)
copy(encKey.SecKey[:], sec)