Search in sources :

Example 31 with ECKeyPair

use of org.whispersystems.libsignal.ecc.ECKeyPair in project libsignal-service-java by signalapp.

the class ProvisioningCipher method encrypt.

public byte[] encrypt(ProvisionMessage message) throws InvalidKeyException {
    ECKeyPair ourKeyPair = Curve.generateKeyPair();
    byte[] sharedSecret = Curve.calculateAgreement(theirPublicKey, ourKeyPair.getPrivateKey());
    byte[] derivedSecret = new HKDFv3().deriveSecrets(sharedSecret, "TextSecure Provisioning Message".getBytes(), 64);
    byte[][] parts = Util.split(derivedSecret, 32, 32);
    byte[] version = { 0x01 };
    byte[] ciphertext = getCiphertext(parts[0], message.toByteArray());
    byte[] mac = getMac(parts[1], Util.join(version, ciphertext));
    byte[] body = Util.join(version, ciphertext, mac);
    return ProvisionEnvelope.newBuilder().setPublicKey(ByteString.copyFrom(ourKeyPair.getPublicKey().serialize())).setBody(ByteString.copyFrom(body)).build().toByteArray();
}
Also used : ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) HKDFv3(org.whispersystems.libsignal.kdf.HKDFv3)

Example 32 with ECKeyPair

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

the class PrimaryProvisioningCipher method encrypt.

public byte[] encrypt(ProvisionMessage message) throws InvalidKeyException {
    ECKeyPair ourKeyPair = Curve.generateKeyPair();
    byte[] sharedSecret = Curve.calculateAgreement(theirPublicKey, ourKeyPair.getPrivateKey());
    byte[] derivedSecret = HKDF.deriveSecrets(sharedSecret, PROVISIONING_MESSAGE.getBytes(), 64);
    byte[][] parts = Util.split(derivedSecret, 32, 32);
    byte[] version = { 0x01 };
    byte[] ciphertext = getCiphertext(parts[0], message.toByteArray());
    byte[] mac = getMac(parts[1], Util.join(version, ciphertext));
    byte[] body = Util.join(version, ciphertext, mac);
    return ProvisionEnvelope.newBuilder().setPublicKey(ByteString.copyFrom(ourKeyPair.getPublicKey().serialize())).setBody(ByteString.copyFrom(body)).build().toByteArray();
}
Also used : ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair)

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