mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Minor refactoring and renaming.
This commit is contained in:
parent
c330eef7b9
commit
eda393b11c
@ -17,32 +17,24 @@
|
|||||||
|
|
||||||
package org.whispersystems.libaxolotl.kdf;
|
package org.whispersystems.libaxolotl.kdf;
|
||||||
|
|
||||||
|
import org.whispersystems.libaxolotl.util.ByteUtil;
|
||||||
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
public class DerivedMessageSecrets {
|
public class DerivedMessageSecrets {
|
||||||
|
|
||||||
public static final int SIZE = 64;
|
public static final int SIZE = 64;
|
||||||
private static final int CIPHER_KEYS_OFFSET = 0;
|
private static final int CIPHER_KEY_LENGTH = 32;
|
||||||
private static final int MAC_KEYS_OFFSET = 32;
|
private static final int MAC_KEY_LENGTH = 32;
|
||||||
|
|
||||||
private final SecretKeySpec cipherKey;
|
private final SecretKeySpec cipherKey;
|
||||||
private final SecretKeySpec macKey;
|
private final SecretKeySpec macKey;
|
||||||
|
|
||||||
public DerivedMessageSecrets(byte[] okm) {
|
public DerivedMessageSecrets(byte[] okm) {
|
||||||
this.cipherKey = deriveCipherKey(okm);
|
byte[][] keys = ByteUtil.split(okm, CIPHER_KEY_LENGTH, MAC_KEY_LENGTH);
|
||||||
this.macKey = deriveMacKey(okm);
|
|
||||||
}
|
|
||||||
|
|
||||||
private SecretKeySpec deriveCipherKey(byte[] okm) {
|
this.cipherKey = new SecretKeySpec(keys[0], "AES");
|
||||||
byte[] cipherKey = new byte[32];
|
this.macKey = new SecretKeySpec(keys[1], "HmacSHA256");
|
||||||
System.arraycopy(okm, CIPHER_KEYS_OFFSET, cipherKey, 0, cipherKey.length);
|
|
||||||
return new SecretKeySpec(cipherKey, "AES");
|
|
||||||
}
|
|
||||||
|
|
||||||
private SecretKeySpec deriveMacKey(byte[] okm) {
|
|
||||||
byte[] macKey = new byte[32];
|
|
||||||
System.arraycopy(okm, MAC_KEYS_OFFSET, macKey, 0, macKey.length);
|
|
||||||
return new SecretKeySpec(macKey, "HmacSHA256");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SecretKeySpec getCipherKey() {
|
public SecretKeySpec getCipherKey() {
|
||||||
|
@ -39,10 +39,10 @@ public class RootKey {
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pair<RootKey, ChainKey> createChain(ECPublicKey theirEphemeral, ECKeyPair ourEphemeral)
|
public Pair<RootKey, ChainKey> createChain(ECPublicKey theirRatchetKey, ECKeyPair ourRatchetKey)
|
||||||
throws InvalidKeyException
|
throws InvalidKeyException
|
||||||
{
|
{
|
||||||
byte[] sharedSecret = Curve.calculateAgreement(theirEphemeral, ourEphemeral.getPrivateKey());
|
byte[] sharedSecret = Curve.calculateAgreement(theirRatchetKey, ourRatchetKey.getPrivateKey());
|
||||||
byte[] derivedSecretBytes = kdf.deriveSecrets(sharedSecret, key, "WhisperRatchet".getBytes(), DerivedRootSecrets.SIZE);
|
byte[] derivedSecretBytes = kdf.deriveSecrets(sharedSecret, key, "WhisperRatchet".getBytes(), DerivedRootSecrets.SIZE);
|
||||||
DerivedRootSecrets derivedSecrets = new DerivedRootSecrets(derivedSecretBytes);
|
DerivedRootSecrets derivedSecrets = new DerivedRootSecrets(derivedSecretBytes);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user