diff --git a/ecc/bls12-377/fp/element_test.go b/ecc/bls12-377/fp/element_test.go index cbf950f679..f6a766f15d 100644 --- a/ecc/bls12-377/fp/element_test.go +++ b/ecc/bls12-377/fp/element_test.go @@ -2368,7 +2368,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2412,7 +2412,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2472,13 +2472,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2748,7 +2748,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2758,7 +2758,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2783,7 +2783,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2792,7 +2792,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bls12-377/fr/element_test.go b/ecc/bls12-377/fr/element_test.go index 4cf60880fb..7a4fa43fc9 100644 --- a/ecc/bls12-377/fr/element_test.go +++ b/ecc/bls12-377/fr/element_test.go @@ -2354,7 +2354,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2396,7 +2396,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2454,13 +2454,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2728,7 +2728,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2738,7 +2738,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2763,7 +2763,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2772,7 +2772,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bls12-377/hash_to_g1_test.go b/ecc/bls12-377/hash_to_g1_test.go index a5a45d5f05..467aa1c55c 100644 --- a/ecc/bls12-377/hash_to_g1_test.go +++ b/ecc/bls12-377/hash_to_g1_test.go @@ -196,7 +196,7 @@ func BenchmarkEncodeToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG1(bytes, dst); err != nil { b.Fail() @@ -212,7 +212,7 @@ func BenchmarkHashToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG1(bytes, dst); err != nil { b.Fail() diff --git a/ecc/bls12-377/hash_to_g2_test.go b/ecc/bls12-377/hash_to_g2_test.go index 79a9e8979b..4534802343 100644 --- a/ecc/bls12-377/hash_to_g2_test.go +++ b/ecc/bls12-377/hash_to_g2_test.go @@ -198,7 +198,7 @@ func BenchmarkEncodeToG2(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG2(bytes, dst); err != nil { b.Fail() @@ -214,7 +214,7 @@ func BenchmarkHashToG2(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG2(bytes, dst); err != nil { b.Fail() diff --git a/ecc/bls12-377/marshal_test.go b/ecc/bls12-377/marshal_test.go index 87dd70bf02..02004b7c87 100644 --- a/ecc/bls12-377/marshal_test.go +++ b/ecc/bls12-377/marshal_test.go @@ -54,12 +54,12 @@ func TestEncoder(t *testing.T) { var inK fr.Vector // set values of inputs - inA = rand.Uint64() + inA = rand.Uint64() //#nosec G404 weak rng is fine here inB.SetRandom() inC.SetRandom() - inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) + inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here // inE --> infinity - inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) + inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here inG = make([]G1Affine, 2) inH = make([]G2Affine, 0) inG[1] = inD @@ -219,7 +219,7 @@ func TestIsCompressed(t *testing.T) { func TestG1AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG1AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G1Affine buf[0] = 0b111 << 5 @@ -332,7 +332,7 @@ func TestG1AffineSerialization(t *testing.T) { func TestG2AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG2AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G2Affine buf[0] = 0b111 << 5 @@ -506,7 +506,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fp.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bls12-377/multiexp_test.go b/ecc/bls12-377/multiexp_test.go index f07f32dd16..16c498e01b 100644 --- a/ecc/bls12-377/multiexp_test.go +++ b/ecc/bls12-377/multiexp_test.go @@ -59,10 +59,10 @@ func TestMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -244,10 +244,10 @@ func TestCrossMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) @@ -475,10 +475,10 @@ func TestMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -658,10 +658,10 @@ func TestCrossMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) diff --git a/ecc/bls12-377/twistededwards/eddsa/eddsa_test.go b/ecc/bls12-377/twistededwards/eddsa/eddsa_test.go index 2c2148143a..f8681709b6 100644 --- a/ecc/bls12-377/twistededwards/eddsa/eddsa_test.go +++ b/ecc/bls12-377/twistededwards/eddsa/eddsa_test.go @@ -59,7 +59,7 @@ func Example() { func TestSerialization(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here privKey1, err := GenerateKey(r) if err != nil { @@ -101,7 +101,7 @@ func TestSerialization(t *testing.T) { func TestEddsaMIMC(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here // create eddsa obj and sign a message privKey, err := GenerateKey(r) @@ -144,7 +144,7 @@ func TestEddsaMIMC(t *testing.T) { func TestEddsaSHA256(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := sha256.New() @@ -187,7 +187,7 @@ func TestEddsaSHA256(t *testing.T) { func BenchmarkVerify(b *testing.B) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := hash.MIMC_BLS12_377.New() diff --git a/ecc/bls12-377/twistededwards/point_test.go b/ecc/bls12-377/twistededwards/point_test.go index 950ea15ac7..e4b5c5c0b6 100644 --- a/ecc/bls12-377/twistededwards/point_test.go +++ b/ecc/bls12-377/twistededwards/point_test.go @@ -735,7 +735,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fr.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bls12-378/fp/element_test.go b/ecc/bls12-378/fp/element_test.go index 40d1014873..a1b3d1b190 100644 --- a/ecc/bls12-378/fp/element_test.go +++ b/ecc/bls12-378/fp/element_test.go @@ -2368,7 +2368,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2412,7 +2412,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2472,13 +2472,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2748,7 +2748,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2758,7 +2758,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2783,7 +2783,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2792,7 +2792,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bls12-378/fr/element_test.go b/ecc/bls12-378/fr/element_test.go index 6372c7f19a..f15b116c68 100644 --- a/ecc/bls12-378/fr/element_test.go +++ b/ecc/bls12-378/fr/element_test.go @@ -2354,7 +2354,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2396,7 +2396,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2454,13 +2454,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2728,7 +2728,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2738,7 +2738,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2763,7 +2763,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2772,7 +2772,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bls12-378/hash_to_g1_test.go b/ecc/bls12-378/hash_to_g1_test.go index 74040eb56b..bb5795bafc 100644 --- a/ecc/bls12-378/hash_to_g1_test.go +++ b/ecc/bls12-378/hash_to_g1_test.go @@ -196,7 +196,7 @@ func BenchmarkEncodeToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG1(bytes, dst); err != nil { b.Fail() @@ -212,7 +212,7 @@ func BenchmarkHashToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG1(bytes, dst); err != nil { b.Fail() diff --git a/ecc/bls12-378/marshal_test.go b/ecc/bls12-378/marshal_test.go index 89693623b4..ef0d65dd2b 100644 --- a/ecc/bls12-378/marshal_test.go +++ b/ecc/bls12-378/marshal_test.go @@ -54,12 +54,12 @@ func TestEncoder(t *testing.T) { var inK fr.Vector // set values of inputs - inA = rand.Uint64() + inA = rand.Uint64() //#nosec G404 weak rng is fine here inB.SetRandom() inC.SetRandom() - inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) + inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here // inE --> infinity - inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) + inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here inG = make([]G1Affine, 2) inH = make([]G2Affine, 0) inG[1] = inD @@ -219,7 +219,7 @@ func TestIsCompressed(t *testing.T) { func TestG1AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG1AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G1Affine buf[0] = 0b111 << 5 @@ -332,7 +332,7 @@ func TestG1AffineSerialization(t *testing.T) { func TestG2AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG2AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G2Affine buf[0] = 0b111 << 5 @@ -506,7 +506,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fp.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bls12-378/multiexp_test.go b/ecc/bls12-378/multiexp_test.go index bffa3a5d19..f84127642a 100644 --- a/ecc/bls12-378/multiexp_test.go +++ b/ecc/bls12-378/multiexp_test.go @@ -59,10 +59,10 @@ func TestMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -244,10 +244,10 @@ func TestCrossMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) @@ -475,10 +475,10 @@ func TestMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -658,10 +658,10 @@ func TestCrossMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) diff --git a/ecc/bls12-378/twistededwards/eddsa/eddsa_test.go b/ecc/bls12-378/twistededwards/eddsa/eddsa_test.go index 14ebba1f1c..cd91303d3b 100644 --- a/ecc/bls12-378/twistededwards/eddsa/eddsa_test.go +++ b/ecc/bls12-378/twistededwards/eddsa/eddsa_test.go @@ -59,7 +59,7 @@ func Example() { func TestSerialization(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here privKey1, err := GenerateKey(r) if err != nil { @@ -101,7 +101,7 @@ func TestSerialization(t *testing.T) { func TestEddsaMIMC(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here // create eddsa obj and sign a message privKey, err := GenerateKey(r) @@ -144,7 +144,7 @@ func TestEddsaMIMC(t *testing.T) { func TestEddsaSHA256(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := sha256.New() @@ -187,7 +187,7 @@ func TestEddsaSHA256(t *testing.T) { func BenchmarkVerify(b *testing.B) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := hash.MIMC_BLS12_378.New() diff --git a/ecc/bls12-378/twistededwards/point_test.go b/ecc/bls12-378/twistededwards/point_test.go index b3baa3e279..f5ae6f1704 100644 --- a/ecc/bls12-378/twistededwards/point_test.go +++ b/ecc/bls12-378/twistededwards/point_test.go @@ -735,7 +735,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fr.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bls12-381/bandersnatch/eddsa/eddsa_test.go b/ecc/bls12-381/bandersnatch/eddsa/eddsa_test.go index 890b0980be..7541836fa0 100644 --- a/ecc/bls12-381/bandersnatch/eddsa/eddsa_test.go +++ b/ecc/bls12-381/bandersnatch/eddsa/eddsa_test.go @@ -59,7 +59,7 @@ func Example() { func TestSerialization(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here privKey1, err := GenerateKey(r) if err != nil { @@ -101,7 +101,7 @@ func TestSerialization(t *testing.T) { func TestEddsaMIMC(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here // create eddsa obj and sign a message privKey, err := GenerateKey(r) @@ -144,7 +144,7 @@ func TestEddsaMIMC(t *testing.T) { func TestEddsaSHA256(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := sha256.New() @@ -187,7 +187,7 @@ func TestEddsaSHA256(t *testing.T) { func BenchmarkVerify(b *testing.B) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := hash.MIMC_BLS12_381.New() diff --git a/ecc/bls12-381/bandersnatch/point_test.go b/ecc/bls12-381/bandersnatch/point_test.go index d8b8fbc9ca..95cc832be8 100644 --- a/ecc/bls12-381/bandersnatch/point_test.go +++ b/ecc/bls12-381/bandersnatch/point_test.go @@ -735,7 +735,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fr.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bls12-381/fp/element_test.go b/ecc/bls12-381/fp/element_test.go index 38517f4ced..f3006b3f64 100644 --- a/ecc/bls12-381/fp/element_test.go +++ b/ecc/bls12-381/fp/element_test.go @@ -2368,7 +2368,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2412,7 +2412,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2472,13 +2472,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2748,7 +2748,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2758,7 +2758,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2783,7 +2783,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2792,7 +2792,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bls12-381/fr/element_test.go b/ecc/bls12-381/fr/element_test.go index 85fa755e20..28ad95a42a 100644 --- a/ecc/bls12-381/fr/element_test.go +++ b/ecc/bls12-381/fr/element_test.go @@ -2354,7 +2354,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2396,7 +2396,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2454,13 +2454,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2728,7 +2728,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2738,7 +2738,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2763,7 +2763,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2772,7 +2772,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bls12-381/hash_to_g1_test.go b/ecc/bls12-381/hash_to_g1_test.go index 9ace94cccf..6253f705c2 100644 --- a/ecc/bls12-381/hash_to_g1_test.go +++ b/ecc/bls12-381/hash_to_g1_test.go @@ -196,7 +196,7 @@ func BenchmarkEncodeToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG1(bytes, dst); err != nil { b.Fail() @@ -212,7 +212,7 @@ func BenchmarkHashToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG1(bytes, dst); err != nil { b.Fail() diff --git a/ecc/bls12-381/hash_to_g2_test.go b/ecc/bls12-381/hash_to_g2_test.go index 1a29cd5e6e..ee12cf7921 100644 --- a/ecc/bls12-381/hash_to_g2_test.go +++ b/ecc/bls12-381/hash_to_g2_test.go @@ -198,7 +198,7 @@ func BenchmarkEncodeToG2(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG2(bytes, dst); err != nil { b.Fail() @@ -214,7 +214,7 @@ func BenchmarkHashToG2(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG2(bytes, dst); err != nil { b.Fail() diff --git a/ecc/bls12-381/marshal_test.go b/ecc/bls12-381/marshal_test.go index 7080b13d74..681217d6a6 100644 --- a/ecc/bls12-381/marshal_test.go +++ b/ecc/bls12-381/marshal_test.go @@ -54,12 +54,12 @@ func TestEncoder(t *testing.T) { var inK fr.Vector // set values of inputs - inA = rand.Uint64() + inA = rand.Uint64() //#nosec G404 weak rng is fine here inB.SetRandom() inC.SetRandom() - inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) + inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here // inE --> infinity - inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) + inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here inG = make([]G1Affine, 2) inH = make([]G2Affine, 0) inG[1] = inD @@ -219,7 +219,7 @@ func TestIsCompressed(t *testing.T) { func TestG1AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG1AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G1Affine buf[0] = 0b111 << 5 @@ -332,7 +332,7 @@ func TestG1AffineSerialization(t *testing.T) { func TestG2AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG2AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G2Affine buf[0] = 0b111 << 5 @@ -506,7 +506,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fp.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bls12-381/multiexp_test.go b/ecc/bls12-381/multiexp_test.go index 64b5a03480..cf4676b2e7 100644 --- a/ecc/bls12-381/multiexp_test.go +++ b/ecc/bls12-381/multiexp_test.go @@ -59,10 +59,10 @@ func TestMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -244,10 +244,10 @@ func TestCrossMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) @@ -475,10 +475,10 @@ func TestMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -658,10 +658,10 @@ func TestCrossMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) diff --git a/ecc/bls12-381/twistededwards/eddsa/eddsa_test.go b/ecc/bls12-381/twistededwards/eddsa/eddsa_test.go index 890b0980be..7541836fa0 100644 --- a/ecc/bls12-381/twistededwards/eddsa/eddsa_test.go +++ b/ecc/bls12-381/twistededwards/eddsa/eddsa_test.go @@ -59,7 +59,7 @@ func Example() { func TestSerialization(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here privKey1, err := GenerateKey(r) if err != nil { @@ -101,7 +101,7 @@ func TestSerialization(t *testing.T) { func TestEddsaMIMC(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here // create eddsa obj and sign a message privKey, err := GenerateKey(r) @@ -144,7 +144,7 @@ func TestEddsaMIMC(t *testing.T) { func TestEddsaSHA256(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := sha256.New() @@ -187,7 +187,7 @@ func TestEddsaSHA256(t *testing.T) { func BenchmarkVerify(b *testing.B) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := hash.MIMC_BLS12_381.New() diff --git a/ecc/bls12-381/twistededwards/point_test.go b/ecc/bls12-381/twistededwards/point_test.go index 0d5bf5cb0f..b3af05cc58 100644 --- a/ecc/bls12-381/twistededwards/point_test.go +++ b/ecc/bls12-381/twistededwards/point_test.go @@ -735,7 +735,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fr.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bls24-315/fp/element_test.go b/ecc/bls24-315/fp/element_test.go index f9131d65a8..2e5e5554bf 100644 --- a/ecc/bls24-315/fp/element_test.go +++ b/ecc/bls24-315/fp/element_test.go @@ -2361,7 +2361,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2404,7 +2404,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2463,13 +2463,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2738,7 +2738,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2748,7 +2748,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2773,7 +2773,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2782,7 +2782,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bls24-315/fr/element_test.go b/ecc/bls24-315/fr/element_test.go index 818b0d93e1..d20fb3f7fc 100644 --- a/ecc/bls24-315/fr/element_test.go +++ b/ecc/bls24-315/fr/element_test.go @@ -2354,7 +2354,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2396,7 +2396,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2454,13 +2454,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2728,7 +2728,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2738,7 +2738,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2763,7 +2763,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2772,7 +2772,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bls24-315/hash_to_g1_test.go b/ecc/bls24-315/hash_to_g1_test.go index bdbbcf42f8..af66a2c63b 100644 --- a/ecc/bls24-315/hash_to_g1_test.go +++ b/ecc/bls24-315/hash_to_g1_test.go @@ -196,7 +196,7 @@ func BenchmarkEncodeToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG1(bytes, dst); err != nil { b.Fail() @@ -212,7 +212,7 @@ func BenchmarkHashToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG1(bytes, dst); err != nil { b.Fail() diff --git a/ecc/bls24-315/marshal_test.go b/ecc/bls24-315/marshal_test.go index 553c5e1b3e..bfb70098d8 100644 --- a/ecc/bls24-315/marshal_test.go +++ b/ecc/bls24-315/marshal_test.go @@ -54,12 +54,12 @@ func TestEncoder(t *testing.T) { var inK fr.Vector // set values of inputs - inA = rand.Uint64() + inA = rand.Uint64() //#nosec G404 weak rng is fine here inB.SetRandom() inC.SetRandom() - inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) + inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here // inE --> infinity - inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) + inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here inG = make([]G1Affine, 2) inH = make([]G2Affine, 0) inG[1] = inD @@ -219,7 +219,7 @@ func TestIsCompressed(t *testing.T) { func TestG1AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG1AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G1Affine buf[0] = 0b111 << 5 @@ -332,7 +332,7 @@ func TestG1AffineSerialization(t *testing.T) { func TestG2AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG2AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G2Affine buf[0] = 0b111 << 5 @@ -516,7 +516,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fp.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bls24-315/multiexp_test.go b/ecc/bls24-315/multiexp_test.go index b4f5e17dbf..7a6a2e75ee 100644 --- a/ecc/bls24-315/multiexp_test.go +++ b/ecc/bls24-315/multiexp_test.go @@ -59,10 +59,10 @@ func TestMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -244,10 +244,10 @@ func TestCrossMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) @@ -475,10 +475,10 @@ func TestMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -658,10 +658,10 @@ func TestCrossMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) diff --git a/ecc/bls24-315/twistededwards/eddsa/eddsa_test.go b/ecc/bls24-315/twistededwards/eddsa/eddsa_test.go index 2ca085f9cd..a0cc2a163b 100644 --- a/ecc/bls24-315/twistededwards/eddsa/eddsa_test.go +++ b/ecc/bls24-315/twistededwards/eddsa/eddsa_test.go @@ -59,7 +59,7 @@ func Example() { func TestSerialization(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here privKey1, err := GenerateKey(r) if err != nil { @@ -101,7 +101,7 @@ func TestSerialization(t *testing.T) { func TestEddsaMIMC(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here // create eddsa obj and sign a message privKey, err := GenerateKey(r) @@ -144,7 +144,7 @@ func TestEddsaMIMC(t *testing.T) { func TestEddsaSHA256(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := sha256.New() @@ -187,7 +187,7 @@ func TestEddsaSHA256(t *testing.T) { func BenchmarkVerify(b *testing.B) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := hash.MIMC_BLS24_315.New() diff --git a/ecc/bls24-315/twistededwards/point_test.go b/ecc/bls24-315/twistededwards/point_test.go index 6c96a37f9f..3f0a432448 100644 --- a/ecc/bls24-315/twistededwards/point_test.go +++ b/ecc/bls24-315/twistededwards/point_test.go @@ -735,7 +735,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fr.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bls24-317/fp/element_test.go b/ecc/bls24-317/fp/element_test.go index cae9032b8d..4c9a447390 100644 --- a/ecc/bls24-317/fp/element_test.go +++ b/ecc/bls24-317/fp/element_test.go @@ -2361,7 +2361,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2404,7 +2404,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2463,13 +2463,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2738,7 +2738,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2748,7 +2748,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2773,7 +2773,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2782,7 +2782,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bls24-317/fr/element_test.go b/ecc/bls24-317/fr/element_test.go index 674a51908f..7163902c77 100644 --- a/ecc/bls24-317/fr/element_test.go +++ b/ecc/bls24-317/fr/element_test.go @@ -2354,7 +2354,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2396,7 +2396,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2454,13 +2454,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2728,7 +2728,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2738,7 +2738,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2763,7 +2763,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2772,7 +2772,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bls24-317/hash_to_g1_test.go b/ecc/bls24-317/hash_to_g1_test.go index e287586e01..c74036999b 100644 --- a/ecc/bls24-317/hash_to_g1_test.go +++ b/ecc/bls24-317/hash_to_g1_test.go @@ -196,7 +196,7 @@ func BenchmarkEncodeToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG1(bytes, dst); err != nil { b.Fail() @@ -212,7 +212,7 @@ func BenchmarkHashToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG1(bytes, dst); err != nil { b.Fail() diff --git a/ecc/bls24-317/marshal_test.go b/ecc/bls24-317/marshal_test.go index 98eb09e681..01bde9d861 100644 --- a/ecc/bls24-317/marshal_test.go +++ b/ecc/bls24-317/marshal_test.go @@ -54,12 +54,12 @@ func TestEncoder(t *testing.T) { var inK fr.Vector // set values of inputs - inA = rand.Uint64() + inA = rand.Uint64() //#nosec G404 weak rng is fine here inB.SetRandom() inC.SetRandom() - inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) + inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here // inE --> infinity - inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) + inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here inG = make([]G1Affine, 2) inH = make([]G2Affine, 0) inG[1] = inD @@ -219,7 +219,7 @@ func TestIsCompressed(t *testing.T) { func TestG1AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG1AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G1Affine buf[0] = 0b111 << 5 @@ -332,7 +332,7 @@ func TestG1AffineSerialization(t *testing.T) { func TestG2AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG2AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G2Affine buf[0] = 0b111 << 5 @@ -516,7 +516,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fp.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bls24-317/multiexp_test.go b/ecc/bls24-317/multiexp_test.go index 44196e0c0f..638c59255a 100644 --- a/ecc/bls24-317/multiexp_test.go +++ b/ecc/bls24-317/multiexp_test.go @@ -59,10 +59,10 @@ func TestMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -244,10 +244,10 @@ func TestCrossMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) @@ -475,10 +475,10 @@ func TestMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -658,10 +658,10 @@ func TestCrossMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) diff --git a/ecc/bls24-317/twistededwards/eddsa/eddsa_test.go b/ecc/bls24-317/twistededwards/eddsa/eddsa_test.go index b480a83fee..6f12c390ad 100644 --- a/ecc/bls24-317/twistededwards/eddsa/eddsa_test.go +++ b/ecc/bls24-317/twistededwards/eddsa/eddsa_test.go @@ -59,7 +59,7 @@ func Example() { func TestSerialization(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here privKey1, err := GenerateKey(r) if err != nil { @@ -101,7 +101,7 @@ func TestSerialization(t *testing.T) { func TestEddsaMIMC(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here // create eddsa obj and sign a message privKey, err := GenerateKey(r) @@ -144,7 +144,7 @@ func TestEddsaMIMC(t *testing.T) { func TestEddsaSHA256(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := sha256.New() @@ -187,7 +187,7 @@ func TestEddsaSHA256(t *testing.T) { func BenchmarkVerify(b *testing.B) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := hash.MIMC_BLS24_317.New() diff --git a/ecc/bls24-317/twistededwards/point_test.go b/ecc/bls24-317/twistededwards/point_test.go index 2da327d286..8a8def1c89 100644 --- a/ecc/bls24-317/twistededwards/point_test.go +++ b/ecc/bls24-317/twistededwards/point_test.go @@ -735,7 +735,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fr.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bn254/fp/element_test.go b/ecc/bn254/fp/element_test.go index 5d2729e06d..9ccd7cb629 100644 --- a/ecc/bn254/fp/element_test.go +++ b/ecc/bn254/fp/element_test.go @@ -2354,7 +2354,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2396,7 +2396,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2454,13 +2454,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2728,7 +2728,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2738,7 +2738,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2763,7 +2763,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2772,7 +2772,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bn254/fr/element_test.go b/ecc/bn254/fr/element_test.go index dfeab886a6..226378d64b 100644 --- a/ecc/bn254/fr/element_test.go +++ b/ecc/bn254/fr/element_test.go @@ -2354,7 +2354,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2396,7 +2396,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2454,13 +2454,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2728,7 +2728,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2738,7 +2738,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2763,7 +2763,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2772,7 +2772,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bn254/hash_to_g1_test.go b/ecc/bn254/hash_to_g1_test.go index 0a18db90f8..98ee9b89b8 100644 --- a/ecc/bn254/hash_to_g1_test.go +++ b/ecc/bn254/hash_to_g1_test.go @@ -151,7 +151,7 @@ func BenchmarkEncodeToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG1(bytes, dst); err != nil { b.Fail() @@ -167,7 +167,7 @@ func BenchmarkHashToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG1(bytes, dst); err != nil { b.Fail() diff --git a/ecc/bn254/hash_to_g2_test.go b/ecc/bn254/hash_to_g2_test.go index 9804d47139..de7f103cb7 100644 --- a/ecc/bn254/hash_to_g2_test.go +++ b/ecc/bn254/hash_to_g2_test.go @@ -153,7 +153,7 @@ func BenchmarkEncodeToG2(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG2(bytes, dst); err != nil { b.Fail() @@ -169,7 +169,7 @@ func BenchmarkHashToG2(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG2(bytes, dst); err != nil { b.Fail() diff --git a/ecc/bn254/marshal_test.go b/ecc/bn254/marshal_test.go index 45504bdf5f..67f3f9a6c9 100644 --- a/ecc/bn254/marshal_test.go +++ b/ecc/bn254/marshal_test.go @@ -54,12 +54,12 @@ func TestEncoder(t *testing.T) { var inK fr.Vector // set values of inputs - inA = rand.Uint64() + inA = rand.Uint64() //#nosec G404 weak rng is fine here inB.SetRandom() inC.SetRandom() - inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) + inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here // inE --> infinity - inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) + inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here inG = make([]G1Affine, 2) inH = make([]G2Affine, 0) inG[1] = inD @@ -466,7 +466,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fp.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bn254/multiexp_test.go b/ecc/bn254/multiexp_test.go index b0aca8e31d..a6ce9fe669 100644 --- a/ecc/bn254/multiexp_test.go +++ b/ecc/bn254/multiexp_test.go @@ -59,10 +59,10 @@ func TestMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -244,10 +244,10 @@ func TestCrossMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) @@ -475,10 +475,10 @@ func TestMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -658,10 +658,10 @@ func TestCrossMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) diff --git a/ecc/bn254/twistededwards/eddsa/eddsa_test.go b/ecc/bn254/twistededwards/eddsa/eddsa_test.go index eb23ddd966..78a2efb882 100644 --- a/ecc/bn254/twistededwards/eddsa/eddsa_test.go +++ b/ecc/bn254/twistededwards/eddsa/eddsa_test.go @@ -59,7 +59,7 @@ func Example() { func TestSerialization(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here privKey1, err := GenerateKey(r) if err != nil { @@ -101,7 +101,7 @@ func TestSerialization(t *testing.T) { func TestEddsaMIMC(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here // create eddsa obj and sign a message privKey, err := GenerateKey(r) @@ -144,7 +144,7 @@ func TestEddsaMIMC(t *testing.T) { func TestEddsaSHA256(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := sha256.New() @@ -187,7 +187,7 @@ func TestEddsaSHA256(t *testing.T) { func BenchmarkVerify(b *testing.B) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := hash.MIMC_BN254.New() diff --git a/ecc/bn254/twistededwards/point_test.go b/ecc/bn254/twistededwards/point_test.go index c8434cff61..d070082b9d 100644 --- a/ecc/bn254/twistededwards/point_test.go +++ b/ecc/bn254/twistededwards/point_test.go @@ -735,7 +735,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fr.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bw6-633/fp/element_test.go b/ecc/bw6-633/fp/element_test.go index 55412f3697..1954650a9f 100644 --- a/ecc/bw6-633/fp/element_test.go +++ b/ecc/bw6-633/fp/element_test.go @@ -2396,7 +2396,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2444,7 +2444,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2508,13 +2508,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2788,7 +2788,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2798,7 +2798,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2823,7 +2823,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2832,7 +2832,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bw6-633/fr/element_test.go b/ecc/bw6-633/fr/element_test.go index 202b261869..889cae8af5 100644 --- a/ecc/bw6-633/fr/element_test.go +++ b/ecc/bw6-633/fr/element_test.go @@ -2361,7 +2361,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2404,7 +2404,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2463,13 +2463,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2738,7 +2738,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2748,7 +2748,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2773,7 +2773,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2782,7 +2782,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bw6-633/hash_to_g1_test.go b/ecc/bw6-633/hash_to_g1_test.go index 7e8814aa30..986a4d7d01 100644 --- a/ecc/bw6-633/hash_to_g1_test.go +++ b/ecc/bw6-633/hash_to_g1_test.go @@ -196,7 +196,7 @@ func BenchmarkEncodeToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG1(bytes, dst); err != nil { b.Fail() @@ -212,7 +212,7 @@ func BenchmarkHashToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG1(bytes, dst); err != nil { b.Fail() diff --git a/ecc/bw6-633/hash_to_g2_test.go b/ecc/bw6-633/hash_to_g2_test.go index 44371b4dd1..75daa99607 100644 --- a/ecc/bw6-633/hash_to_g2_test.go +++ b/ecc/bw6-633/hash_to_g2_test.go @@ -196,7 +196,7 @@ func BenchmarkEncodeToG2(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG2(bytes, dst); err != nil { b.Fail() @@ -212,7 +212,7 @@ func BenchmarkHashToG2(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG2(bytes, dst); err != nil { b.Fail() diff --git a/ecc/bw6-633/marshal_test.go b/ecc/bw6-633/marshal_test.go index beec029d48..a5325d26ac 100644 --- a/ecc/bw6-633/marshal_test.go +++ b/ecc/bw6-633/marshal_test.go @@ -54,12 +54,12 @@ func TestEncoder(t *testing.T) { var inK fr.Vector // set values of inputs - inA = rand.Uint64() + inA = rand.Uint64() //#nosec G404 weak rng is fine here inB.SetRandom() inC.SetRandom() - inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) + inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here // inE --> infinity - inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) + inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here inG = make([]G1Affine, 2) inH = make([]G2Affine, 0) inG[1] = inD @@ -219,7 +219,7 @@ func TestIsCompressed(t *testing.T) { func TestG1AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG1AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G1Affine buf[0] = 0b111 << 5 @@ -332,7 +332,7 @@ func TestG1AffineSerialization(t *testing.T) { func TestG2AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG2AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G2Affine buf[0] = 0b111 << 5 @@ -496,7 +496,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fp.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bw6-633/multiexp_test.go b/ecc/bw6-633/multiexp_test.go index e17370e5e3..b36d3db65a 100644 --- a/ecc/bw6-633/multiexp_test.go +++ b/ecc/bw6-633/multiexp_test.go @@ -59,10 +59,10 @@ func TestMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -244,10 +244,10 @@ func TestCrossMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) @@ -475,10 +475,10 @@ func TestMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -658,10 +658,10 @@ func TestCrossMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) diff --git a/ecc/bw6-633/twistededwards/eddsa/eddsa_test.go b/ecc/bw6-633/twistededwards/eddsa/eddsa_test.go index a3e75f5c4f..0ed2470d44 100644 --- a/ecc/bw6-633/twistededwards/eddsa/eddsa_test.go +++ b/ecc/bw6-633/twistededwards/eddsa/eddsa_test.go @@ -59,7 +59,7 @@ func Example() { func TestSerialization(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here privKey1, err := GenerateKey(r) if err != nil { @@ -101,7 +101,7 @@ func TestSerialization(t *testing.T) { func TestEddsaMIMC(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here // create eddsa obj and sign a message privKey, err := GenerateKey(r) @@ -144,7 +144,7 @@ func TestEddsaMIMC(t *testing.T) { func TestEddsaSHA256(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := sha256.New() @@ -187,7 +187,7 @@ func TestEddsaSHA256(t *testing.T) { func BenchmarkVerify(b *testing.B) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := hash.MIMC_BW6_633.New() diff --git a/ecc/bw6-633/twistededwards/point_test.go b/ecc/bw6-633/twistededwards/point_test.go index 0ffa874543..e9fcb4347c 100644 --- a/ecc/bw6-633/twistededwards/point_test.go +++ b/ecc/bw6-633/twistededwards/point_test.go @@ -735,7 +735,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fr.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bw6-756/fp/element_test.go b/ecc/bw6-756/fp/element_test.go index d1bd113fe6..3292ab6003 100644 --- a/ecc/bw6-756/fp/element_test.go +++ b/ecc/bw6-756/fp/element_test.go @@ -2410,7 +2410,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2460,7 +2460,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2526,13 +2526,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2808,7 +2808,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2818,7 +2818,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2843,7 +2843,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2852,7 +2852,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bw6-756/fr/element_test.go b/ecc/bw6-756/fr/element_test.go index 59fc125ea7..ef37d92a57 100644 --- a/ecc/bw6-756/fr/element_test.go +++ b/ecc/bw6-756/fr/element_test.go @@ -2368,7 +2368,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2412,7 +2412,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2472,13 +2472,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2748,7 +2748,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2758,7 +2758,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2783,7 +2783,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2792,7 +2792,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bw6-756/hash_to_g1_test.go b/ecc/bw6-756/hash_to_g1_test.go index 230a841d99..ffa80a08f5 100644 --- a/ecc/bw6-756/hash_to_g1_test.go +++ b/ecc/bw6-756/hash_to_g1_test.go @@ -196,7 +196,7 @@ func BenchmarkEncodeToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG1(bytes, dst); err != nil { b.Fail() @@ -212,7 +212,7 @@ func BenchmarkHashToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG1(bytes, dst); err != nil { b.Fail() diff --git a/ecc/bw6-756/hash_to_g2_test.go b/ecc/bw6-756/hash_to_g2_test.go index 77d526ffa8..f444e2a1da 100644 --- a/ecc/bw6-756/hash_to_g2_test.go +++ b/ecc/bw6-756/hash_to_g2_test.go @@ -196,7 +196,7 @@ func BenchmarkEncodeToG2(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG2(bytes, dst); err != nil { b.Fail() @@ -212,7 +212,7 @@ func BenchmarkHashToG2(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG2(bytes, dst); err != nil { b.Fail() diff --git a/ecc/bw6-756/marshal_test.go b/ecc/bw6-756/marshal_test.go index c706745f4a..0b4fb5df39 100644 --- a/ecc/bw6-756/marshal_test.go +++ b/ecc/bw6-756/marshal_test.go @@ -54,12 +54,12 @@ func TestEncoder(t *testing.T) { var inK fr.Vector // set values of inputs - inA = rand.Uint64() + inA = rand.Uint64() //#nosec G404 weak rng is fine here inB.SetRandom() inC.SetRandom() - inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) + inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here // inE --> infinity - inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) + inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here inG = make([]G1Affine, 2) inH = make([]G2Affine, 0) inG[1] = inD @@ -219,7 +219,7 @@ func TestIsCompressed(t *testing.T) { func TestG1AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG1AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G1Affine buf[0] = 0b111 << 5 @@ -332,7 +332,7 @@ func TestG1AffineSerialization(t *testing.T) { func TestG2AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG2AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G2Affine buf[0] = 0b111 << 5 @@ -496,7 +496,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fp.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bw6-756/multiexp_test.go b/ecc/bw6-756/multiexp_test.go index e45d451a89..a944459b77 100644 --- a/ecc/bw6-756/multiexp_test.go +++ b/ecc/bw6-756/multiexp_test.go @@ -59,10 +59,10 @@ func TestMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -244,10 +244,10 @@ func TestCrossMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) @@ -475,10 +475,10 @@ func TestMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -658,10 +658,10 @@ func TestCrossMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) diff --git a/ecc/bw6-756/twistededwards/eddsa/eddsa_test.go b/ecc/bw6-756/twistededwards/eddsa/eddsa_test.go index b83ba2805d..a0258d1218 100644 --- a/ecc/bw6-756/twistededwards/eddsa/eddsa_test.go +++ b/ecc/bw6-756/twistededwards/eddsa/eddsa_test.go @@ -59,7 +59,7 @@ func Example() { func TestSerialization(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here privKey1, err := GenerateKey(r) if err != nil { @@ -101,7 +101,7 @@ func TestSerialization(t *testing.T) { func TestEddsaMIMC(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here // create eddsa obj and sign a message privKey, err := GenerateKey(r) @@ -144,7 +144,7 @@ func TestEddsaMIMC(t *testing.T) { func TestEddsaSHA256(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := sha256.New() @@ -187,7 +187,7 @@ func TestEddsaSHA256(t *testing.T) { func BenchmarkVerify(b *testing.B) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := hash.MIMC_BW6_756.New() diff --git a/ecc/bw6-756/twistededwards/point_test.go b/ecc/bw6-756/twistededwards/point_test.go index fc5347fb00..9b28026a60 100644 --- a/ecc/bw6-756/twistededwards/point_test.go +++ b/ecc/bw6-756/twistededwards/point_test.go @@ -735,7 +735,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fr.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bw6-761/fp/element_test.go b/ecc/bw6-761/fp/element_test.go index c089a22ea8..de2a02827c 100644 --- a/ecc/bw6-761/fp/element_test.go +++ b/ecc/bw6-761/fp/element_test.go @@ -2410,7 +2410,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2460,7 +2460,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2526,13 +2526,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2808,7 +2808,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2818,7 +2818,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2843,7 +2843,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2852,7 +2852,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bw6-761/fr/element_test.go b/ecc/bw6-761/fr/element_test.go index 66d3f95f7c..840a666c0f 100644 --- a/ecc/bw6-761/fr/element_test.go +++ b/ecc/bw6-761/fr/element_test.go @@ -2368,7 +2368,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2412,7 +2412,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2472,13 +2472,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2748,7 +2748,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2758,7 +2758,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2783,7 +2783,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2792,7 +2792,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/bw6-761/hash_to_g1_test.go b/ecc/bw6-761/hash_to_g1_test.go index ddfc96c565..db33614c6e 100644 --- a/ecc/bw6-761/hash_to_g1_test.go +++ b/ecc/bw6-761/hash_to_g1_test.go @@ -196,7 +196,7 @@ func BenchmarkEncodeToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG1(bytes, dst); err != nil { b.Fail() @@ -212,7 +212,7 @@ func BenchmarkHashToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG1(bytes, dst); err != nil { b.Fail() diff --git a/ecc/bw6-761/hash_to_g2_test.go b/ecc/bw6-761/hash_to_g2_test.go index a030e271bd..e669c88c52 100644 --- a/ecc/bw6-761/hash_to_g2_test.go +++ b/ecc/bw6-761/hash_to_g2_test.go @@ -196,7 +196,7 @@ func BenchmarkEncodeToG2(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG2(bytes, dst); err != nil { b.Fail() @@ -212,7 +212,7 @@ func BenchmarkHashToG2(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG2(bytes, dst); err != nil { b.Fail() diff --git a/ecc/bw6-761/marshal_test.go b/ecc/bw6-761/marshal_test.go index 452f681776..1801fb2e03 100644 --- a/ecc/bw6-761/marshal_test.go +++ b/ecc/bw6-761/marshal_test.go @@ -54,12 +54,12 @@ func TestEncoder(t *testing.T) { var inK fr.Vector // set values of inputs - inA = rand.Uint64() + inA = rand.Uint64() //#nosec G404 weak rng is fine here inB.SetRandom() inC.SetRandom() - inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) + inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here // inE --> infinity - inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) + inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here inG = make([]G1Affine, 2) inH = make([]G2Affine, 0) inG[1] = inD @@ -219,7 +219,7 @@ func TestIsCompressed(t *testing.T) { func TestG1AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG1AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G1Affine buf[0] = 0b111 << 5 @@ -332,7 +332,7 @@ func TestG1AffineSerialization(t *testing.T) { func TestG2AffineInvalidBitMask(t *testing.T) { t.Parallel() var buf [SizeOfG2AffineCompressed]byte - rand.Read(buf[:]) + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p G2Affine buf[0] = 0b111 << 5 @@ -496,7 +496,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fp.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/bw6-761/multiexp_test.go b/ecc/bw6-761/multiexp_test.go index 05173f16a3..13e025fa28 100644 --- a/ecc/bw6-761/multiexp_test.go +++ b/ecc/bw6-761/multiexp_test.go @@ -59,10 +59,10 @@ func TestMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -244,10 +244,10 @@ func TestCrossMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) @@ -475,10 +475,10 @@ func TestMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -658,10 +658,10 @@ func TestCrossMultiExpG2(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) diff --git a/ecc/bw6-761/twistededwards/eddsa/eddsa_test.go b/ecc/bw6-761/twistededwards/eddsa/eddsa_test.go index 9e145fbaad..a5654456a3 100644 --- a/ecc/bw6-761/twistededwards/eddsa/eddsa_test.go +++ b/ecc/bw6-761/twistededwards/eddsa/eddsa_test.go @@ -59,7 +59,7 @@ func Example() { func TestSerialization(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here privKey1, err := GenerateKey(r) if err != nil { @@ -101,7 +101,7 @@ func TestSerialization(t *testing.T) { func TestEddsaMIMC(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here // create eddsa obj and sign a message privKey, err := GenerateKey(r) @@ -144,7 +144,7 @@ func TestEddsaMIMC(t *testing.T) { func TestEddsaSHA256(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := sha256.New() @@ -187,7 +187,7 @@ func TestEddsaSHA256(t *testing.T) { func BenchmarkVerify(b *testing.B) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := hash.MIMC_BW6_761.New() diff --git a/ecc/bw6-761/twistededwards/point_test.go b/ecc/bw6-761/twistededwards/point_test.go index 56225dc1bd..eae9406914 100644 --- a/ecc/bw6-761/twistededwards/point_test.go +++ b/ecc/bw6-761/twistededwards/point_test.go @@ -735,7 +735,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fr.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/secp256k1/g1_test.go b/ecc/secp256k1/g1_test.go index a88a358f6e..2dae2547f9 100644 --- a/ecc/secp256k1/g1_test.go +++ b/ecc/secp256k1/g1_test.go @@ -716,7 +716,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fp.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/secp256k1/hash_to_g1_test.go b/ecc/secp256k1/hash_to_g1_test.go index e4d31d0d13..fe00906fc5 100644 --- a/ecc/secp256k1/hash_to_g1_test.go +++ b/ecc/secp256k1/hash_to_g1_test.go @@ -151,7 +151,7 @@ func BenchmarkEncodeToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG1(bytes, dst); err != nil { b.Fail() @@ -167,7 +167,7 @@ func BenchmarkHashToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG1(bytes, dst); err != nil { b.Fail() diff --git a/ecc/secp256k1/multiexp_test.go b/ecc/secp256k1/multiexp_test.go index b3f2e74f35..08996728a5 100644 --- a/ecc/secp256k1/multiexp_test.go +++ b/ecc/secp256k1/multiexp_test.go @@ -59,10 +59,10 @@ func TestMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -244,10 +244,10 @@ func TestCrossMultiExpG1(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element fillBenchScalars(sampleScalars[:]) diff --git a/ecc/stark-curve/fp/element_test.go b/ecc/stark-curve/fp/element_test.go index 53d70ed7aa..f182e9d70f 100644 --- a/ecc/stark-curve/fp/element_test.go +++ b/ecc/stark-curve/fp/element_test.go @@ -2354,7 +2354,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2396,7 +2396,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2454,13 +2454,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2728,7 +2728,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2738,7 +2738,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2763,7 +2763,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2772,7 +2772,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/stark-curve/fr/element_test.go b/ecc/stark-curve/fr/element_test.go index 91a592313f..354b4f9891 100644 --- a/ecc/stark-curve/fr/element_test.go +++ b/ecc/stark-curve/fr/element_test.go @@ -2306,7 +2306,7 @@ func TestElementInversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs-j] = 0 } @@ -2348,7 +2348,7 @@ func TestElementLinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -2406,13 +2406,13 @@ func TestElementBigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func TestElementVeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x Element x.SetRandom() var xInt big.Int @@ -2680,7 +2680,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -2690,7 +2690,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -2715,7 +2715,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -2724,7 +2724,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/ecc/stark-curve/g1_test.go b/ecc/stark-curve/g1_test.go index a88306b324..b8062a8b04 100644 --- a/ecc/stark-curve/g1_test.go +++ b/ecc/stark-curve/g1_test.go @@ -66,7 +66,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fp.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/ecc/stark-curve/hash_to_g1_test.go b/ecc/stark-curve/hash_to_g1_test.go index b53f89bbae..b180e69521 100644 --- a/ecc/stark-curve/hash_to_g1_test.go +++ b/ecc/stark-curve/hash_to_g1_test.go @@ -151,7 +151,7 @@ func BenchmarkEncodeToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeToG1(bytes, dst); err != nil { b.Fail() @@ -167,7 +167,7 @@ func BenchmarkHashToG1(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashToG1(bytes, dst); err != nil { b.Fail() diff --git a/ecc/stark-curve/marshal_test.go b/ecc/stark-curve/marshal_test.go index 470f6fc0fe..21a2fea2b6 100644 --- a/ecc/stark-curve/marshal_test.go +++ b/ecc/stark-curve/marshal_test.go @@ -44,10 +44,10 @@ func TestEncoder(t *testing.T) { var inJ []fr.Element // set values of inputs - inA = rand.Uint64() + inA = rand.Uint64() //#nosec G404 weak rng is fine here inB.SetRandom() inC.SetRandom() - inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) + inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here // inE --> infinity inG = make([]G1Affine, 2) inG[1] = inD diff --git a/field/generator/internal/templates/element/inverse_tests.go b/field/generator/internal/templates/element/inverse_tests.go index d85d1ead84..6631658cc3 100644 --- a/field/generator/internal/templates/element/inverse_tests.go +++ b/field/generator/internal/templates/element/inverse_tests.go @@ -10,7 +10,7 @@ func Test{{.ElementName}}InversionApproximation(t *testing.T) { x.SetRandom() // Normally small elements are unlikely. Here we give them a higher chance - xZeros := mrand.Int() % Limbs + xZeros := mrand.Int() % Limbs //#nosec G404 weak rng is fine here for j := 1; j < xZeros; j++ { x[Limbs - j] = 0 } @@ -51,7 +51,7 @@ func Test{{.ElementName}}LinearComb(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() y.SetRandom() - testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) + testLinearComb(t, &x, mrand.Int63(), &y, mrand.Int63()) //#nosec G404 weak rng is fine here } } @@ -108,13 +108,13 @@ func Test{{.ElementName}}BigNumWMul(t *testing.T) { for i := 0; i < 1000; i++ { x.SetRandom() - w := mrand.Int63() + w := mrand.Int63() //#nosec G404 weak rng is fine here testBigNumWMul(t, &x, w) } } func Test{{.ElementName}}VeryBigIntConversion(t *testing.T) { - xHi := mrand.Uint64() + xHi := mrand.Uint64() //#nosec G404 weak rng is fine here var x {{.ElementName}} x.SetRandom() var xInt big.Int @@ -385,7 +385,7 @@ func TestUpdateFactorsRandomization(t *testing.T) { func randomizeUpdateFactor(absLimit uint32) int64 { const maxSizeLikelihood = 10 - maxSize := mrand.Intn(maxSizeLikelihood) + maxSize := mrand.Intn(maxSizeLikelihood) //#nosec G404 weak rng is fine here absLimit64 := int64(absLimit) var f int64 @@ -395,7 +395,7 @@ func randomizeUpdateFactor(absLimit uint32) int64 { case 1: f = -absLimit64 default: - f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 + f = int64(mrand.Uint64()%(2*uint64(absLimit64)+1)) - absLimit64 //#nosec G404 weak rng is fine here } if f > 1<<31 { @@ -420,7 +420,7 @@ func abs64T32(f int64) uint32 { func randomizeUpdateFactors() (int64, int64) { var f [2]int64 - b := mrand.Int() % 2 + b := mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b] = randomizeUpdateFactor(1 << 31) @@ -429,7 +429,7 @@ func randomizeUpdateFactors() (int64, int64) { //Patching another edge case if f[0]+f[1] == -1<<31 { - b = mrand.Int() % 2 + b = mrand.Int() % 2 //#nosec G404 weak rng is fine here f[b]++ } diff --git a/internal/generator/ecc/template/tests/hash_to_curve.go.tmpl b/internal/generator/ecc/template/tests/hash_to_curve.go.tmpl index 5cd6e2f003..a44edff7a9 100644 --- a/internal/generator/ecc/template/tests/hash_to_curve.go.tmpl +++ b/internal/generator/ecc/template/tests/hash_to_curve.go.tmpl @@ -38,9 +38,9 @@ func Test{{$CurveTitle}}SqrtRatio(t *testing.T) { properties := gopter.NewProperties(parameters) - + gen := {{$fuzzer}} - + properties.Property("{{$CurveTitle}}SqrtRatio must square back to the right value", prop.ForAll( func(u {{$CoordType}}, v {{$CoordType}}) bool { @@ -205,7 +205,7 @@ func BenchmarkEncodeTo{{$CurveTitle}}(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := EncodeTo{{$CurveTitle}}(bytes, dst); err != nil { b.Fail() @@ -221,7 +221,7 @@ func BenchmarkHashTo{{$CurveTitle}}(b *testing.B) { for i := 0; i < b.N; i++ { - bytes[rand.Int()%size] = byte(rand.Int()) + bytes[rand.Int()%size] = byte(rand.Int()) //#nosec G404 weak rng is fine here if _, err := HashTo{{$CurveTitle}}(bytes, dst); err != nil { b.Fail() @@ -293,7 +293,7 @@ func {{$CurveName}}CoordAt(slice []fp.Element, i int) {{$CoordType}} { func {{$CurveName}}TestMatchCoord(t *testing.T, coordName string, msg string, expectedStr string, seen {{$CoordType}}) { var expected {{$CoordType}} - + {{$CurveName}}CoordSetString(&expected, expectedStr) if !expected.Equal(&seen) { diff --git a/internal/generator/ecc/template/tests/marshal.go.tmpl b/internal/generator/ecc/template/tests/marshal.go.tmpl index 50ffd56512..9ca3df8e08 100644 --- a/internal/generator/ecc/template/tests/marshal.go.tmpl +++ b/internal/generator/ecc/template/tests/marshal.go.tmpl @@ -44,12 +44,12 @@ func TestEncoder(t *testing.T) { var inK fr.Vector // set values of inputs - inA = rand.Uint64() + inA = rand.Uint64() //#nosec G404 weak rng is fine here inB.SetRandom() inC.SetRandom() - inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) + inD.ScalarMultiplication(&g1GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here // inE --> infinity - inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) + inF.ScalarMultiplication(&g2GenAff, new(big.Int).SetUint64(rand.Uint64())) //#nosec G404 weak rng is fine here inG = make([]G1Affine, 2) inH = make([]G2Affine, 0) inG[1] = inD @@ -227,8 +227,8 @@ func TestIsCompressed(t *testing.T) { {{if ge $.FpUnusedBits 3}} func Test{{ $.TAffine }}InvalidBitMask(t *testing.T) { t.Parallel() - var buf [SizeOf{{ $.TAffine }}Compressed]byte - rand.Read(buf[:]) + var buf [SizeOf{{ $.TAffine }}Compressed]byte + rand.Read(buf[:]) //#nosec G404 weak rng is fine here var p {{ $.TAffine }} buf[0] = 0b111 << 5 @@ -352,11 +352,11 @@ func Test{{ $.TAffine }}Serialization(t *testing.T) { func GenFr() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var elmt fr.Element - + if _, err := elmt.SetRandom(); err != nil { panic(err) } - + return gopter.NewGenResult(elmt, gopter.NoShrinker) } } @@ -365,11 +365,11 @@ func GenFr() gopter.Gen { func GenFp() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var elmt fp.Element - + if _, err := elmt.SetRandom(); err != nil { panic(err) } - + return gopter.NewGenResult(elmt, gopter.NoShrinker) } } @@ -472,7 +472,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fp.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/internal/generator/ecc/template/tests/multiexp.go.tmpl b/internal/generator/ecc/template/tests/multiexp.go.tmpl index e6bf734091..0201ada492 100644 --- a/internal/generator/ecc/template/tests/multiexp.go.tmpl +++ b/internal/generator/ecc/template/tests/multiexp.go.tmpl @@ -61,10 +61,10 @@ func TestMultiExp{{$.UPointName}}(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here // final scalar to use in double and add method (without mixer factor) // n(n+1)(2n+1)/6 (sum of the squares from 1 to n) @@ -260,10 +260,10 @@ func TestCrossMultiExp{{ $.UPointName }}(t *testing.T) { // sprinkle some points at infinity rand.Seed(time.Now().UnixNano()) - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() - samplePoints[rand.Intn(nbSamples)].setInfinity() + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here + samplePoints[rand.Intn(nbSamples)].setInfinity() //#nosec G404 weak rng is fine here var sampleScalars [nbSamples]fr.Element diff --git a/internal/generator/ecc/template/tests/point.go.tmpl b/internal/generator/ecc/template/tests/point.go.tmpl index 23b67956cb..932221628c 100644 --- a/internal/generator/ecc/template/tests/point.go.tmpl +++ b/internal/generator/ecc/template/tests/point.go.tmpl @@ -840,7 +840,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fp.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) } diff --git a/internal/generator/edwards/eddsa/template/eddsa.test.go.tmpl b/internal/generator/edwards/eddsa/template/eddsa.test.go.tmpl index 7cb21bd856..b2bf054a8c 100644 --- a/internal/generator/edwards/eddsa/template/eddsa.test.go.tmpl +++ b/internal/generator/edwards/eddsa/template/eddsa.test.go.tmpl @@ -42,7 +42,7 @@ func Example() { func TestSerialization(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here privKey1, err := GenerateKey(r) if err != nil { @@ -84,7 +84,7 @@ func TestSerialization(t *testing.T) { func TestEddsaMIMC(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here // create eddsa obj and sign a message privKey, err := GenerateKey(r) @@ -127,7 +127,7 @@ func TestEddsaMIMC(t *testing.T) { func TestEddsaSHA256(t *testing.T) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := sha256.New() @@ -170,7 +170,7 @@ func TestEddsaSHA256(t *testing.T) { func BenchmarkVerify(b *testing.B) { src := rand.NewSource(0) - r := rand.New(src) + r := rand.New(src) //#nosec G404 weak rng is fine here hFunc := hash.MIMC_{{ .EnumID }}.New() diff --git a/internal/generator/edwards/template/tests/point.go.tmpl b/internal/generator/edwards/template/tests/point.go.tmpl index 650dd93d4a..e0bf457c86 100644 --- a/internal/generator/edwards/template/tests/point.go.tmpl +++ b/internal/generator/edwards/template/tests/point.go.tmpl @@ -719,7 +719,7 @@ func GenBigInt() gopter.Gen { return func(genParams *gopter.GenParameters) *gopter.GenResult { var s big.Int var b [fr.Bytes]byte - _, err := rand.Read(b[:]) + _, err := rand.Read(b[:]) //#nosec G404 weak rng is fine here if err != nil { panic(err) }