Beispiel #1
0
        public MessageKeys getMessageKeys()
        {
            byte[] inputKeyMaterial           = getBaseMaterial(MESSAGE_KEY_SEED);
            byte[] keyMaterialBytes           = kdf.deriveSecrets(inputKeyMaterial, Encoding.UTF8.GetBytes("WhisperMessageKeys"), DerivedMessageSecrets.SIZE);
            DerivedMessageSecrets keyMaterial = new DerivedMessageSecrets(keyMaterialBytes);

            return(new MessageKeys(keyMaterial.getCipherKey(), keyMaterial.getMacKey(), keyMaterial.getIv(), index));
        }
        private static DerivedKeys calculateDerivedKeys(uint sessionVersion, byte[] masterSecret)
        {
            HKDF kdf = HKDF.createFor(sessionVersion);

            byte[]   derivedSecretBytes = kdf.deriveSecrets(masterSecret, Encoding.UTF8.GetBytes("WhisperText"), 64);
            byte[][] derivedSecrets     = ByteUtil.split(derivedSecretBytes, 32, 32);

            return(new DerivedKeys(new RootKey(kdf, derivedSecrets[0]),
                                   new ChainKey(kdf, derivedSecrets[1], 0)));
        }
Beispiel #3
0
        public Pair <RootKey, ChainKey> createChain(ECPublicKey theirRatchetKey, ECKeyPair ourRatchetKey)
        {
            byte[]             sharedSecret       = Curve.calculateAgreement(theirRatchetKey, ourRatchetKey.getPrivateKey());
            byte[]             derivedSecretBytes = kdf.deriveSecrets(sharedSecret, key, Encoding.UTF8.GetBytes("WhisperRatchet"), DerivedRootSecrets.SIZE);
            DerivedRootSecrets derivedSecrets     = new DerivedRootSecrets(derivedSecretBytes);

            RootKey  newRootKey  = new RootKey(kdf, derivedSecrets.getRootKey());
            ChainKey newChainKey = new ChainKey(kdf, derivedSecrets.getChainKey(), 0);

            return(new Pair <RootKey, ChainKey>(newRootKey, newChainKey));
        }