Search in sources :

Example 1 with HKDF

use of im.actor.runtime.crypto.primitives.kdf.HKDF in project actor-platform by actorapp.

the class RatchetRootChainKey method makeRootChainKey.

public static byte[] makeRootChainKey(RatchetPrivateKey ownEphermal, RatchetPublicKey theirEphermal, byte[] masterSecret) {
    byte[] ecRes = Curve25519.calculateAgreement(ownEphermal.getPrivateKey(), theirEphermal.getKey());
    HKDF hkdf = new HKDF(Crypto.createSHA256());
    return hkdf.deriveSecrets(ecRes, masterSecret, "ActorRatchet".getBytes(), 32);
}
Also used : HKDF(im.actor.runtime.crypto.primitives.kdf.HKDF)

Example 2 with HKDF

use of im.actor.runtime.crypto.primitives.kdf.HKDF in project actor-platform by actorapp.

the class RatchetMessageKey method buildKey.

public static ActorBoxKey buildKey(byte[] rootChainKey, int index) {
    HMAC hmac = new HMAC(rootChainKey, Crypto.createSHA256());
    byte[] indx = ByteStrings.intToBytes(index);
    hmac.update(indx, 0, indx.length);
    byte[] messageKey = new byte[32];
    hmac.doFinal(messageKey, 0);
    byte[] messageKeyExt = new HKDF(Crypto.createSHA256()).deriveSecrets(messageKey, 128);
    byte[] aesCipherKey = ByteStrings.substring(messageKeyExt, 0, 32);
    byte[] aesMacKey = ByteStrings.substring(messageKeyExt, 32, 32);
    byte[] kuzCipherKey = ByteStrings.substring(messageKeyExt, 64, 32);
    byte[] kuzMacKey = ByteStrings.substring(messageKeyExt, 96, 32);
    return new ActorBoxKey(aesCipherKey, aesMacKey, kuzCipherKey, kuzMacKey);
}
Also used : HKDF(im.actor.runtime.crypto.primitives.kdf.HKDF) HMAC(im.actor.runtime.crypto.primitives.hmac.HMAC) ActorBoxKey(im.actor.runtime.crypto.box.ActorBoxKey)

Aggregations

HKDF (im.actor.runtime.crypto.primitives.kdf.HKDF)2 ActorBoxKey (im.actor.runtime.crypto.box.ActorBoxKey)1 HMAC (im.actor.runtime.crypto.primitives.hmac.HMAC)1