Search in sources :

Example 1 with ECKeyPair

use of org.whispersystems.libsignal.ecc.ECKeyPair in project Signal-Android by WhisperSystems.

the class PreKeyUtil method generateSignedPreKey.

public static SignedPreKeyRecord generateSignedPreKey(Context context, IdentityKeyPair identityKeyPair, boolean active) {
    try {
        SignedPreKeyStore signedPreKeyStore = new TextSecurePreKeyStore(context);
        int signedPreKeyId = getNextSignedPreKeyId(context);
        ECKeyPair keyPair = Curve.generateKeyPair();
        byte[] signature = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize());
        SignedPreKeyRecord record = new SignedPreKeyRecord(signedPreKeyId, System.currentTimeMillis(), keyPair, signature);
        signedPreKeyStore.storeSignedPreKey(signedPreKeyId, record);
        setNextSignedPreKeyId(context, (signedPreKeyId + 1) % Medium.MAX_VALUE);
        if (active) {
            setActiveSignedPreKeyId(context, signedPreKeyId);
        }
        return record;
    } catch (InvalidKeyException e) {
        throw new AssertionError(e);
    }
}
Also used : SignedPreKeyStore(org.whispersystems.libsignal.state.SignedPreKeyStore) TextSecurePreKeyStore(org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord)

Example 2 with ECKeyPair

use of org.whispersystems.libsignal.ecc.ECKeyPair in project Signal-Android by WhisperSystems.

the class PreKeyUtil method generatePreKeys.

public static List<PreKeyRecord> generatePreKeys(Context context) {
    PreKeyStore preKeyStore = new TextSecurePreKeyStore(context);
    List<PreKeyRecord> records = new LinkedList<>();
    int preKeyIdOffset = getNextPreKeyId(context);
    for (int i = 0; i < BATCH_SIZE; i++) {
        int preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
        ECKeyPair keyPair = Curve.generateKeyPair();
        PreKeyRecord record = new PreKeyRecord(preKeyId, keyPair);
        preKeyStore.storePreKey(preKeyId, record);
        records.add(record);
    }
    setNextPreKeyId(context, (preKeyIdOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE);
    return records;
}
Also used : TextSecurePreKeyStore(org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) PreKeyRecord(org.whispersystems.libsignal.state.PreKeyRecord) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) PreKeyStore(org.whispersystems.libsignal.state.PreKeyStore) TextSecurePreKeyStore(org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore) SignedPreKeyStore(org.whispersystems.libsignal.state.SignedPreKeyStore) LinkedList(java.util.LinkedList)

Example 3 with ECKeyPair

use of org.whispersystems.libsignal.ecc.ECKeyPair in project Signal-Android by WhisperSystems.

the class IdentityKeyUtil method generateIdentityKeys.

public static void generateIdentityKeys(Context context) {
    ECKeyPair djbKeyPair = Curve.generateKeyPair();
    IdentityKey djbIdentityKey = new IdentityKey(djbKeyPair.getPublicKey());
    ECPrivateKey djbPrivateKey = djbKeyPair.getPrivateKey();
    save(context, IDENTITY_PUBLIC_KEY_PREF, Base64.encodeBytes(djbIdentityKey.serialize()));
    save(context, IDENTITY_PRIVATE_KEY_PREF, Base64.encodeBytes(djbPrivateKey.serialize()));
}
Also used : ECPrivateKey(org.whispersystems.libsignal.ecc.ECPrivateKey) IdentityKey(org.whispersystems.libsignal.IdentityKey) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair)

Example 4 with ECKeyPair

use of org.whispersystems.libsignal.ecc.ECKeyPair in project Signal-Android by signalapp.

the class IdentityKeyUtil method generateIdentityKeys.

public static void generateIdentityKeys(Context context) {
    ECKeyPair djbKeyPair = Curve.generateKeyPair();
    IdentityKey djbIdentityKey = new IdentityKey(djbKeyPair.getPublicKey());
    ECPrivateKey djbPrivateKey = djbKeyPair.getPrivateKey();
    save(context, IDENTITY_PUBLIC_KEY_PREF, Base64.encodeBytes(djbIdentityKey.serialize()));
    save(context, IDENTITY_PRIVATE_KEY_PREF, Base64.encodeBytes(djbPrivateKey.serialize()));
}
Also used : ECPrivateKey(org.whispersystems.libsignal.ecc.ECPrivateKey) IdentityKey(org.whispersystems.libsignal.IdentityKey) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair)

Example 5 with ECKeyPair

use of org.whispersystems.libsignal.ecc.ECKeyPair in project Signal-Android by signalapp.

the class AsymmetricMasterCipher method encryptBytes.

public byte[] encryptBytes(byte[] body) {
    try {
        ECPublicKey theirPublic = asymmetricMasterSecret.getDjbPublicKey();
        ECKeyPair ourKeyPair = Curve.generateKeyPair();
        byte[] secret = Curve.calculateAgreement(theirPublic, ourKeyPair.getPrivateKey());
        MasterCipher masterCipher = getMasterCipherForSecret(secret);
        byte[] encryptedBodyBytes = masterCipher.encryptBytes(body);
        PublicKey ourPublicKey = new PublicKey(31337, ourKeyPair.getPublicKey());
        byte[] publicKeyBytes = ourPublicKey.serialize();
        return Util.combine(publicKeyBytes, encryptedBodyBytes);
    } catch (InvalidKeyException e) {
        throw new AssertionError(e);
    }
}
Also used : ECPublicKey(org.whispersystems.libsignal.ecc.ECPublicKey) ECPublicKey(org.whispersystems.libsignal.ecc.ECPublicKey) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException)

Aggregations

ECKeyPair (org.whispersystems.libsignal.ecc.ECKeyPair)26 SignedPreKeyRecord (org.whispersystems.libsignal.state.SignedPreKeyRecord)12 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)9 SignedPreKeyStore (org.whispersystems.libsignal.state.SignedPreKeyStore)8 PreKeyRecord (org.whispersystems.libsignal.state.PreKeyRecord)7 ECPrivateKey (org.whispersystems.libsignal.ecc.ECPrivateKey)6 LinkedList (java.util.LinkedList)5 TextSecurePreKeyStore (org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore)5 IdentityKey (org.whispersystems.libsignal.IdentityKey)5 ECPublicKey (org.whispersystems.libsignal.ecc.ECPublicKey)5 PreKeyStore (org.whispersystems.libsignal.state.PreKeyStore)5 Cursor (android.database.Cursor)3 SignalPreKeyStore (com.toshi.crypto.signal.store.SignalPreKeyStore)3 IOException (java.io.IOException)3 SQLiteDatabase (net.sqlcipher.database.SQLiteDatabase)3 IdentityKeyPair (org.whispersystems.libsignal.IdentityKeyPair)3 Nullable (android.support.annotation.Nullable)2 NonNull (androidx.annotation.NonNull)2 InvalidKeyIdException (org.whispersystems.libsignal.InvalidKeyIdException)2 MultiRemoteAttestationResponse (org.whispersystems.signalservice.internal.contacts.entities.MultiRemoteAttestationResponse)2