@@ -71,6 +71,8 @@ type ADNL struct {
7171 recvPriorityAddrVer int32
7272 ourAddrVerOnPeerSide int32
7373
74+ peerID []byte
75+ sharedKey []byte
7476 peerKey ed25519.PublicKey
7577 ourAddresses unsafe.Pointer
7678
@@ -175,6 +177,16 @@ func (a *ADNL) processPacket(packet *PacketContent, fromChannel bool) (err error
175177 if ! fromChannel && packet .From != nil {
176178 a .mx .Lock ()
177179 if a .peerKey == nil {
180+ a .sharedKey , err = keys .SharedKey (a .ourKey , packet .From .Key )
181+ if err != nil {
182+ return err
183+ }
184+
185+ a .peerID , err = tl .Hash (keys.PublicKeyED25519 {Key : packet .From .Key })
186+ if err != nil {
187+ return err
188+ }
189+
178190 a .peerKey = packet .From .Key
179191 }
180192 a .mx .Unlock ()
@@ -735,12 +747,11 @@ func (a *ADNL) GetAddressList() address.List {
735747}
736748
737749func (a * ADNL ) GetID () []byte {
738- id , _ := tl .Hash (keys.PublicKeyED25519 {Key : a .peerKey })
739- return id
750+ return append ([]byte {}, a .peerID ... )
740751}
741752
742753func (a * ADNL ) GetPubKey () ed25519.PublicKey {
743- return a .peerKey
754+ return append (ed25519. PublicKey {}, a .peerKey ... )
744755}
745756
746757func (a * ADNL ) Reinit () {
@@ -825,23 +836,14 @@ func (a *ADNL) createPacket(seqno int64, isResp bool, msgs ...any) ([]byte, erro
825836 hash := sha256 .Sum256 (packetData )
826837 checksum := hash [:]
827838
828- key , err := keys .SharedKey (a .ourKey , a .peerKey )
829- if err != nil {
830- return nil , err
831- }
832-
833- ctr , err := keys .BuildSharedCipher (key , checksum )
839+ ctr , err := keys .BuildSharedCipher (a .sharedKey , checksum )
834840 if err != nil {
835841 return nil , err
836842 }
837843
838844 ctr .XORKeyStream (packetData , packetData )
839845
840- enc , err := tl .Hash (keys.PublicKeyED25519 {Key : a .peerKey })
841- if err != nil {
842- return nil , err
843- }
844- copy (bufData , enc )
846+ copy (bufData , a .peerID )
845847 copy (bufData [32 :], a .ourKey .Public ().(ed25519.PublicKey ))
846848 copy (bufData [64 :], checksum )
847849
0 commit comments