mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 00:02:27 -08:00
Get rounds from KdfParameters
This commit is contained in:
1 parent
1e4deb2182
commit
b3ff38fb35
11 files changed
+31
-14
No files matched your search
@@ -24,7 +24,6 @@ import com.keepassdroid.stream.LEDataOutputStream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -33,7 +32,7 @@ public class VariantDictionary {
|
||||
private static final int VdmCritical = 0xFF00;
|
||||
private static final int VdmInfo = 0x00FF;
|
||||
|
||||
private Map<String, VdType> dict = new HashMap<String, VdType>();
|
||||
private Map<String, VdType> dict = new HashMap<>();
|
||||
|
||||
private class VdType {
|
||||
public static final byte None = 0x00;
|
||||
|
||||
@@ -22,7 +22,6 @@ package com.keepassdroid.crypto.keyDerivation;
|
||||
import com.keepassdroid.crypto.CryptoUtil;
|
||||
import com.keepassdroid.crypto.finalkey.FinalKey;
|
||||
import com.keepassdroid.crypto.finalkey.FinalKeyFactory;
|
||||
import com.keepassdroid.database.PwDatabaseV4;
|
||||
import com.keepassdroid.utils.Types;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -30,6 +29,10 @@ import java.security.SecureRandom;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AesKdf extends KdfEngine {
|
||||
|
||||
public static final int DEFAULT_ROUNDS = 6000;
|
||||
public static final String DEFAULT_NAME = "AES-KDF";
|
||||
|
||||
public static final UUID CIPHER_UUID = Types.bytestoUUID(
|
||||
new byte[]{(byte) 0xC9, (byte) 0xD9, (byte) 0xF3, (byte) 0x9A, (byte) 0x62, (byte) 0x8A, (byte) 0x44, (byte) 0x60,
|
||||
(byte) 0xBF, (byte) 0x74, (byte) 0x0D, (byte) 0x08, (byte)0xC1, (byte) 0x8A, (byte) 0x4F, (byte) 0xEA
|
||||
@@ -43,13 +46,13 @@ public class AesKdf extends KdfEngine {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "AES-KDF";
|
||||
return DEFAULT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KdfParameters getDefaultParameters() {
|
||||
KdfParameters p = super.getDefaultParameters();
|
||||
p.setUInt32(ParamRounds, PwDatabaseV4.DEFAULT_ROUNDS);
|
||||
p.setUInt32(ParamRounds, DEFAULT_ROUNDS);
|
||||
|
||||
return p;
|
||||
}
|
||||
@@ -80,4 +83,9 @@ public class AesKdf extends KdfEngine {
|
||||
|
||||
p.setByteArray(ParamSeed, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getKeyRounds(KdfParameters p) {
|
||||
return p.getUInt64(ParamRounds);
|
||||
}
|
||||
}
|
||||
@@ -102,4 +102,9 @@ public class Argon2Kdf extends KdfEngine {
|
||||
|
||||
p.setByteArray(ParamSalt, salt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getKeyRounds(KdfParameters p) {
|
||||
return p.getUInt64(ParamIterations);
|
||||
}
|
||||
}
|
||||
@@ -35,4 +35,6 @@ public abstract class KdfEngine {
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract long getKeyRounds(KdfParameters p);
|
||||
|
||||
}
|
||||
@@ -46,6 +46,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
package com.keepassdroid.database;
|
||||
|
||||
// Java
|
||||
import com.keepassdroid.crypto.keyDerivation.AesKdf;
|
||||
import com.keepassdroid.database.exception.InvalidKeyFileException;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -97,7 +98,7 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
|
||||
|
||||
@Override
|
||||
public String getKeyDerivationName() {
|
||||
return "AES";
|
||||
return AesKdf.DEFAULT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -58,7 +58,6 @@ import biz.source_code.base64Coder.Base64Coder;
|
||||
|
||||
public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
||||
|
||||
public static final int DEFAULT_ROUNDS = 6000;
|
||||
private static final int DEFAULT_HISTORY_MAX_ITEMS = 10; // -1 unlimited
|
||||
private static final long DEFAULT_HISTORY_MAX_SIZE = 6 * 1024 * 1024; // -1 unlimited
|
||||
private static final String RECYCLEBIN_NAME = "RecycleBin";
|
||||
@@ -70,7 +69,7 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
||||
private KdfEngine kdfEngine;
|
||||
|
||||
// TODO: Refactor me away to get directly from kdfParameters
|
||||
private long numKeyEncRounds = DEFAULT_ROUNDS;
|
||||
private long numKeyEncRounds = AesKdf.DEFAULT_ROUNDS; // By default take the AES rounds
|
||||
private PwDate nameChanged = new PwDate();
|
||||
private PwDate settingsChanged = new PwDate();
|
||||
private String description = "";
|
||||
@@ -137,11 +136,14 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
||||
|
||||
@Override
|
||||
public long getNumberKeyEncryptionRounds() {
|
||||
if (getKdfEngine() != null && getKdfParameters() != null)
|
||||
numKeyEncRounds = getKdfEngine().getKeyRounds(getKdfParameters());
|
||||
return numKeyEncRounds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNumberKeyEncryptionRounds(long rounds) throws NumberFormatException {
|
||||
// TODO set kdfParameter
|
||||
numKeyEncRounds = rounds;
|
||||
}
|
||||
|
||||
|
||||
@@ -283,7 +283,7 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
|
||||
.getKeyDerivationName());
|
||||
|
||||
// Round encryption
|
||||
Preference roundPref = findPreference(getString(R.string.rounds_key));
|
||||
Preference roundPref = findPreference(getString(R.string.transform_rounds_key));
|
||||
roundPref.setSummary(Long.toString(pwDatabase.getNumberKeyEncryptionRounds()));
|
||||
roundPref.setEnabled(false); //TODO refactor round pref
|
||||
roundPref.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
|
||||
Reference in new issue
Block a user