all: use min/max/clear from go1.21 (#29307)

pull/28751/head^2
Martin HS 6 months ago committed by GitHub
parent bca6c40709
commit 14eb8967be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      accounts/keystore/keystore.go
  2. 4
      core/vm/analysis_test.go
  3. 4
      crypto/crypto.go
  4. 8
      crypto/secp256k1/scalar_mult_cgo.go
  5. 8
      eth/protocols/eth/peer.go
  6. 9
      internal/era/era.go
  7. 7
      metrics/sample_test.go
  8. 7
      p2p/discover/common.go
  9. 4
      p2p/discover/v5wire/crypto.go
  10. 4
      rlp/decode.go

@ -500,7 +500,5 @@ func (ks *KeyStore) isUpdating() bool {
// zeroKey zeroes a private key in memory.
func zeroKey(k *ecdsa.PrivateKey) {
b := k.D.Bits()
for i := range b {
b[i] = 0
}
clear(b)
}

@ -93,9 +93,7 @@ func BenchmarkJumpdestOpAnalysis(bench *testing.B) {
bits := make(bitvec, len(code)/8+1+4)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for j := range bits {
bits[j] = 0
}
clear(bits)
codeBitmapInternal(code, bits)
}
}

@ -287,7 +287,5 @@ func PubkeyToAddress(p ecdsa.PublicKey) common.Address {
}
func zeroBytes(bytes []byte) {
for i := range bytes {
bytes[i] = 0
}
clear(bytes)
}

@ -44,12 +44,8 @@ func (BitCurve *BitCurve) ScalarMult(Bx, By *big.Int, scalar []byte) (*big.Int,
// Unpack the result and clear temporaries.
x := new(big.Int).SetBytes(point[:32])
y := new(big.Int).SetBytes(point[32:])
for i := range point {
point[i] = 0
}
for i := range padded {
scalar[i] = 0
}
clear(point)
clear(scalar)
if res != 1 {
return nil, nil
}

@ -42,14 +42,6 @@ const (
maxQueuedTxAnns = 4096
)
// max is a helper function which returns the larger of the two given integers.
func max(a, b int) int {
if a > b {
return a
}
return b
}
// Peer is a collection of relevant information we have about a `eth` peer.
type Peer struct {
id string // Unique ID for the peer, cached

@ -229,7 +229,7 @@ func (e *Era) readOffset(n uint64) (int64, error) {
)
e.mu.Lock()
defer e.mu.Unlock()
clearBuffer(e.buf[:])
clear(e.buf[:])
if _, err := e.f.ReadAt(e.buf[:], offOffset); err != nil {
return 0, err
}
@ -248,13 +248,6 @@ func newSnappyReader(e *e2store.Reader, expectedType uint16, off int64) (io.Read
return snappy.NewReader(r), int64(n), err
}
// clearBuffer zeroes out the buffer.
func clearBuffer(buf []byte) {
for i := 0; i < len(buf); i++ {
buf[i] = 0
}
}
// metadata wraps the metadata in the block index.
type metadata struct {
start uint64

@ -87,13 +87,6 @@ func BenchmarkUniformSample1028(b *testing.B) {
benchmarkSample(b, NewUniformSample(1028))
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
func TestExpDecaySample(t *testing.T) {
for _, tc := range []struct {
reservoirSize int

@ -92,10 +92,3 @@ type ReadPacket struct {
Data []byte
Addr *net.UDPAddr
}
func min(x, y int) int {
if x > y {
return y
}
return x
}

@ -129,9 +129,7 @@ func deriveKeys(hash hashFn, priv *ecdsa.PrivateKey, pub *ecdsa.PublicKey, n1, n
sec := session{writeKey: make([]byte, aesKeySize), readKey: make([]byte, aesKeySize)}
kdf.Read(sec.writeKey)
kdf.Read(sec.readKey)
for i := range eph {
eph[i] = 0
}
clear(eph)
return &sec
}

@ -1105,9 +1105,7 @@ func (s *Stream) readUint(size byte) (uint64, error) {
return uint64(b), err
default:
buffer := s.uintbuf[:8]
for i := range buffer {
buffer[i] = 0
}
clear(buffer)
start := int(8 - size)
if err := s.readFull(buffer[start:]); err != nil {
return 0, err

Loading…
Cancel
Save