From dc1c5806c9e8cbe314149259d741d8fb7098e193 Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Wed, 26 Feb 2025 10:50:35 +0800 Subject: [PATCH] internal/bigmod: use clear() --- ecdh/ecdh_test.go | 4 +--- internal/bigmod/nat.go | 10 ++-------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/ecdh/ecdh_test.go b/ecdh/ecdh_test.go index bf348ab..85f4ff8 100644 --- a/ecdh/ecdh_test.go +++ b/ecdh/ecdh_test.go @@ -374,9 +374,7 @@ type zr struct{} // Read replaces the contents of dst with zeros. It is safe for concurrent use. func (zr) Read(dst []byte) (n int, err error) { - for i := range dst { - dst[i] = 0 - } + clear(dst) return len(dst), nil } diff --git a/internal/bigmod/nat.go b/internal/bigmod/nat.go index 6cd801e..128a40c 100644 --- a/internal/bigmod/nat.go +++ b/internal/bigmod/nat.go @@ -85,10 +85,7 @@ func (x *Nat) expand(n int) *Nat { return x } extraLimbs := x.limbs[len(x.limbs):n] - // clear(extraLimbs) - for i := range extraLimbs { - extraLimbs[i] = 0 - } + clear(extraLimbs) x.limbs = x.limbs[:n] return x } @@ -99,10 +96,7 @@ func (x *Nat) reset(n int) *Nat { x.limbs = make([]uint, n) return x } - // clear(x.limbs) - for i := range x.limbs { - x.limbs[i] = 0 - } + clear(x.limbs) x.limbs = x.limbs[:n] return x }