From 759bb4c0b9a8b39e9692271e6b52408e7fb2af42 Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Tue, 4 Mar 2025 11:30:20 +0800 Subject: [PATCH] internal/sm2ec: make SetBytes constant time, use latest golang features #309 --- internal/subtle/constant_time_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/subtle/constant_time_test.go b/internal/subtle/constant_time_test.go index e36e267..3546113 100644 --- a/internal/subtle/constant_time_test.go +++ b/internal/subtle/constant_time_test.go @@ -2,13 +2,18 @@ package subtle import ( "bytes" - "crypto/rand" "fmt" + "math/rand/v2" "testing" + "time" + + "github.com/emmansun/gmsm/internal/byteorder" ) func TestConstantTimeLessOrEqBytes(t *testing.T) { - r := rand.Reader + seed := make([]byte, 32) + byteorder.BEPutUint64(seed, uint64(time.Now().UnixNano())) + r := rand.NewChaCha8([32]byte(seed)) for l := 0; l < 20; l++ { a := make([]byte, l) b := make([]byte, l)