def init_aes(shared_secret, nonce):
""" Initialize AES instance
:param hex shared_secret: Shared Secret to use as encryption key
:param int nonce: Random nonce
:return: AES instance and checksum of the encryption key
:rtype: length 2 tuple
"""
" Seed "
ss = unhexlify(shared_secret)
n = struct.pack("<Q", int(nonce))
encryption_key = hashlib.sha512(n + ss).hexdigest()
" Check'sum' "
check = hashlib.sha256(unhexlify(encryption_key)).digest()
check = struct.unpack_from("<I", check[:4])[0]
" AES "
key = unhexlify(encryption_key[0:64])
iv = unhexlify(encryption_key[64:96])
return AES.new(key, AES.MODE_CBC, iv), check
评论列表
文章目录