github.com/cloudflare/circl@v1.5.0/sign/eddilithium3/example_test.go (about)

     1  package eddilithium3_test
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/cloudflare/circl/sign/eddilithium3"
     7  )
     8  
     9  func Example() {
    10  	// Generates a keypair.
    11  	pk, sk, err := eddilithium3.GenerateKey(nil)
    12  	if err != nil {
    13  		panic(err)
    14  	}
    15  
    16  	// (Alternatively one can derive a keypair from a seed,
    17  	// see NewKeyFromSeed().)
    18  
    19  	// Packs public and private key
    20  	var packedSk [eddilithium3.PrivateKeySize]byte
    21  	var packedPk [eddilithium3.PublicKeySize]byte
    22  	sk.Pack(&packedSk)
    23  	pk.Pack(&packedPk)
    24  
    25  	// Load it again
    26  	var sk2 eddilithium3.PrivateKey
    27  	var pk2 eddilithium3.PublicKey
    28  	sk2.Unpack(&packedSk)
    29  	pk2.Unpack(&packedPk)
    30  
    31  	// Creates a signature on our message with the generated private key.
    32  	msg := []byte("Some message")
    33  	var signature [eddilithium3.SignatureSize]byte
    34  	eddilithium3.SignTo(&sk2, msg, signature[:])
    35  
    36  	// Checks whether a signature is correct
    37  	if !eddilithium3.Verify(&pk2, msg, signature[:]) {
    38  		panic("incorrect signature")
    39  	}
    40  
    41  	fmt.Printf("O.K.")
    42  
    43  	// Output:
    44  	// O.K.
    45  }