github.com/cloudflare/circl@v1.5.0/pke/kyber/kyber768/internal/cpapke_test.go (about)

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