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();
}
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();
}
Aggregations