3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-13 02:35:52 +00:00

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 d876ea9d34
commit 9c9e3a9744

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