mtproto v57.3.0-beta MTProto.Crypto
Summary
Functions
auth_key_hash is computed := 64 lower-order bits of SHA1(auth_key)
sha1_a = SHA1(msg_key + substr(auth_key, x, 32)); sha1_b = SHA1(substr(auth_key, 32+x, 16) + msg_key + substr(auth_key, 48+x, 16)); sha1_с = SHA1(substr(auth_key, 64+x, 32) + msg_key); sha1_d = SHA1(msg_key + substr(auth_key, 96+x, 32)); aes_key = substr(sha1_a, 0, 8) + substr(sha1_b, 8, 12) + substr(sha1_c, 4, 12); aes_iv = substr(sha1_a, 8, 12) + substr(sha1_b, 0, 8) + substr(sha1_c, 16, 4) + substr(sha1_d, 0, 8);
new_nonce_hash1
, new_nonce_hash2
, and new_nonce_hash3
are obtained
as the 128 lower-order bits of SHA1 of the byte string derived from the
new_nonce string by adding a single byte with the value of 1, 2, or 3,
and followed by another 8 bytes with auth_key_aux_hash
server_salt := substr(new_nonce, 0, 8) XOR substr(server_nonce, 0, 8)
Functions
auth_key_hash is computed := 64 lower-order bits of SHA1(auth_key).
The server checks whether there already is another key with the same
auth_key_hash
and responds in one of the following ways.
sha1_a = SHA1(msg_key + substr(auth_key, x, 32)); sha1_b = SHA1(substr(auth_key, 32+x, 16) + msg_key + substr(auth_key, 48+x, 16)); sha1_с = SHA1(substr(auth_key, 64+x, 32) + msg_key); sha1_d = SHA1(msg_key + substr(auth_key, 96+x, 32)); aes_key = substr(sha1_a, 0, 8) + substr(sha1_b, 8, 12) + substr(sha1_c, 4, 12); aes_iv = substr(sha1_a, 8, 12) + substr(sha1_b, 0, 8) + substr(sha1_c, 16, 4) + substr(sha1_d, 0, 8);
new_nonce_hash1
, new_nonce_hash2
, and new_nonce_hash3
are obtained
as the 128 lower-order bits of SHA1 of the byte string derived from the
new_nonce string by adding a single byte with the value of 1, 2, or 3,
and followed by another 8 bytes with auth_key_aux_hash.
Different values are required to prevent an intruder from changing server
response dh_gen_ok
into dh_gen_retry
.
server_salt := substr(new_nonce, 0, 8) XOR substr(server_nonce, 0, 8)
https://core.telegram.org/mtproto/auth_key#dh-key-exchange-complete (9)