github.com/cloudflare/circl@v1.5.0/pke/kyber/kyber512/internal/cpapke_test.go (about) 1 package internal 2 3 import ( 4 "crypto/rand" 5 "testing" 6 ) 7 8 func TestEncryptThenDecrypt(t *testing.T) { 9 var seed [32]byte 10 var coin [SeedSize]byte 11 12 for i := 0; i < 32; i++ { 13 seed[i] = byte(i) 14 coin[i] = byte(i) 15 } 16 17 for i := 0; i < 100; i++ { 18 seed[0] = byte(i) 19 pk, sk := NewKeyFromSeed(seed[:]) 20 21 for j := 0; j < 100; j++ { 22 var msg, msg2 [PlaintextSize]byte 23 var ct [CiphertextSize]byte 24 25 _, _ = rand.Read(msg[:]) 26 _, _ = rand.Read(coin[:]) 27 28 pk.EncryptTo(ct[:], msg[:], coin[:]) 29 sk.DecryptTo(msg2[:], ct[:]) 30 31 if msg != msg2 { 32 t.Fatalf("%v %v %v", ct, msg, msg2) 33 } 34 } 35 } 36 }