Search in sources :

Example 21 with ECKeyPair

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

the class PreKeyUtil method generateAndStoreSignedPreKey.

@NonNull
public static synchronized SignedPreKeyRecord generateAndStoreSignedPreKey(@NonNull SignalProtocolStore protocolStore, @NonNull PreKeyMetadataStore metadataStore, boolean setAsActive) {
    Log.i(TAG, "Generating signed prekeys...");
    try {
        int signedPreKeyId = metadataStore.getNextSignedPreKeyId();
        ECKeyPair keyPair = Curve.generateKeyPair();
        byte[] signature = Curve.calculateSignature(protocolStore.getIdentityKeyPair().getPrivateKey(), keyPair.getPublicKey().serialize());
        SignedPreKeyRecord record = new SignedPreKeyRecord(signedPreKeyId, System.currentTimeMillis(), keyPair, signature);
        protocolStore.storeSignedPreKey(signedPreKeyId, record);
        metadataStore.setNextSignedPreKeyId((signedPreKeyId + 1) % Medium.MAX_VALUE);
        if (setAsActive) {
            metadataStore.setActiveSignedPreKeyId(signedPreKeyId);
        }
        return record;
    } catch (InvalidKeyException e) {
        throw new AssertionError(e);
    }
}
Also used : ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) NonNull(androidx.annotation.NonNull)

Example 22 with ECKeyPair

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

the class PreKeyUtil method generateAndStoreOneTimePreKeys.

@NonNull
public static synchronized List<PreKeyRecord> generateAndStoreOneTimePreKeys(@NonNull SignalProtocolStore protocolStore, @NonNull PreKeyMetadataStore metadataStore) {
    Log.i(TAG, "Generating one-time prekeys...");
    List<PreKeyRecord> records = new LinkedList<>();
    int preKeyIdOffset = metadataStore.getNextOneTimePreKeyId();
    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);
        protocolStore.storePreKey(preKeyId, record);
        records.add(record);
    }
    metadataStore.setNextOneTimePreKeyId((preKeyIdOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE);
    return records;
}
Also used : ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) PreKeyRecord(org.whispersystems.libsignal.state.PreKeyRecord) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) LinkedList(java.util.LinkedList) NonNull(androidx.annotation.NonNull)

Example 23 with ECKeyPair

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

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)

Example 24 with ECKeyPair

use of org.whispersystems.libsignal.ecc.ECKeyPair in project Conversations by siacs.

the class SQLiteAxolotlStore method generateIdentityKeyPair.

private static IdentityKeyPair generateIdentityKeyPair() {
    Log.i(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Generating axolotl IdentityKeyPair...");
    ECKeyPair identityKeyPairKeys = Curve.generateKeyPair();
    return new IdentityKeyPair(new IdentityKey(identityKeyPairKeys.getPublicKey()), identityKeyPairKeys.getPrivateKey());
}
Also used : IdentityKey(org.whispersystems.libsignal.IdentityKey) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair)

Example 25 with ECKeyPair

use of org.whispersystems.libsignal.ecc.ECKeyPair in project Pix-Art-Messenger by kriztan.

the class SQLiteAxolotlStore method generateIdentityKeyPair.

private static IdentityKeyPair generateIdentityKeyPair() {
    Log.i(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Generating axolotl IdentityKeyPair...");
    ECKeyPair identityKeyPairKeys = Curve.generateKeyPair();
    return new IdentityKeyPair(new IdentityKey(identityKeyPairKeys.getPublicKey()), identityKeyPairKeys.getPrivateKey());
}
Also used : IdentityKey(org.whispersystems.libsignal.IdentityKey) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair)

Aggregations

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