diff --git a/libaxolotl/jni/curve25519-donna.c b/libaxolotl/jni/curve25519-donna.c index f2c2ac58e6..77876e3984 100644 --- a/libaxolotl/jni/curve25519-donna.c +++ b/libaxolotl/jni/curve25519-donna.c @@ -857,9 +857,9 @@ curve25519_donna(u8 *mypublic, const u8 *secret, const u8 *basepoint) { int i; for (i = 0; i < 32; ++i) e[i] = secret[i]; -// e[0] &= 248; -// e[31] &= 127; -// e[31] |= 64; + e[0] &= 248; + e[31] &= 127; + e[31] |= 64; fexpand(bp, basepoint); cmult(x, z, e, bp); diff --git a/libaxolotl/jni/curve25519-jni.c b/libaxolotl/jni/curve25519-jni.c index 5b4cc2f432..46838b82ce 100644 --- a/libaxolotl/jni/curve25519-jni.c +++ b/libaxolotl/jni/curve25519-jni.c @@ -23,16 +23,11 @@ #include "curve_sigs.h" JNIEXPORT jbyteArray JNICALL Java_org_whispersystems_libaxolotl_ecc_Curve25519_generatePrivateKey - (JNIEnv *env, jclass clazz, jbyteArray random, jboolean ephemeral) + (JNIEnv *env, jclass clazz, jbyteArray random) { uint8_t* privateKey = (uint8_t*)(*env)->GetByteArrayElements(env, random, 0); privateKey[0] &= 248; - - if (ephemeral) { - privateKey[0] |= 1; - } - privateKey[31] &= 127; privateKey[31] |= 64; diff --git a/libaxolotl/libs/armeabi-v7a/libcurve25519.so b/libaxolotl/libs/armeabi-v7a/libcurve25519.so index 1dd438f09c..bd318cbf6a 100755 Binary files a/libaxolotl/libs/armeabi-v7a/libcurve25519.so and b/libaxolotl/libs/armeabi-v7a/libcurve25519.so differ diff --git a/libaxolotl/libs/armeabi/libcurve25519.so b/libaxolotl/libs/armeabi/libcurve25519.so index 714f898191..dfd6de8d15 100755 Binary files a/libaxolotl/libs/armeabi/libcurve25519.so and b/libaxolotl/libs/armeabi/libcurve25519.so differ diff --git a/libaxolotl/libs/x86/libcurve25519.so b/libaxolotl/libs/x86/libcurve25519.so index 1bff1ccf1e..e72eaad4a4 100755 Binary files a/libaxolotl/libs/x86/libcurve25519.so and b/libaxolotl/libs/x86/libcurve25519.so differ diff --git a/libaxolotl/src/androidTest/java/org/whispersystems/test/InMemoryIdentityKeyStore.java b/libaxolotl/src/androidTest/java/org/whispersystems/test/InMemoryIdentityKeyStore.java index e510a26d1b..8a2e1d8f34 100644 --- a/libaxolotl/src/androidTest/java/org/whispersystems/test/InMemoryIdentityKeyStore.java +++ b/libaxolotl/src/androidTest/java/org/whispersystems/test/InMemoryIdentityKeyStore.java @@ -20,7 +20,7 @@ public class InMemoryIdentityKeyStore implements IdentityKeyStore { public InMemoryIdentityKeyStore() { try { - ECKeyPair identityKeyPairKeys = Curve.generateKeyPair(false); + ECKeyPair identityKeyPairKeys = Curve.generateKeyPair(); this.identityKeyPair = new IdentityKeyPair(new IdentityKey(identityKeyPairKeys.getPublicKey()), identityKeyPairKeys.getPrivateKey()); diff --git a/libaxolotl/src/androidTest/java/org/whispersystems/test/SessionBuilderTest.java b/libaxolotl/src/androidTest/java/org/whispersystems/test/SessionBuilderTest.java index 44434d7384..1d410784dc 100644 --- a/libaxolotl/src/androidTest/java/org/whispersystems/test/SessionBuilderTest.java +++ b/libaxolotl/src/androidTest/java/org/whispersystems/test/SessionBuilderTest.java @@ -52,7 +52,7 @@ public class SessionBuilderTest extends AndroidTestCase { SignedPreKeyStore bobSignedPreKeyStore = new InMemorySignedPreKeyStore(); IdentityKeyStore bobIdentityKeyStore = new InMemoryIdentityKeyStore(); - ECKeyPair bobPreKeyPair = Curve.generateKeyPair(true); + ECKeyPair bobPreKeyPair = Curve.generateKeyPair(); PreKeyBundle bobPreKey = new PreKeyBundle(bobIdentityKeyStore.getLocalRegistrationId(), 1, 31337, bobPreKeyPair.getPublicKey(), 0, null, null, @@ -97,7 +97,7 @@ public class SessionBuilderTest extends AndroidTestCase { BOB_RECIPIENT_ID, 1); aliceSessionCipher = new SessionCipher(aliceSessionStore, alicePreKeyStore, aliceSignedPreKeyStore, aliceIdentityKeyStore, BOB_RECIPIENT_ID, 1); - bobPreKeyPair = Curve.generateKeyPair(true); + bobPreKeyPair = Curve.generateKeyPair(); bobPreKey = new PreKeyBundle(bobIdentityKeyStore.getLocalRegistrationId(), 1, 31338, bobPreKeyPair.getPublicKey(), 0, null, null, bobIdentityKeyStore.getIdentityKeyPair().getPublicKey()); @@ -119,7 +119,7 @@ public class SessionBuilderTest extends AndroidTestCase { assertTrue(new String(plaintext).equals(originalMessage)); bobPreKey = new PreKeyBundle(bobIdentityKeyStore.getLocalRegistrationId(), 1, - 31337, Curve.generateKeyPair(true).getPublicKey(), + 31337, Curve.generateKeyPair().getPublicKey(), 0, null, null, aliceIdentityKeyStore.getIdentityKeyPair().getPublicKey()); @@ -147,8 +147,8 @@ public class SessionBuilderTest extends AndroidTestCase { SignedPreKeyStore bobSignedPreKeyStore = new InMemorySignedPreKeyStore(); IdentityKeyStore bobIdentityKeyStore = new InMemoryIdentityKeyStore(); - ECKeyPair bobPreKeyPair = Curve.generateKeyPair(true); - ECKeyPair bobSignedPreKeyPair = Curve.generateKeyPair(true); + ECKeyPair bobPreKeyPair = Curve.generateKeyPair(); + ECKeyPair bobSignedPreKeyPair = Curve.generateKeyPair(); byte[] bobSignedPreKeySignature = Curve.calculateSignature(bobIdentityKeyStore.getIdentityKeyPair().getPrivateKey(), bobSignedPreKeyPair.getPublicKey().serialize()); @@ -200,8 +200,8 @@ public class SessionBuilderTest extends AndroidTestCase { BOB_RECIPIENT_ID, 1); aliceSessionCipher = new SessionCipher(aliceSessionStore, alicePreKeyStore, aliceSignedPreKeyStore, aliceIdentityKeyStore, BOB_RECIPIENT_ID, 1); - bobPreKeyPair = Curve.generateKeyPair(true); - bobSignedPreKeyPair = Curve.generateKeyPair(true); + bobPreKeyPair = Curve.generateKeyPair(); + bobSignedPreKeyPair = Curve.generateKeyPair(); bobSignedPreKeySignature = Curve.calculateSignature(bobIdentityKeyStore.getIdentityKeyPair().getPrivateKey(), bobSignedPreKeyPair.getPublicKey().serialize()); bobPreKey = new PreKeyBundle(bobIdentityKeyStore.getLocalRegistrationId(), 1, 31338, bobPreKeyPair.getPublicKey(), @@ -225,7 +225,7 @@ public class SessionBuilderTest extends AndroidTestCase { assertTrue(new String(plaintext).equals(originalMessage)); bobPreKey = new PreKeyBundle(bobIdentityKeyStore.getLocalRegistrationId(), 1, - 31337, Curve.generateKeyPair(true).getPublicKey(), + 31337, Curve.generateKeyPair().getPublicKey(), 23, bobSignedPreKeyPair.getPublicKey(), bobSignedPreKeySignature, aliceIdentityKeyStore.getIdentityKeyPair().getPublicKey()); @@ -249,8 +249,8 @@ public class SessionBuilderTest extends AndroidTestCase { IdentityKeyStore bobIdentityKeyStore = new InMemoryIdentityKeyStore(); - ECKeyPair bobPreKeyPair = Curve.generateKeyPair(true); - ECKeyPair bobSignedPreKeyPair = Curve.generateKeyPair(true); + ECKeyPair bobPreKeyPair = Curve.generateKeyPair(); + ECKeyPair bobSignedPreKeyPair = Curve.generateKeyPair(); byte[] bobSignedPreKeySignature = Curve.calculateSignature(bobIdentityKeyStore.getIdentityKeyPair().getPrivateKey(), bobSignedPreKeyPair.getPublicKey().serialize()); @@ -297,8 +297,8 @@ public class SessionBuilderTest extends AndroidTestCase { SignedPreKeyStore bobSignedPreKeyStore = new InMemorySignedPreKeyStore(); IdentityKeyStore bobIdentityKeyStore = new InMemoryIdentityKeyStore(); - ECKeyPair bobPreKeyPair = Curve.generateKeyPair(true); - ECKeyPair bobSignedPreKeyPair = Curve.generateKeyPair(true); + ECKeyPair bobPreKeyPair = Curve.generateKeyPair(); + ECKeyPair bobSignedPreKeyPair = Curve.generateKeyPair(); byte[] bobSignedPreKeySignature = Curve.calculateSignature(bobIdentityKeyStore.getIdentityKeyPair().getPrivateKey(), bobSignedPreKeyPair.getPublicKey().serialize()); @@ -359,8 +359,8 @@ public class SessionBuilderTest extends AndroidTestCase { SignedPreKeyStore bobSignedPreKeyStore = new InMemorySignedPreKeyStore(); IdentityKeyStore bobIdentityKeyStore = new InMemoryIdentityKeyStore(); - ECKeyPair bobPreKeyPair = Curve.generateKeyPair(true); - ECKeyPair bobSignedPreKeyPair = Curve.generateKeyPair(true); + ECKeyPair bobPreKeyPair = Curve.generateKeyPair(); + ECKeyPair bobSignedPreKeyPair = Curve.generateKeyPair(); byte[] bobSignedPreKeySignature = Curve.calculateSignature(bobIdentityKeyStore.getIdentityKeyPair().getPrivateKey(), bobSignedPreKeyPair.getPublicKey().serialize()); diff --git a/libaxolotl/src/androidTest/java/org/whispersystems/test/SessionCipherTest.java b/libaxolotl/src/androidTest/java/org/whispersystems/test/SessionCipherTest.java index cad3ddfdd0..192a7a5506 100644 --- a/libaxolotl/src/androidTest/java/org/whispersystems/test/SessionCipherTest.java +++ b/libaxolotl/src/androidTest/java/org/whispersystems/test/SessionCipherTest.java @@ -138,16 +138,16 @@ public class SessionCipherTest extends AndroidTestCase { private void initializeSessionsV2(SessionState aliceSessionState, SessionState bobSessionState) throws InvalidKeyException { - ECKeyPair aliceIdentityKeyPair = Curve.generateKeyPair(false); + ECKeyPair aliceIdentityKeyPair = Curve.generateKeyPair(); IdentityKeyPair aliceIdentityKey = new IdentityKeyPair(new IdentityKey(aliceIdentityKeyPair.getPublicKey()), aliceIdentityKeyPair.getPrivateKey()); - ECKeyPair aliceBaseKey = Curve.generateKeyPair(true); - ECKeyPair aliceEphemeralKey = Curve.generateKeyPair(true); + ECKeyPair aliceBaseKey = Curve.generateKeyPair(); + ECKeyPair aliceEphemeralKey = Curve.generateKeyPair(); - ECKeyPair bobIdentityKeyPair = Curve.generateKeyPair(false); + ECKeyPair bobIdentityKeyPair = Curve.generateKeyPair(); IdentityKeyPair bobIdentityKey = new IdentityKeyPair(new IdentityKey(bobIdentityKeyPair.getPublicKey()), bobIdentityKeyPair.getPrivateKey()); - ECKeyPair bobBaseKey = Curve.generateKeyPair(true); + ECKeyPair bobBaseKey = Curve.generateKeyPair(); ECKeyPair bobEphemeralKey = bobBaseKey; AliceAxolotlParameters aliceParameters = AliceAxolotlParameters.newBuilder() @@ -175,21 +175,21 @@ public class SessionCipherTest extends AndroidTestCase { private void initializeSessionsV3(SessionState aliceSessionState, SessionState bobSessionState) throws InvalidKeyException { - ECKeyPair aliceIdentityKeyPair = Curve.generateKeyPair(false); + ECKeyPair aliceIdentityKeyPair = Curve.generateKeyPair(); IdentityKeyPair aliceIdentityKey = new IdentityKeyPair(new IdentityKey(aliceIdentityKeyPair.getPublicKey()), aliceIdentityKeyPair.getPrivateKey()); - ECKeyPair aliceBaseKey = Curve.generateKeyPair(true); - ECKeyPair aliceEphemeralKey = Curve.generateKeyPair(true); + ECKeyPair aliceBaseKey = Curve.generateKeyPair(); + ECKeyPair aliceEphemeralKey = Curve.generateKeyPair(); ECKeyPair alicePreKey = aliceBaseKey; - ECKeyPair bobIdentityKeyPair = Curve.generateKeyPair(false); + ECKeyPair bobIdentityKeyPair = Curve.generateKeyPair(); IdentityKeyPair bobIdentityKey = new IdentityKeyPair(new IdentityKey(bobIdentityKeyPair.getPublicKey()), bobIdentityKeyPair.getPrivateKey()); - ECKeyPair bobBaseKey = Curve.generateKeyPair(true); + ECKeyPair bobBaseKey = Curve.generateKeyPair(); ECKeyPair bobEphemeralKey = bobBaseKey; - ECKeyPair bobPreKey = Curve.generateKeyPair(true); + ECKeyPair bobPreKey = Curve.generateKeyPair(); AliceAxolotlParameters aliceParameters = AliceAxolotlParameters.newBuilder() .setOurBaseKey(aliceBaseKey) diff --git a/libaxolotl/src/androidTest/java/org/whispersystems/test/ecc/Curve25519Test.java b/libaxolotl/src/androidTest/java/org/whispersystems/test/ecc/Curve25519Test.java index 5903353de1..b0f9617084 100644 --- a/libaxolotl/src/androidTest/java/org/whispersystems/test/ecc/Curve25519Test.java +++ b/libaxolotl/src/androidTest/java/org/whispersystems/test/ecc/Curve25519Test.java @@ -70,8 +70,8 @@ public class Curve25519Test extends AndroidTestCase { public void testRandomAgreements() throws InvalidKeyException { for (int i=0;i<50;i++) { - ECKeyPair alice = Curve.generateKeyPair(false); - ECKeyPair bob = Curve.generateKeyPair(false); + ECKeyPair alice = Curve.generateKeyPair(); + ECKeyPair bob = Curve.generateKeyPair(); byte[] sharedAlice = Curve.calculateAgreement(bob.getPublicKey(), alice.getPrivateKey()); byte[] sharedBob = Curve.calculateAgreement(alice.getPublicKey(), bob.getPrivateKey()); diff --git a/libaxolotl/src/androidTest/java/org/whispersystems/test/ratchet/RatchetingSessionTest.java b/libaxolotl/src/androidTest/java/org/whispersystems/test/ratchet/RatchetingSessionTest.java index 48f7bc64e4..b09f6dbd4a 100644 --- a/libaxolotl/src/androidTest/java/org/whispersystems/test/ratchet/RatchetingSessionTest.java +++ b/libaxolotl/src/androidTest/java/org/whispersystems/test/ratchet/RatchetingSessionTest.java @@ -1,6 +1,7 @@ package org.whispersystems.test.ratchet; import android.test.AndroidTestCase; +import android.util.Log; import org.whispersystems.libaxolotl.IdentityKey; import org.whispersystems.libaxolotl.IdentityKeyPair; @@ -13,6 +14,7 @@ import org.whispersystems.libaxolotl.ratchet.AliceAxolotlParameters; import org.whispersystems.libaxolotl.ratchet.BobAxolotlParameters; import org.whispersystems.libaxolotl.ratchet.RatchetingSession; import org.whispersystems.libaxolotl.state.SessionState; +import org.whispersystems.libaxolotl.util.Hex; import org.whispersystems.libaxolotl.util.guava.Optional; import java.util.Arrays; @@ -88,13 +90,12 @@ public class RatchetingSessionTest extends AndroidTestCase { (byte) 0xee, (byte) 0xfc, (byte) 0xb4, (byte) 0x2b, (byte) 0x4a}; - byte[] senderChain = {(byte)0xd2, (byte)0x2f, (byte)0xd5, (byte)0x6d, (byte)0x3f, - (byte)0xec, (byte)0x81, (byte)0x9c, (byte)0xf4, (byte)0xc3, - (byte)0xd5, (byte)0x0c, (byte)0x56, (byte)0xed, (byte)0xfb, - (byte)0x1c, (byte)0x28, (byte)0x0a, (byte)0x1b, (byte)0x31, - (byte)0x96, (byte)0x45, (byte)0x37, (byte)0xf1, (byte)0xd1, - (byte)0x61, (byte)0xe1, (byte)0xc9, (byte)0x31, (byte)0x48, - (byte)0xe3, (byte)0x6b}; + byte[] senderChain = {(byte)0x33, (byte)0xe9, (byte)0x46, (byte)0x5e, (byte)0x88, (byte)0x92, + (byte)0x2b, (byte)0x51, (byte)0xa6, (byte)0x76, (byte)0xaf, (byte)0xba, + (byte)0x03, (byte)0xf2, (byte)0x27, (byte)0x58, (byte)0xee, (byte)0xe1, + (byte)0xef, (byte)0x15, (byte)0xb0, (byte)0x28, (byte)0x39, (byte)0x0d, + (byte)0x70, (byte)0x76, (byte)0xc7, (byte)0xc7, (byte)0x09, (byte)0xef, + (byte)0x5d, (byte)0x8b}; IdentityKey bobIdentityKeyPublic = new IdentityKey(bobIdentityPublic, 0); ECPrivateKey bobIdentityKeyPrivate = Curve.decodePrivatePoint(bobIdentityPrivate); @@ -191,13 +192,12 @@ public class RatchetingSessionTest extends AndroidTestCase { (byte) 0xeb, (byte) 0x0a, (byte) 0x6f, (byte) 0x4f, (byte) 0x5f, (byte) 0x8f, (byte) 0x58}; - byte[] receiverChain = {(byte) 0xd2, (byte) 0x2f, (byte) 0xd5, (byte) 0x6d, (byte) 0x3f, - (byte) 0xec, (byte) 0x81, (byte) 0x9c, (byte) 0xf4, (byte) 0xc3, - (byte) 0xd5, (byte) 0x0c, (byte) 0x56, (byte) 0xed, (byte) 0xfb, - (byte) 0x1c, (byte) 0x28, (byte) 0x0a, (byte) 0x1b, (byte) 0x31, - (byte) 0x96, (byte) 0x45, (byte) 0x37, (byte) 0xf1, (byte) 0xd1, - (byte) 0x61, (byte) 0xe1, (byte) 0xc9, (byte) 0x31, (byte) 0x48, - (byte) 0xe3, (byte) 0x6b}; + byte[] receiverChain = {(byte)0x68, (byte)0x4a, (byte)0xc5, (byte)0x15, (byte)0xc9, (byte)0x14, + (byte)0x45, (byte)0xf7, (byte)0xa0, (byte)0xc9, (byte)0x3c, (byte)0x39, + (byte)0xf7, (byte)0xe6, (byte)0xa1, (byte)0x7f, (byte)0xa0, (byte)0x8e, + (byte)0x04, (byte)0x62, (byte)0xf1, (byte)0x50, (byte)0xe5, (byte)0xac, + (byte)0x60, (byte)0x71, (byte)0x78, (byte)0xc1, (byte)0xa5, (byte)0xd2, + (byte)0xc7, (byte)0xd6}; IdentityKey bobIdentityKey = new IdentityKey(bobIdentityPublic, 0); ECPublicKey bobEphemeralPublicKey = Curve.decodePoint(bobPublic, 0); diff --git a/libaxolotl/src/androidTest/java/org/whispersystems/test/ratchet/RootKeyTest.java b/libaxolotl/src/androidTest/java/org/whispersystems/test/ratchet/RootKeyTest.java index c48ef23d2f..b7a19b0f97 100644 --- a/libaxolotl/src/androidTest/java/org/whispersystems/test/ratchet/RootKeyTest.java +++ b/libaxolotl/src/androidTest/java/org/whispersystems/test/ratchet/RootKeyTest.java @@ -50,21 +50,21 @@ public class RootKeyTest extends AndroidTestCase { (byte) 0x95, (byte) 0x55, (byte) 0xe8, (byte) 0x47, (byte) 0x57, (byte) 0x70, (byte) 0x8a, (byte) 0x30}; - byte[] nextRoot = {(byte) 0xb1, (byte) 0x14, (byte) 0xf5, (byte) 0xde, (byte) 0x28, - (byte) 0x01, (byte) 0x19, (byte) 0x85, (byte) 0xe6, (byte) 0xeb, - (byte) 0xa2, (byte) 0x5d, (byte) 0x50, (byte) 0xe7, (byte) 0xec, - (byte) 0x41, (byte) 0xa9, (byte) 0xb0, (byte) 0x2f, (byte) 0x56, - (byte) 0x93, (byte) 0xc5, (byte) 0xc7, (byte) 0x88, (byte) 0xa6, - (byte) 0x3a, (byte) 0x06, (byte) 0xd2, (byte) 0x12, (byte) 0xa2, - (byte) 0xf7, (byte) 0x31}; + byte[] nextRoot = {(byte)0x67, (byte)0x46, (byte)0x77, (byte)0x65, (byte)0x21, + (byte)0x04, (byte)0xe8, (byte)0x64, (byte)0xd0, (byte)0x7c, + (byte)0x54, (byte)0x33, (byte)0xef, (byte)0xaa, (byte)0x59, + (byte)0x25, (byte)0xed, (byte)0x43, (byte)0x67, (byte)0xd6, + (byte)0xb2, (byte)0x5a, (byte)0xaf, (byte)0xe6, (byte)0x99, + (byte)0x1d, (byte)0xef, (byte)0x5c, (byte)0x7f, (byte)0x0f, + (byte)0xb8, (byte)0x6f}; - byte[] nextChain = {(byte) 0x9d, (byte) 0x7d, (byte) 0x24, (byte) 0x69, (byte) 0xbc, - (byte) 0x9a, (byte) 0xe5, (byte) 0x3e, (byte) 0xe9, (byte) 0x80, - (byte) 0x5a, (byte) 0xa3, (byte) 0x26, (byte) 0x4d, (byte) 0x24, - (byte) 0x99, (byte) 0xa3, (byte) 0xac, (byte) 0xe8, (byte) 0x0f, - (byte) 0x4c, (byte) 0xca, (byte) 0xe2, (byte) 0xda, (byte) 0x13, - (byte) 0x43, (byte) 0x0c, (byte) 0x5c, (byte) 0x55, (byte) 0xb5, - (byte) 0xca, (byte) 0x5f}; + byte[] nextChain = {(byte)0xfa, (byte)0xed, (byte)0x7f, (byte)0xb2, (byte)0xc3, + (byte)0xe6, (byte)0xf6, (byte)0x06, (byte)0xfc, (byte)0xbf, + (byte)0x26, (byte)0x64, (byte)0x6c, (byte)0xf2, (byte)0x68, + (byte)0xad, (byte)0x49, (byte)0x58, (byte)0x9f, (byte)0xcb, + (byte)0xde, (byte)0x01, (byte)0xc1, (byte)0x26, (byte)0x75, + (byte)0xe5, (byte)0xe8, (byte)0x22, (byte)0xa7, (byte)0xe3, + (byte)0x35, (byte)0xd1}; ECPublicKey alicePublicKey = Curve.decodePoint(alicePublic, 0); ECPrivateKey alicePrivateKey = Curve.decodePrivatePoint(alicePrivate); diff --git a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/SessionBuilder.java b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/SessionBuilder.java index a6dd95304d..6756a288d7 100644 --- a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/SessionBuilder.java +++ b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/SessionBuilder.java @@ -217,7 +217,7 @@ public class SessionBuilder { } SessionRecord sessionRecord = sessionStore.loadSession(recipientId, deviceId); - ECKeyPair ourBaseKey = Curve.generateKeyPair(true); + ECKeyPair ourBaseKey = Curve.generateKeyPair(); ECPublicKey theirSignedPreKey = preKey.getSignedPreKey() != null ? preKey.getSignedPreKey() : preKey.getPreKey(); @@ -287,8 +287,8 @@ public class SessionBuilder { if (!sessionRecord.getSessionState().hasPendingKeyExchange()) { builder.setOurIdentityKey(identityKeyStore.getIdentityKeyPair()) - .setOurBaseKey(Curve.generateKeyPair(true)) - .setOurRatchetKey(Curve.generateKeyPair(true)); + .setOurBaseKey(Curve.generateKeyPair()) + .setOurRatchetKey(Curve.generateKeyPair()); } else { builder.setOurIdentityKey(sessionRecord.getSessionState().getPendingKeyExchangeIdentityKey()) .setOurBaseKey(sessionRecord.getSessionState().getPendingKeyExchangeBaseKey()) @@ -372,8 +372,8 @@ public class SessionBuilder { try { int sequence = KeyHelper.getRandomSequence(65534) + 1; int flags = KeyExchangeMessage.INITIATE_FLAG; - ECKeyPair baseKey = Curve.generateKeyPair(true); - ECKeyPair ratchetKey = Curve.generateKeyPair(true); + ECKeyPair baseKey = Curve.generateKeyPair(); + ECKeyPair ratchetKey = Curve.generateKeyPair(); IdentityKeyPair identityKey = identityKeyStore.getIdentityKeyPair(); byte[] baseKeySignature = Curve.calculateSignature(identityKey.getPrivateKey(), baseKey.getPublicKey().serialize()); SessionRecord sessionRecord = sessionStore.loadSession(recipientId, deviceId); diff --git a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/SessionCipher.java b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/SessionCipher.java index d94f648b89..33415ce573 100644 --- a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/SessionCipher.java +++ b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/SessionCipher.java @@ -261,7 +261,7 @@ public class SessionCipher { RootKey rootKey = sessionState.getRootKey(); ECKeyPair ourEphemeral = sessionState.getSenderRatchetKeyPair(); Pair receiverChain = rootKey.createChain(theirEphemeral, ourEphemeral); - ECKeyPair ourNewEphemeral = Curve.generateKeyPair(true); + ECKeyPair ourNewEphemeral = Curve.generateKeyPair(); Pair senderChain = receiverChain.first().createChain(theirEphemeral, ourNewEphemeral); sessionState.setRootKey(senderChain.first()); diff --git a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/ecc/Curve.java b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/ecc/Curve.java index 4d26962da6..66b8cc3ab8 100644 --- a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/ecc/Curve.java +++ b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/ecc/Curve.java @@ -22,8 +22,8 @@ public class Curve { public static final int DJB_TYPE = 0x05; - public static ECKeyPair generateKeyPair(boolean ephemeral) { - return Curve25519.generateKeyPair(ephemeral); + public static ECKeyPair generateKeyPair() { + return Curve25519.generateKeyPair(); } public static ECPublicKey decodePoint(byte[] bytes, int offset) diff --git a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/ecc/Curve25519.java b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/ecc/Curve25519.java index 18152d395a..6f5d610fd7 100644 --- a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/ecc/Curve25519.java +++ b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/ecc/Curve25519.java @@ -37,13 +37,13 @@ public class Curve25519 { private static native byte[] calculateAgreement(byte[] ourPrivate, byte[] theirPublic); private static native byte[] generatePublicKey(byte[] privateKey); - private static native byte[] generatePrivateKey(byte[] random, boolean ephemeral); + private static native byte[] generatePrivateKey(byte[] random); private static native byte[] calculateSignature(byte[] random, byte[] privateKey, byte[] message); private static native boolean verifySignature(byte[] publicKey, byte[] message, byte[] signature); - public static ECKeyPair generateKeyPair(boolean ephemeral) { - byte[] privateKey = generatePrivateKey(ephemeral); + public static ECKeyPair generateKeyPair() { + byte[] privateKey = generatePrivateKey(); byte[] publicKey = generatePublicKey(privateKey); return new ECKeyPair(new DjbECPublicKey(publicKey), new DjbECPrivateKey(privateKey)); @@ -77,11 +77,11 @@ public class Curve25519 { return new DjbECPublicKey(keyBytes); } - private static byte[] generatePrivateKey(boolean ephemeral) { + private static byte[] generatePrivateKey() { byte[] privateKey = new byte[32]; random.nextBytes(privateKey); - return generatePrivateKey(privateKey, ephemeral); + return generatePrivateKey(privateKey); } private static byte[] getRandom(int size) { diff --git a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/ratchet/RatchetingSession.java b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/ratchet/RatchetingSession.java index 564969d980..8c094ec0d7 100644 --- a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/ratchet/RatchetingSession.java +++ b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/ratchet/RatchetingSession.java @@ -72,7 +72,7 @@ public class RatchetingSession { sessionState.setRemoteIdentityKey(parameters.getTheirIdentityKey()); sessionState.setLocalIdentityKey(parameters.getOurIdentityKey().getPublicKey()); - ECKeyPair sendingRatchetKey = Curve.generateKeyPair(true); + ECKeyPair sendingRatchetKey = Curve.generateKeyPair(); ByteArrayOutputStream secrets = new ByteArrayOutputStream(); if (sessionVersion >= 3) { diff --git a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/util/KeyHelper.java b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/util/KeyHelper.java index d46077a782..356d01759c 100644 --- a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/util/KeyHelper.java +++ b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/util/KeyHelper.java @@ -29,7 +29,7 @@ public class KeyHelper { * @return the generated IdentityKeyPair. */ public static IdentityKeyPair generateIdentityKeyPair() { - ECKeyPair keyPair = Curve.generateKeyPair(false); + ECKeyPair keyPair = Curve.generateKeyPair(); IdentityKey publicKey = new IdentityKey(keyPair.getPublicKey()); return new IdentityKeyPair(publicKey, keyPair.getPrivateKey()); } @@ -72,7 +72,7 @@ public class KeyHelper { List results = new LinkedList<>(); for (int i=0;i