diff options
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/main/java/org/whispersystems/libaxolotl/ecc/Curve.java | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/java/src/main/java/org/whispersystems/libaxolotl/ecc/Curve.java b/java/src/main/java/org/whispersystems/libaxolotl/ecc/Curve.java index 5d47e3aa..9f2c202a 100644 --- a/java/src/main/java/org/whispersystems/libaxolotl/ecc/Curve.java +++ b/java/src/main/java/org/whispersystems/libaxolotl/ecc/Curve.java @@ -16,24 +16,23 @@ */ package org.whispersystems.libaxolotl.ecc; +import org.whispersystems.curve25519.Curve25519; import org.whispersystems.curve25519.Curve25519KeyPair; +import org.whispersystems.curve25519.NoSuchProviderException; import org.whispersystems.libaxolotl.InvalidKeyException; -import org.whispersystems.curve25519.Curve25519; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; +import static org.whispersystems.curve25519.Curve25519.BEST; public class Curve { public static final int DJB_TYPE = 0x05; public static boolean isNative() { - return Curve25519.isNative(); + return Curve25519.getInstance(BEST).isNative(); } public static ECKeyPair generateKeyPair() { - SecureRandom secureRandom = getSecureRandom(); - Curve25519KeyPair keyPair = Curve25519.generateKeyPair(secureRandom); + Curve25519KeyPair keyPair = Curve25519.getInstance(BEST).generateKeyPair(); return new ECKeyPair(new DjbECPublicKey(keyPair.getPublicKey()), new DjbECPrivateKey(keyPair.getPrivateKey())); @@ -66,8 +65,9 @@ public class Curve { } if (publicKey.getType() == DJB_TYPE) { - return Curve25519.calculateAgreement(((DjbECPublicKey)publicKey).getPublicKey(), - ((DjbECPrivateKey)privateKey).getPrivateKey()); + return Curve25519.getInstance(BEST) + .calculateAgreement(((DjbECPublicKey) publicKey).getPublicKey(), + ((DjbECPrivateKey) privateKey).getPrivateKey()); } else { throw new InvalidKeyException("Unknown type: " + publicKey.getType()); } @@ -77,7 +77,8 @@ public class Curve { throws InvalidKeyException { if (signingKey.getType() == DJB_TYPE) { - return Curve25519.verifySignature(((DjbECPublicKey)signingKey).getPublicKey(), message, signature); + return Curve25519.getInstance(BEST) + .verifySignature(((DjbECPublicKey) signingKey).getPublicKey(), message, signature); } else { throw new InvalidKeyException("Unknown type: " + signingKey.getType()); } @@ -87,17 +88,10 @@ public class Curve { throws InvalidKeyException { if (signingKey.getType() == DJB_TYPE) { - return Curve25519.calculateSignature(getSecureRandom(), ((DjbECPrivateKey)signingKey).getPrivateKey(), message); + return Curve25519.getInstance(BEST) + .calculateSignature(((DjbECPrivateKey) signingKey).getPrivateKey(), message); } else { throw new InvalidKeyException("Unknown type: " + signingKey.getType()); } } - - private static SecureRandom getSecureRandom() { - try { - return SecureRandom.getInstance("SHA1PRNG"); - } catch (NoSuchAlgorithmException e) { - throw new AssertionError(e); - } - } } |