# Path: axolotl/kdf/derivedmessagesecrets.py
# class DerivedMessageSecrets:
#     SIZE = 80
#     CIPHER_KEY_LENGTH = 32
#     MAC_KEY_LENGTH = 32
#     IV_LENGTH = 16
# 
#     def __init__(self, okm):
#         keys = ByteUtil.split(okm,
#                               self.__class__.CIPHER_KEY_LENGTH,
#                               self.__class__.MAC_KEY_LENGTH,
#                               self.__class__.IV_LENGTH)
#         self.cipherKey = keys[0]  # AES
#         self.macKey = keys[1]  # sha256
#         self.iv = keys[2]
# 
#     def getCipherKey(self):
#         return self.cipherKey
# 
#     def getMacKey(self):
#         return self.macKey
# 
#     def getIv(self):
#         return self.iv
# 
# Path: axolotl/kdf/messagekeys.py
# class MessageKeys:
#     def __init__(self, cipherKey, macKey, iv, counter):
#         self.cipherKey = cipherKey
#         self.macKey = macKey
#         self.iv = iv
#         self.counter = counter
# 
#     def getCipherKey(self):
#         return self.cipherKey
# 
#     def getMacKey(self):
#         return self.macKey
# 
#     def getIv(self):
#         return self.iv
# 
#     def getCounter(self):
#         return self.counter


import hmac
import hashlib
from ..kdf.derivedmessagesecrets import DerivedMessageSecrets
from ..kdf.messagekeys import MessageKeys
# -*- coding: utf-8 -*-




class ChainKey:
    MESSAGE_KEY_SEED = bytearray([0x01])
    CHAIN_KEY_SEED = bytearray([0x02])

    def __init__(self, kdf, key, index):
        self.kdf = kdf
        self.key = key
        self.index = index

    def getKey(self):
        return self.key

    def getIndex(self):
        return self.index

    def getNextChainKey(self):
        nextKey = self.getBaseMaterial(self.__class__.CHAIN_KEY_SEED)
        return ChainKey(self.kdf, nextKey, self.index + 1)

    def getMessageKeys(self):
        inputKeyMaterial = self.getBaseMaterial(self.__class__.MESSAGE_KEY_SEED)
        keyMaterialBytes = self.kdf.deriveSecrets(inputKeyMaterial,
                                                  bytearray("WhisperMessageKeys".encode()),
                                                  DerivedMessageSecrets.SIZE)

# Path: axolotl/kdf/derivedmessagesecrets.py
# class DerivedMessageSecrets:
#     SIZE = 80
#     CIPHER_KEY_LENGTH = 32
#     MAC_KEY_LENGTH = 32
#     IV_LENGTH = 16
# 
#     def __init__(self, okm):
#         keys = ByteUtil.split(okm,
#                               self.__class__.CIPHER_KEY_LENGTH,
#                               self.__class__.MAC_KEY_LENGTH,
#                               self.__class__.IV_LENGTH)
#         self.cipherKey = keys[0]  # AES
#         self.macKey = keys[1]  # sha256
#         self.iv = keys[2]
# 
#     def getCipherKey(self):
#         return self.cipherKey
# 
#     def getMacKey(self):
#         return self.macKey
# 
#     def getIv(self):
#         return self.iv
# 
# Path: axolotl/kdf/messagekeys.py
# class MessageKeys:
#     def __init__(self, cipherKey, macKey, iv, counter):
#         self.cipherKey = cipherKey
#         self.macKey = macKey
#         self.iv = iv
#         self.counter = counter
# 
#     def getCipherKey(self):
#         return self.cipherKey
# 
#     def getMacKey(self):
#         return self.macKey
# 
#     def getIv(self):
#         return self.iv
# 
#     def getCounter(self):
#         return self.counter


# Path: axolotl/ratchet/chainkey.py
import hmac
import hashlib
from ..kdf.derivedmessagesecrets import DerivedMessageSecrets
from ..kdf.messagekeys import MessageKeys

# -*- coding: utf-8 -*-




class ChainKey:
    MESSAGE_KEY_SEED = bytearray([0x01])
    CHAIN_KEY_SEED = bytearray([0x02])

    def __init__(self, kdf, key, index):
        self.kdf = kdf
        self.key = key
        self.index = index

    def getKey(self):
        return self.key

    def getIndex(self):
        return self.index

    def getNextChainKey(self):
        nextKey = self.getBaseMaterial(self.__class__.CHAIN_KEY_SEED)
        return ChainKey(self.kdf, nextKey, self.index + 1)

    def getMessageKeys(self):
        inputKeyMaterial = self.getBaseMaterial(self.__class__.MESSAGE_KEY_SEED)
        keyMaterialBytes = self.kdf.deriveSecrets(inputKeyMaterial,
                                                  bytearray("WhisperMessageKeys".encode()),
                                                  DerivedMessageSecrets.SIZE)

        keyMaterial = DerivedMessageSecrets(keyMaterialBytes)