From a7b04fce1942060d833b769f13ac21ae2a590393 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Fri, 1 May 2015 10:29:13 -0700 Subject: [PATCH] Upgrade to Curve25519 0.2.4 --- .../whispersystems/libaxolotl/CurveTest.java | 18 ++++++------- build.gradle | 2 +- .../whispersystems/libaxolotl/CurveTest.java | 18 ++++++------- .../libaxolotl/groups/GroupCipherTest.java | 25 +++++++++++++++++++ 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/android/src/androidTest/java/org/whispersystems/libaxolotl/CurveTest.java b/android/src/androidTest/java/org/whispersystems/libaxolotl/CurveTest.java index bb539d490..baaea3560 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]; + public void testLargeSignatures() throws InvalidKeyException { + ECKeyPair keys = Curve.generateKeyPair(); + byte[] message = new byte[1024 * 1024]; + byte[] signature = Curve.calculateSignature(keys.getPrivateKey(), message); - try { - byte[] signature = Curve.calculateSignature(keys.getPrivateKey(), message); - throw new InvalidKeyException("Should have asserted!"); - } catch (AssertionError e) { - // Success! - } + 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 6f990f9ce..8be770822 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 734f6c860..24c621326 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]; + public void testLargeSignatures() throws InvalidKeyException { + ECKeyPair keys = Curve.generateKeyPair(); + byte[] message = new byte[1024 * 1024]; + byte[] signature = Curve.calculateSignature(keys.getPrivateKey(), message); - try { - byte[] signature = Curve.calculateSignature(keys.getPrivateKey(), message); - throw new InvalidKeyException("Should have asserted!"); - } catch (IllegalArgumentException e) { - // Success! - } + 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 aad8b0836..23d26cabc 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 {