From f7b71e5e281235ac7d2daad3dabec6daa64b76ff Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Tue, 26 Nov 2013 09:08:52 -0800 Subject: [PATCH] Add info to MessageKey HKDF, change order of RootKey derivation. --- .../whispersystems/textsecure/crypto/ratchet/ChainKey.java | 2 +- .../textsecure/crypto/ratchet/RatchetingSession.java | 4 ++-- .../org/whispersystems/textsecure/crypto/ratchet/RootKey.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/src/org/whispersystems/textsecure/crypto/ratchet/ChainKey.java b/library/src/org/whispersystems/textsecure/crypto/ratchet/ChainKey.java index 0b17a30e74..c3c8b26ffa 100644 --- a/library/src/org/whispersystems/textsecure/crypto/ratchet/ChainKey.java +++ b/library/src/org/whispersystems/textsecure/crypto/ratchet/ChainKey.java @@ -38,7 +38,7 @@ public class ChainKey { public MessageKeys getMessageKeys() { HKDF kdf = new HKDF(); byte[] inputKeyMaterial = getBaseMaterial(MESSAGE_KEY_SEED); - DerivedSecrets keyMaterial = kdf.deriveSecrets(inputKeyMaterial, null); + DerivedSecrets keyMaterial = kdf.deriveSecrets(inputKeyMaterial, "WhisperMessageKeys".getBytes()); return new MessageKeys(keyMaterial.getCipherKey(), keyMaterial.getMacKey(), index); } diff --git a/library/src/org/whispersystems/textsecure/crypto/ratchet/RatchetingSession.java b/library/src/org/whispersystems/textsecure/crypto/ratchet/RatchetingSession.java index 456416bc58..313ccbebe4 100644 --- a/library/src/org/whispersystems/textsecure/crypto/ratchet/RatchetingSession.java +++ b/library/src/org/whispersystems/textsecure/crypto/ratchet/RatchetingSession.java @@ -71,8 +71,8 @@ public class RatchetingSession { sessionRecord.setRootKey(sendingChain.first); } - public static Pair calculate3DHE(ECKeyPair ourEphemeral, ECPublicKey theirEphemeral, - IdentityKeyPair ourIdentity, IdentityKey theirIdentity) + private static Pair calculate3DHE(ECKeyPair ourEphemeral, ECPublicKey theirEphemeral, + IdentityKeyPair ourIdentity, IdentityKey theirIdentity) throws InvalidKeyException { try { diff --git a/library/src/org/whispersystems/textsecure/crypto/ratchet/RootKey.java b/library/src/org/whispersystems/textsecure/crypto/ratchet/RootKey.java index 2d8a4d521d..5ba19bc138 100644 --- a/library/src/org/whispersystems/textsecure/crypto/ratchet/RootKey.java +++ b/library/src/org/whispersystems/textsecure/crypto/ratchet/RootKey.java @@ -30,8 +30,8 @@ public class RootKey { HKDF kdf = new HKDF(); byte[] sharedSecret = Curve.calculateAgreement(theirEphemeral, ourEphemeral.getPrivateKey()); DerivedSecrets keys = kdf.deriveSecrets(sharedSecret, key, "WhisperRatchet".getBytes()); - RootKey newRootKey = new RootKey(keys.getMacKey().getEncoded()); - ChainKey newChainKey = new ChainKey(keys.getCipherKey().getEncoded(), 0); + RootKey newRootKey = new RootKey(keys.getCipherKey().getEncoded()); + ChainKey newChainKey = new ChainKey(keys.getMacKey().getEncoded(), 0); return new Pair(newRootKey, newChainKey); }