def _makeRelayCrypto(self, secret_input): '''Derive shared key material using HKDF from secret_input. :returns: **oppy.crypto.relaycrypto.RelayCrypto** initialized with shared key data ''' prk = hkdf.hkdf_extract(salt=T_KEY, input_key_material=secret_input, hash=hashlib.sha256) km = hkdf.hkdf_expand(pseudo_random_key=prk, info=M_EXPAND, length=72, hash=hashlib.sha256) df = km[: DIGEST_LEN] db = km[DIGEST_LEN : DIGEST_LEN * 2] kf = km[DIGEST_LEN * 2 : DIGEST_LEN * 2 + KEY_LEN] kb = km[DIGEST_LEN * 2 + KEY_LEN : DIGEST_LEN * 2 + KEY_LEN * 2] f_digest = hashlib.sha1(df) b_digest = hashlib.sha1(db) f_cipher = util.makeAES128CTRCipher(kf) b_cipher = util.makeAES128CTRCipher(kb) return RelayCrypto(forward_digest=f_digest, backward_digest=b_digest, forward_cipher=f_cipher, backward_cipher=b_cipher)
def _makeRelayCrypto(self, secret_input): '''Derive shared key material using HKDF from secret_input. :returns: **oppy.crypto.relaycrypto.RelayCrypto** initialized with shared key data ''' prk = hkdf.hkdf_extract(salt=T_KEY, input_key_material=secret_input, hash=hashlib.sha256) km = hkdf.hkdf_expand(pseudo_random_key=prk, info=M_EXPAND, length=72, hash=hashlib.sha256) df = km[:DIGEST_LEN] db = km[DIGEST_LEN:DIGEST_LEN * 2] kf = km[DIGEST_LEN * 2:DIGEST_LEN * 2 + KEY_LEN] kb = km[DIGEST_LEN * 2 + KEY_LEN:DIGEST_LEN * 2 + KEY_LEN * 2] f_digest = hashlib.sha1(df) b_digest = hashlib.sha1(db) f_cipher = util.makeAES128CTRCipher(kf) b_cipher = util.makeAES128CTRCipher(kb) return RelayCrypto(forward_digest=f_digest, backward_digest=b_digest, forward_cipher=f_cipher, backward_cipher=b_cipher)
def test_makeAES123CTRCipher_iv(self, mock_aes, mock_counter): mock_counter.return_value = 'ctr' mock_aes.return_value = 'ret' ret = util.makeAES128CTRCipher('key', 'iv') mock_counter.assert_called_once_with(128, initial_value='iv') mock_aes.assert_called_once_with('key', AES.MODE_CTR, counter='ctr') self.assertEqual(ret, 'ret')