package cryptoimport (// #nosec)// DecryptExchangeAnswer decrypts messages created during key exchange.func (, , []byte) ( []byte, error) {// Decrypting inner data. , := aes.NewCipher()if != nil {returnnil, errors.Wrap(, "create aes cipher") } := make([]byte, len())// Checking length. Invalid length will lead to panic in CryptBlocks.iflen()%.BlockSize() != 0 {returnnil, errors.Errorf("invalid len of data_with_hash (%d %% 16 != 0)", len()) }ige.DecryptBlocks(, , , ) = GuessDataWithHash()if == nil {// Most common cause of this error is invalid crypto implementation, // i.e. invalid keys are used to decrypt payload which lead to // decrypt failure, so data does not match sha1 with any padding.returnnil, errors.New("guess data from data_with_hash") }return}// EncryptExchangeAnswer encrypts messages created during key exchange.func ( io.Reader, , , []byte) ( []byte, error) { , := aes.NewCipher()if != nil {returnnil, errors.Wrap(, "create aes cipher") } , := DataWithHash(, )if != nil {returnnil, errors.Wrap(, "get answer with hash") } = make([]byte, len())ige.EncryptBlocks(, , , )return}// NonceHash1 computes nonce_hash_1.// See https://core.telegram.org/mtproto/auth_key#dh-key-exchange-complete.func ( bin.Int256, Key) ( bin.Int128) {var []byte = append(, [:]...) = append(, 1) = append(, sha([:])[0:8]...) = sha()[4:20]copy([:], )return}func ( []byte) []byte { := sha1.Sum() // #nosecreturn [:]}
The pages are generated with Goldsv0.6.7. (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 @Go100and1 (reachable from the left QR code) to get the latest news of Golds.