* Crypto: Don't use "short exponent" on faster platforms.

Rebuild router identity if key length doesn't match setting.
   This affects RI and LS encryption keys, and DH and YK.
   Faster = 64 bit with working jbigi, non-ARM, non-GNU (for now)
   Override default with crypto.elGamal.useLongKey=true/false
   LS key is built at client startup (Dest key unused)
   This will churn most of the RIs at the release.
 * SystemVersion: Add isARM()
This commit is contained in:
zzz
2013-09-07 13:43:28 +00:00
parent f4039b085a
commit 78a426e9ac
8 changed files with 84 additions and 9 deletions

View File

@@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 23;
public final static long BUILD = 24;
/** for example "-test" */
public final static String EXTRA = "";

View File

@@ -14,6 +14,7 @@ import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import net.i2p.crypto.KeyGenerator;
import net.i2p.data.DataFormatException;
import net.i2p.data.PrivateKey;
import net.i2p.data.PublicKey;
@@ -91,6 +92,14 @@ public class LoadRouterInfoJob extends JobImpl {
fis2 = new BufferedInputStream(new FileInputStream(rkf));
PrivateKey privkey = new PrivateKey();
privkey.readBytes(fis2);
if (shouldRebuild(privkey)) {
_us = null;
rif.delete();
rkf.delete();
_infoExists = false;
_keysExist = false;
return;
}
SigningPrivateKey signingPrivKey = new SigningPrivateKey();
signingPrivKey.readBytes(fis2);
PublicKey pubkey = new PublicKey();
@@ -119,4 +128,29 @@ public class LoadRouterInfoJob extends JobImpl {
if (fis2 != null) try { fis2.close(); } catch (IOException ioe) {}
}
}
/**
* Does our RI private key length match the configuration?
* If not, return true.
* @since 0.9.8
*/
private boolean shouldRebuild(PrivateKey privkey) {
byte[] pkd = privkey.getData();
boolean haslong = false;
for (int i = 0; i < 8; i++) {
if (pkd[i] != 0) {
haslong = true;
break;
}
}
boolean uselong = getContext().keyGenerator().useLongElGamalExponent();
// transition to a longer key (update to 0.9.8)
if (uselong && !haslong)
_log.logAlways(Log.WARN, "Rebuilding RouterInfo with longer key");
// transition to a shorter key, should be rare (copy files to different hardware,
// jbigi broke, user overrides in advanced config, ...)
if (!uselong && haslong)
_log.logAlways(Log.WARN, "Rebuilding RouterInfo with faster key");
return uselong != haslong;
}
}

View File

@@ -71,7 +71,7 @@ public class DHSessionKeyBuilder {
* Others should get instances from PrecalcRunner.getBuilder()
*/
DHSessionKeyBuilder() {
this(RandomSource.getInstance());
this(I2PAppContext.getGlobalContext());
}
/**
@@ -79,8 +79,8 @@ public class DHSessionKeyBuilder {
* Only for internal use and unit tests.
* Others should get instances from PrecalcRunner.getBuilder()
*/
DHSessionKeyBuilder(RandomSource random) {
_myPrivateValue = new NativeBigInteger(KeyGenerator.PUBKEY_EXPONENT_SIZE, random);
DHSessionKeyBuilder(I2PAppContext ctx) {
_myPrivateValue = new NativeBigInteger(ctx.keyGenerator().getElGamalExponentSize(), ctx.random());
_myPublicValue = CryptoConstants.elgg.modPow(_myPrivateValue, CryptoConstants.elgp);
_extraExchangedBytes = new ByteArray();
}
@@ -547,7 +547,7 @@ public class DHSessionKeyBuilder {
private DHSessionKeyBuilder precalc() {
long start = System.currentTimeMillis();
DHSessionKeyBuilder builder = new DHSessionKeyBuilder(_context.random());
DHSessionKeyBuilder builder = new DHSessionKeyBuilder(_context);
long end = System.currentTimeMillis();
long diff = end - start;
_context.statManager().addRateData("crypto.dhGeneratePublicTime", diff, diff);