I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit c48266fd authored by zzz's avatar zzz
Browse files

* Transports: Use SigUtil.rectify() in DH

parent 895d54d3
No related branches found
No related tags found
No related merge requests found
...@@ -43,9 +43,9 @@ import net.i2p.util.NativeBigInteger; ...@@ -43,9 +43,9 @@ import net.i2p.util.NativeBigInteger;
/** /**
* Utilities for Signing keys and Signatures * Utilities for Signing keys and Signatures
* *
* @since 0.9.9 * @since 0.9.9, public since 0.9.12
*/ */
class SigUtil { public class SigUtil {
private static final Map<SigningPublicKey, ECPublicKey> _pubkeyCache = new LHMCache<SigningPublicKey, ECPublicKey>(64); private static final Map<SigningPublicKey, ECPublicKey> _pubkeyCache = new LHMCache<SigningPublicKey, ECPublicKey>(64);
private static final Map<SigningPrivateKey, ECPrivateKey> _privkeyCache = new LHMCache<SigningPrivateKey, ECPrivateKey>(16); private static final Map<SigningPrivateKey, ECPrivateKey> _privkeyCache = new LHMCache<SigningPrivateKey, ECPrivateKey>(16);
......
...@@ -12,12 +12,14 @@ package net.i2p.router.transport.crypto; ...@@ -12,12 +12,14 @@ package net.i2p.router.transport.crypto;
//import java.io.InputStream; //import java.io.InputStream;
//import java.io.OutputStream; //import java.io.OutputStream;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
import net.i2p.I2PException; import net.i2p.I2PException;
import net.i2p.crypto.CryptoConstants; import net.i2p.crypto.CryptoConstants;
import net.i2p.crypto.SHA256Generator; import net.i2p.crypto.SHA256Generator;
import net.i2p.crypto.SigUtil;
import net.i2p.data.ByteArray; import net.i2p.data.ByteArray;
//import net.i2p.data.DataHelper; //import net.i2p.data.DataHelper;
import net.i2p.data.SessionKey; import net.i2p.data.SessionKey;
...@@ -183,16 +185,16 @@ public class DHSessionKeyBuilder { ...@@ -183,16 +185,16 @@ public class DHSessionKeyBuilder {
return toByteArray(getMyPublicValue()); return toByteArray(getMyPublicValue());
} }
/**
* @return exactly 256 bytes
* @throws IllegalArgumentException if requires more than 256 bytes
*/
private static final byte[] toByteArray(BigInteger bi) { private static final byte[] toByteArray(BigInteger bi) {
byte data[] = bi.toByteArray(); try {
byte rv[] = new byte[256]; return SigUtil.rectify(bi, 256);
if (data.length == 257) // high byte has the sign bit } catch (InvalidKeyException ike) {
System.arraycopy(data, 1, rv, 0, rv.length); throw new IllegalArgumentException(ike);
else if (data.length == 256) }
System.arraycopy(data, 0, rv, 0, rv.length);
else
System.arraycopy(data, 0, rv, rv.length-data.length, data.length);
return rv;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment