mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 21:15:48 +00:00
Refactor array creation to a function.
This commit is contained in:
@@ -27,7 +27,7 @@ object DeviceNameCipher {
|
||||
val cipherKey: ByteArray = computeCipherKey(masterSecret, syntheticIv)
|
||||
|
||||
val cipher = Cipher.getInstance("AES/CTR/NoPadding")
|
||||
cipher.init(Cipher.ENCRYPT_MODE, SecretKeySpec(cipherKey, "AES"), IvParameterSpec(ByteArray(16)))
|
||||
cipher.init(Cipher.ENCRYPT_MODE, SecretKeySpec(cipherKey, "AES"), IvParameterSpec(createEmptyByteArray(16)))
|
||||
val cipherText = cipher.doFinal(plaintext)
|
||||
|
||||
return DeviceName(
|
||||
@@ -60,4 +60,6 @@ object DeviceNameCipher {
|
||||
ivMac.init(SecretKeySpec(syntheticIvKey, "HmacSHA256"))
|
||||
return ivMac.doFinal(plaintext).sliceArray(0 until SYNTHETIC_IV_LENGTH)
|
||||
}
|
||||
|
||||
private fun createEmptyByteArray(length: Int): ByteArray = ByteArray(length)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package org.whispersystems.signalservice.api.crypto;
|
||||
import org.signal.libsignal.metadata.certificate.InvalidCertificateException;
|
||||
import org.signal.libsignal.metadata.certificate.SenderCertificate;
|
||||
import org.signal.libsignal.protocol.util.ByteUtil;
|
||||
import org.signal.libsignal.zkgroup.internal.ByteArray;
|
||||
import org.signal.libsignal.zkgroup.profiles.ProfileKey;
|
||||
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
@@ -50,8 +51,8 @@ public class UnidentifiedAccess {
|
||||
|
||||
public static byte[] deriveAccessKeyFrom(ProfileKey profileKey) {
|
||||
try {
|
||||
byte[] nonce = new byte[12];
|
||||
byte[] input = new byte[16];
|
||||
byte[] nonce = createEmptyByteArray(12);
|
||||
byte[] input = createEmptyByteArray(16);
|
||||
|
||||
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(profileKey.serialize(), "AES"), new GCMParameterSpec(128, nonce));
|
||||
@@ -63,4 +64,9 @@ public class UnidentifiedAccess {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static byte[] createEmptyByteArray(int length) {
|
||||
return new byte[length];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user