示例#1
0
文件: auth.py 项目: subinps/pyrogram
 def pack(data: TLObject) -> bytes:
     return (
         bytes(8)
         + Long(MsgId())
         + Int(len(data.write()))
         + data.write()
     )
示例#2
0
文件: mtproto.py 项目: Alimov-IQ/Bots
def pack(message: Message, salt: int, session_id: bytes, auth_key: bytes, auth_key_id: bytes) -> bytes:
    data = Long(salt) + session_id + message.write()
    padding = urandom(-(len(data) + 12) % 16 + 12)

    # 88 = 88 + 0 (outgoing message)
    msg_key_large = sha256(auth_key[88: 88 + 32] + data + padding).digest()
    msg_key = msg_key_large[8:24]
    aes_key, aes_iv = kdf(auth_key, msg_key, True)

    return auth_key_id + msg_key + aes.ige256_encrypt(data + padding, aes_key, aes_iv)