github.com/reality95/cryptosystem@v0.0.0-20200827052737-5bb1ed7d6cf9/rand/prime_test.go (about) 1 package rand 2 3 import ( 4 cRand "crypto/rand" 5 "github.com/stretchr/testify/assert" 6 "math/big" 7 mRand "math/rand" 8 "testing" 9 ) 10 11 func TestRandomPSIRand(t *testing.T) { 12 assert := assert.New(t) 13 rnd := mRand.New(mRand.NewSource(69)) 14 r := uint64(1000000007) 15 rBig := new(big.Int).SetUint64(r) 16 p, err := Prime(rnd, 1024, r) 17 assert.Equal(err, nil, "Expected no error for big bits") 18 bigMod := new(big.Int).Mod(p, rBig) 19 assert.Equal(bigMod.Uint64(), uint64(1), "Expected the prime to have residue 1 when divided by r") 20 } 21 22 func BenchmarkRandomCryptoRand(b *testing.B) { 23 rnd := mRand.New(mRand.NewSource(669)) 24 r := uint64(667) 25 rBig := new(big.Int).SetUint64(r) 26 var p *big.Int 27 var err error 28 for { 29 p, err = cRand.Prime(rnd, 1024) 30 if err == nil && new(big.Int).Mod(p, rBig).Cmp(oneInt) == 0 { 31 break 32 } 33 } 34 }