Source File
temp_keys.go
Belonging Package
github.com/gotd/td/crypto
package cryptoimport (// #nosec)// sha1Bytes returns SHA1(a + b).func (, []byte) []byte {:= make([]byte, 0, len()+len())= append(, ...)= append(, ...):= sha1.Sum() // #nosecreturn [:]}// TempAESKeys returns tmp_aes_key and tmp_aes_iv based on new_nonce and// server_nonce as defined in "Creating an Authorization Key".//// new_nonce (int256) and server_nonce (int128) are fixed-length byte strings// of 32 and 16 bytes. They must be hashed at their full length: see// https://core.telegram.org/mtproto/auth_key#presenting-proof-of-work-server-authentication//// They are passed here as *big.Int, so they are first serialized back to their// canonical fixed length with FillBytes. Using big.Int.Bytes() instead would// strip leading zero bytes, and whenever new_nonce or server_nonce starts with// 0x00 (about 1/256 of the time each) the SHA1 input would be a byte short and// the derived tmp_aes_key/tmp_aes_iv would be wrong, making the server_DH_params// answer impossible to decrypt for a spec-compliant peer.func (, *big.Int) (, []byte) {:= make([]byte, 32).FillBytes():= make([]byte, 16).FillBytes()// tmp_aes_key := SHA1(new_nonce + server_nonce) + substr(SHA1(server_nonce + new_nonce), 0, 12)= append(, sha1Bytes(, )...)= append(, sha1Bytes(, )[:12]...)// tmp_aes_iv := substr(SHA1(server_nonce + new_nonce), 12, 8) + SHA1(new_nonce + new_nonce) + substr(new_nonce, 0, 4)= append(, sha1Bytes(, )[12:12+8]...)= append(, sha1Bytes(, )...)= append(, [:4]...)return ,}
![]() |
The pages are generated with Golds v0.8.4. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |