File: example_test.go

package info (click to toggle)
golang-github-cloudflare-circl 1.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,064 kB
  • sloc: asm: 20,492; ansic: 1,292; makefile: 68
file content (45 lines) | stat: -rw-r--r-- 972 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package eddilithium2_test

import (
	"fmt"

	"github.com/cloudflare/circl/sign/eddilithium2"
)

func Example() {
	// Generates a keypair.
	pk, sk, err := eddilithium2.GenerateKey(nil)
	if err != nil {
		panic(err)
	}

	// (Alternatively one can derive a keypair from a seed,
	// see NewKeyFromSeed().)

	// Packs public and private key
	var packedSk [eddilithium2.PrivateKeySize]byte
	var packedPk [eddilithium2.PublicKeySize]byte
	sk.Pack(&packedSk)
	pk.Pack(&packedPk)

	// Load it again
	var sk2 eddilithium2.PrivateKey
	var pk2 eddilithium2.PublicKey
	sk2.Unpack(&packedSk)
	pk2.Unpack(&packedPk)

	// Creates a signature on our message with the generated private key.
	msg := []byte("Some message")
	var signature [eddilithium2.SignatureSize]byte
	eddilithium2.SignTo(&sk2, msg, signature[:])

	// Checks whether a signature is correct
	if !eddilithium2.Verify(&pk2, msg, signature[:]) {
		panic("incorrect signature")
	}

	fmt.Printf("O.K.")

	// Output:
	// O.K.
}