Skip to main content

Module bind_temp_key

Module bind_temp_key 

Source
Expand description

Build the encrypted_message payload for auth.bindTempAuthKey.

The inner message must be encrypted with the permanent auth key using the legacy MTProto v1 scheme (SHA-1-based key derivation + AES-256-IGE), NOT the normal MTProto 2.0 (SHA-256) scheme.

Wire layout of encrypted_message:

  perm_key_id (8 bytes)
  msg_key     (16 bytes)  = SHA1(plaintext_no_pad)[4..20]
  ciphertext  (N bytes)   = AES-IGE(plaintext, derived from perm_key + msg_key)

plaintext =
  server_salt   (8 bytes, random)
  session_id    (8 bytes, random)
  msg_id        (8 bytes)
  seq_no        (4 bytes, = 0)
  data_len      (4 bytes)
  bind_auth_key_inner (40 bytes)
  padding       (0-15 bytes to reach 16-byte alignment)

Functionsยง

encrypt_bind_inner
Build the encrypted_message bytes for auth.bindTempAuthKey.
gen_msg_id
Generate a monotonic MTProto message ID from the current system clock.
serialize_bind_temp_auth_key
Serialize auth.bindTempAuthKey#cdd42a05 to raw TL bytes.