diff --git a/briar-core/src/org/briarproject/crypto/CryptoComponentImpl.java b/briar-core/src/org/briarproject/crypto/CryptoComponentImpl.java index 825c3720f5188500ec89aa7a83fb70096b14270a..bdf74dfaa881a6143b06a434ac9c6dcd173dc297 100644 --- a/briar-core/src/org/briarproject/crypto/CryptoComponentImpl.java +++ b/briar-core/src/org/briarproject/crypto/CryptoComponentImpl.java @@ -164,8 +164,8 @@ class CryptoComponentImpl implements CryptoComponent { // Return a wrapper that uses the SEC 1 encoding ECPublicKeyParameters ecPublicKey = (ECPublicKeyParameters) keyPair.getPublic(); - PublicKey publicKey = new Sec1PublicKey(ecPublicKey, - AGREEMENT_KEY_PAIR_BITS); + PublicKey publicKey = new Sec1PublicKey(ecPublicKey + ); ECPrivateKeyParameters ecPrivateKey = (ECPrivateKeyParameters) keyPair.getPrivate(); PrivateKey privateKey = new Sec1PrivateKey(ecPrivateKey, @@ -183,8 +183,8 @@ class CryptoComponentImpl implements CryptoComponent { // Return a wrapper that uses the SEC 1 encoding ECPublicKeyParameters ecPublicKey = (ECPublicKeyParameters) keyPair.getPublic(); - PublicKey publicKey = new Sec1PublicKey(ecPublicKey, - SIGNATURE_KEY_PAIR_BITS); + PublicKey publicKey = new Sec1PublicKey(ecPublicKey + ); ECPrivateKeyParameters ecPrivateKey = (ECPrivateKeyParameters) keyPair.getPrivate(); PrivateKey privateKey = new Sec1PrivateKey(ecPrivateKey, diff --git a/briar-core/src/org/briarproject/crypto/Sec1KeyParser.java b/briar-core/src/org/briarproject/crypto/Sec1KeyParser.java index 99b3d2e727ddf64c598cdf37ebde4304340e44d5..a3bc7c71ee3c93b6c6d7cb3fdf54ae0748117b19 100644 --- a/briar-core/src/org/briarproject/crypto/Sec1KeyParser.java +++ b/briar-core/src/org/briarproject/crypto/Sec1KeyParser.java @@ -1,11 +1,5 @@ package org.briarproject.crypto; -import static java.util.logging.Level.INFO; - -import java.math.BigInteger; -import java.security.GeneralSecurityException; -import java.util.logging.Logger; - import org.briarproject.api.crypto.KeyParser; import org.briarproject.api.crypto.PrivateKey; import org.briarproject.api.crypto.PublicKey; @@ -15,6 +9,12 @@ import org.spongycastle.crypto.params.ECPublicKeyParameters; import org.spongycastle.math.ec.ECCurve; import org.spongycastle.math.ec.ECPoint; +import java.math.BigInteger; +import java.security.GeneralSecurityException; +import java.util.logging.Logger; + +import static java.util.logging.Level.INFO; + /** * A key parser that uses the encoding defined in "SEC 1: Elliptic Curve * Cryptography", section 2.3 (Certicom Corporation, May 2009). Point @@ -73,7 +73,7 @@ class Sec1KeyParser implements KeyParser { throw new GeneralSecurityException(); // Construct a public key from the point (x, y) and the params ECPublicKeyParameters k = new ECPublicKeyParameters(pub, params); - PublicKey p = new Sec1PublicKey(k, keyBits); + PublicKey p = new Sec1PublicKey(k); long duration = System.currentTimeMillis() - now; if (LOG.isLoggable(INFO)) LOG.info("Parsing public key took " + duration + " ms"); diff --git a/briar-core/src/org/briarproject/crypto/Sec1PublicKey.java b/briar-core/src/org/briarproject/crypto/Sec1PublicKey.java index 95523c79b85a77c5b594ca519243368898a85a09..f85a34b8d7255e7cb31e3a7ce319986e0e52178f 100644 --- a/briar-core/src/org/briarproject/crypto/Sec1PublicKey.java +++ b/briar-core/src/org/briarproject/crypto/Sec1PublicKey.java @@ -2,7 +2,6 @@ package org.briarproject.crypto; import org.briarproject.api.crypto.PublicKey; import org.spongycastle.crypto.params.ECPublicKeyParameters; -import org.spongycastle.math.ec.ECPoint; /** * An elliptic curve public key that uses the encoding defined in "SEC 1: @@ -12,24 +11,13 @@ import org.spongycastle.math.ec.ECPoint; class Sec1PublicKey implements PublicKey { private final ECPublicKeyParameters key; - private final int bytesPerInt, publicKeyBytes; - Sec1PublicKey(ECPublicKeyParameters key, int keyBits) { + Sec1PublicKey(ECPublicKeyParameters key) { this.key = key; - bytesPerInt = (keyBits + 7) / 8; - publicKeyBytes = 1 + 2 * bytesPerInt; } public byte[] getEncoded() { - byte[] encodedKey = new byte[publicKeyBytes]; - encodedKey[0] = 4; - ECPoint pub = key.getQ().normalize(); - byte[] x = pub.getAffineXCoord().toBigInteger().toByteArray(); - Sec1Utils.convertToFixedLength(x, encodedKey, 1, bytesPerInt); - byte[] y = pub.getAffineYCoord().toBigInteger().toByteArray(); - Sec1Utils.convertToFixedLength(y, encodedKey, 1 + bytesPerInt, - bytesPerInt); - return encodedKey; + return key.getQ().getEncoded(false); } ECPublicKeyParameters getKey() {