p2p/rlpx: optimize XOR operation using bitutil.XORBytes (#32217)

Replace manual byte-by-byte XOR implementation with the optimized
bitutil.XORBytes function. This improves performance by using word-sized
operations on supported architectures while maintaining the same
functionality. The optimized version processes data in bulk rather than
one byte at a time

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
Micke 2025-07-22 23:06:48 +02:00 committed by GitHub
parent 264c06a72c
commit a7efdcbf09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -33,6 +33,7 @@ import (
"net" "net"
"time" "time"
"github.com/ethereum/go-ethereum/common/bitutil"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/crypto/ecies"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
@ -676,8 +677,6 @@ func exportPubkey(pub *ecies.PublicKey) []byte {
func xor(one, other []byte) (xor []byte) { func xor(one, other []byte) (xor []byte) {
xor = make([]byte, len(one)) xor = make([]byte, len(one))
for i := 0; i < len(one); i++ { bitutil.XORBytes(xor, one, other)
xor[i] = one[i] ^ other[i]
}
return xor return xor
} }