From a7b04fce1942060d833b769f13ac21ae2a590393 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Fri, 1 May 2015 10:29:13 -0700 Subject: Upgrade to Curve25519 0.2.4 --- .../org/whispersystems/libaxolotl/CurveTest.java | 20 ++++++++--------- build.gradle | 2 +- .../org/whispersystems/libaxolotl/CurveTest.java | 20 ++++++++--------- .../libaxolotl/groups/GroupCipherTest.java | 25 ++++++++++++++++++++++ 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/android/src/androidTest/java/org/whispersystems/libaxolotl/CurveTest.java b/android/src/androidTest/java/org/whispersystems/libaxolotl/CurveTest.java index bb539d49..baaea356 100644 --- a/android/src/androidTest/java/org/whispersystems/libaxolotl/CurveTest.java +++ b/android/src/androidTest/java/org/whispersystems/libaxolotl/CurveTest.java @@ -11,16 +11,16 @@ public class CurveTest extends TestCase { assertTrue(Curve.isNative()); } - public void testSignatureOverflow() throws InvalidKeyException { - ECKeyPair keys = Curve.generateKeyPair(); - byte[] message = new byte[4096]; - - try { - byte[] signature = Curve.calculateSignature(keys.getPrivateKey(), message); - throw new InvalidKeyException("Should have asserted!"); - } catch (AssertionError e) { - // Success! - } + public void testLargeSignatures() throws InvalidKeyException { + ECKeyPair keys = Curve.generateKeyPair(); + byte[] message = new byte[1024 * 1024]; + byte[] signature = Curve.calculateSignature(keys.getPrivateKey(), message); + + assertTrue(Curve.verifySignature(keys.getPublicKey(), message, signature)); + + message[0] ^= 0x01; + + assertFalse(Curve.verifySignature(keys.getPublicKey(), message, signature)); } } diff --git a/build.gradle b/build.gradle index 6f990f9c..8be77082 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ subprojects { ext.version_number = "1.3.3" ext.group_info = "org.whispersystems" - ext.curve25519_version = "0.2.2" + ext.curve25519_version = "0.2.4" if (JavaVersion.current().isJava8Compatible()) { allprojects { diff --git a/java/src/test/java/org/whispersystems/libaxolotl/CurveTest.java b/java/src/test/java/org/whispersystems/libaxolotl/CurveTest.java index 734f6c86..24c62132 100644 --- a/java/src/test/java/org/whispersystems/libaxolotl/CurveTest.java +++ b/java/src/test/java/org/whispersystems/libaxolotl/CurveTest.java @@ -11,16 +11,16 @@ public class CurveTest extends TestCase { assertFalse(Curve.isNative()); } - public void testSignatureOverflow() throws InvalidKeyException { - ECKeyPair keys = Curve.generateKeyPair(); - byte[] message = new byte[4096]; - - try { - byte[] signature = Curve.calculateSignature(keys.getPrivateKey(), message); - throw new InvalidKeyException("Should have asserted!"); - } catch (IllegalArgumentException e) { - // Success! - } + public void testLargeSignatures() throws InvalidKeyException { + ECKeyPair keys = Curve.generateKeyPair(); + byte[] message = new byte[1024 * 1024]; + byte[] signature = Curve.calculateSignature(keys.getPrivateKey(), message); + + assertTrue(Curve.verifySignature(keys.getPublicKey(), message, signature)); + + message[0] ^= 0x01; + + assertFalse(Curve.verifySignature(keys.getPublicKey(), message, signature)); } } diff --git a/tests/src/test/java/org/whispersystems/libaxolotl/groups/GroupCipherTest.java b/tests/src/test/java/org/whispersystems/libaxolotl/groups/GroupCipherTest.java index aad8b083..23d26cab 100644 --- a/tests/src/test/java/org/whispersystems/libaxolotl/groups/GroupCipherTest.java +++ b/tests/src/test/java/org/whispersystems/libaxolotl/groups/GroupCipherTest.java @@ -12,6 +12,8 @@ import org.whispersystems.libaxolotl.protocol.SenderKeyDistributionMessage; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Random; public class GroupCipherTest extends TestCase { @@ -64,6 +66,29 @@ public class GroupCipherTest extends TestCase { assertTrue(new String(plaintextFromAlice).equals("smert ze smert")); } + public void testLargeMessages() throws InvalidMessageException, LegacyMessageException, NoSessionException, DuplicateMessageException { + InMemorySenderKeyStore aliceStore = new InMemorySenderKeyStore(); + InMemorySenderKeyStore bobStore = new InMemorySenderKeyStore(); + + GroupSessionBuilder aliceSessionBuilder = new GroupSessionBuilder(aliceStore); + GroupSessionBuilder bobSessionBuilder = new GroupSessionBuilder(bobStore); + + GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, GROUP_SENDER); + GroupCipher bobGroupCipher = new GroupCipher(bobStore, GROUP_SENDER); + + SenderKeyDistributionMessage sentAliceDistributionMessage = aliceSessionBuilder.create(GROUP_SENDER); + SenderKeyDistributionMessage receivedAliceDistributionMessage = new SenderKeyDistributionMessage(sentAliceDistributionMessage.serialize()); + bobSessionBuilder.process(GROUP_SENDER, receivedAliceDistributionMessage); + + byte[] plaintext = new byte[1024 * 1024]; + new Random().nextBytes(plaintext); + + byte[] ciphertextFromAlice = aliceGroupCipher.encrypt(plaintext); + byte[] plaintextFromAlice = bobGroupCipher.decrypt(ciphertextFromAlice); + + assertTrue(Arrays.equals(plaintext, plaintextFromAlice)); + } + public void testBasicRatchet() throws LegacyMessageException, DuplicateMessageException, InvalidMessageException, NoSessionException { -- cgit v1.2.3