Remove 1 mod 8.
This commit is contained in:
parent
eda393b11c
commit
27b5bf54cc
21 changed files with 85 additions and 90 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -261,7 +261,7 @@ public class SessionCipher {
|
|||
RootKey rootKey = sessionState.getRootKey();
|
||||
ECKeyPair ourEphemeral = sessionState.getSenderRatchetKeyPair();
|
||||
Pair<RootKey, ChainKey> receiverChain = rootKey.createChain(theirEphemeral, ourEphemeral);
|
||||
ECKeyPair ourNewEphemeral = Curve.generateKeyPair(true);
|
||||
ECKeyPair ourNewEphemeral = Curve.generateKeyPair();
|
||||
Pair<RootKey, ChainKey> senderChain = receiverChain.first().createChain(theirEphemeral, ourNewEphemeral);
|
||||
|
||||
sessionState.setRootKey(senderChain.first());
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<PreKeyRecord> results = new LinkedList<>();
|
||||
|
||||
for (int i=0;i<count;i++) {
|
||||
results.add(new PreKeyRecord((start + i) % Medium.MAX_VALUE, Curve.generateKeyPair(true)));
|
||||
results.add(new PreKeyRecord((start + i) % Medium.MAX_VALUE, Curve.generateKeyPair()));
|
||||
}
|
||||
|
||||
return results;
|
||||
|
@ -85,7 +85,7 @@ public class KeyHelper {
|
|||
* @return the generated last resort PreKeyRecord.
|
||||
*/
|
||||
public static PreKeyRecord generateLastResortPreKey() {
|
||||
ECKeyPair keyPair = Curve.generateKeyPair(true);
|
||||
ECKeyPair keyPair = Curve.generateKeyPair();
|
||||
return new PreKeyRecord(Medium.MAX_VALUE, keyPair);
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ public class KeyHelper {
|
|||
public static SignedPreKeyRecord generateSignedPreKey(IdentityKeyPair identityKeyPair, int signedPreKeyId)
|
||||
throws InvalidKeyException
|
||||
{
|
||||
ECKeyPair keyPair = Curve.generateKeyPair(true);
|
||||
ECKeyPair keyPair = Curve.generateKeyPair();
|
||||
byte[] signature = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize());
|
||||
|
||||
return new SignedPreKeyRecord(signedPreKeyId, System.currentTimeMillis(), keyPair, signature);
|
||||
|
|
|
@ -55,7 +55,7 @@ public class PreKeyUtil {
|
|||
|
||||
for (int i=0;i<BATCH_SIZE;i++) {
|
||||
int preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
|
||||
ECKeyPair keyPair = Curve25519.generateKeyPair(true);
|
||||
ECKeyPair keyPair = Curve25519.generateKeyPair();
|
||||
PreKeyRecord record = new PreKeyRecord(preKeyId, keyPair);
|
||||
|
||||
preKeyStore.storePreKey(preKeyId, record);
|
||||
|
@ -72,7 +72,7 @@ public class PreKeyUtil {
|
|||
try {
|
||||
SignedPreKeyStore signedPreKeyStore = new TextSecurePreKeyStore(context, masterSecret);
|
||||
int signedPreKeyId = getNextSignedPreKeyId(context);
|
||||
ECKeyPair keyPair = Curve25519.generateKeyPair(true);
|
||||
ECKeyPair keyPair = Curve25519.generateKeyPair();
|
||||
byte[] signature = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize());
|
||||
SignedPreKeyRecord record = new SignedPreKeyRecord(signedPreKeyId, System.currentTimeMillis(), keyPair, signature);
|
||||
|
||||
|
@ -97,7 +97,7 @@ public class PreKeyUtil {
|
|||
}
|
||||
}
|
||||
|
||||
ECKeyPair keyPair = Curve25519.generateKeyPair(true);
|
||||
ECKeyPair keyPair = Curve25519.generateKeyPair();
|
||||
PreKeyRecord record = new PreKeyRecord(Medium.MAX_VALUE, keyPair);
|
||||
|
||||
preKeyStore.storePreKey(Medium.MAX_VALUE, record);
|
||||
|
|
|
@ -86,7 +86,7 @@ public class AsymmetricMasterCipher {
|
|||
public String encryptBody(String body) {
|
||||
try {
|
||||
ECPublicKey theirPublic = asymmetricMasterSecret.getDjbPublicKey();
|
||||
ECKeyPair ourKeyPair = Curve.generateKeyPair(true);
|
||||
ECKeyPair ourKeyPair = Curve.generateKeyPair();
|
||||
byte[] secret = Curve.calculateAgreement(theirPublic, ourKeyPair.getPrivateKey());
|
||||
MasterCipher masterCipher = getMasterCipherForSecret(secret);
|
||||
byte[] encryptedBodyBytes = masterCipher.encryptBytes(body.getBytes());
|
||||
|
|
|
@ -88,7 +88,7 @@ public class IdentityKeyUtil {
|
|||
}
|
||||
|
||||
public static void generateIdentityKeys(Context context, MasterSecret masterSecret) {
|
||||
ECKeyPair djbKeyPair = Curve.generateKeyPair(false);
|
||||
ECKeyPair djbKeyPair = Curve.generateKeyPair();
|
||||
|
||||
MasterCipher masterCipher = new MasterCipher(masterSecret);
|
||||
IdentityKey djbIdentityKey = new IdentityKey(djbKeyPair.getPublicKey());
|
||||
|
@ -106,7 +106,7 @@ public class IdentityKeyUtil {
|
|||
|
||||
public static void generateCurve25519IdentityKeys(Context context, MasterSecret masterSecret) {
|
||||
MasterCipher masterCipher = new MasterCipher(masterSecret);
|
||||
ECKeyPair djbKeyPair = Curve.generateKeyPair(false);
|
||||
ECKeyPair djbKeyPair = Curve.generateKeyPair();
|
||||
IdentityKey djbIdentityKey = new IdentityKey(djbKeyPair.getPublicKey());
|
||||
byte[] djbPrivateKey = masterCipher.encryptKey(djbKeyPair.getPrivateKey());
|
||||
|
||||
|
|
|
@ -156,7 +156,7 @@ public class MasterSecretUtil {
|
|||
MasterSecret masterSecret)
|
||||
{
|
||||
MasterCipher masterCipher = new MasterCipher(masterSecret);
|
||||
ECKeyPair keyPair = Curve.generateKeyPair(true);
|
||||
ECKeyPair keyPair = Curve.generateKeyPair();
|
||||
|
||||
save(context, ASYMMETRIC_LOCAL_PUBLIC_DJB, keyPair.getPublicKey().serialize());
|
||||
save(context, ASYMMETRIC_LOCAL_PRIVATE_DJB, masterCipher.encryptKey(keyPair.getPrivateKey()));
|
||||
|
|
Loading…
Add table
Reference in a new issue