KeyCrypterScrypt: Log time taken for deriving key from password.

This commit is contained in:
Andreas Schildbach
2016-08-19 22:28:50 +02:00
parent 945d1bdb1d
commit 3d642b9916

View File

@@ -18,6 +18,7 @@
package org.bitcoinj.crypto;
import com.google.common.base.Objects;
import com.google.common.base.Stopwatch;
import com.google.protobuf.ByteString;
import com.lambdaworks.crypto.SCrypt;
import org.bitcoinj.core.Utils;
@@ -154,7 +155,10 @@ public class KeyCrypterScrypt implements KeyCrypter {
log.warn("You are using a ScryptParameters with no salt. Your encryption may be vulnerable to a dictionary attack.");
}
final Stopwatch watch = Stopwatch.createStarted();
byte[] keyBytes = SCrypt.scrypt(passwordBytes, salt, (int) scryptParameters.getN(), scryptParameters.getR(), scryptParameters.getP(), KEY_LENGTH);
watch.stop();
log.info("Deriving key took {} for {} scrypt iterations.", watch, scryptParameters.getN());
return new KeyParameter(keyBytes);
} catch (Exception e) {
throw new KeyCrypterException("Could not generate key from password and salt.", e);