From afc3b0840598d467599708bf0beeb0abe1f7b15e Mon Sep 17 00:00:00 2001
From: GitHub Action Often, a 17-byte version of the secret can be found: this simply indicates that the client should use a specific MTProto transport (based on the first byte, usually it's The extracted encryption and decryption keys must be concatenated with the secret (the first byte of which should be ignored if it's the 17-byte version), and the SHA256 hash of such string should be used as encryption/decryption key. The obtained encryption and decryption key/IV pairs must then be used with AES-256-CTR to encrypt and decrypt all outgoing and incoming payloads.0xdd
, to indicate that the padded intermediate protocol should be used 0xdddddddd
; however, clients should default to the padded intermediate transport whenever an additional byte in the secret is encountered).
-The encryption and decryption counters must be reused for every payload, until the TCP/WS connection is closed.
-In other words, reuse the same AES-256-CTR OpenSSL instance until the connection is closed.
+In other words, reuse the two encryption and decryption AES-256-CTR OpenSSL instances until the connection is closed.
The first thing that must be encrypted using the encryption key is the initialization payload itself.
Then bytes 56-64
of the encrypted initialization payload are substituted in the original initialization payload: this is the part that contains the constant MTProto transport protocol identifier and the DC ID (only for MTProxies).
The final initialization payload must then be sent in the socket as first 64 bytes after the TCP handshake.