...
1 package dilithium_test
2
3 import (
4 "fmt"
5 "sort"
6
7 "github.com/cloudflare/circl/sign/dilithium"
8 )
9
10 func Example() {
11
12 modes := dilithium.ModeNames()
13 sort.Strings(modes)
14 fmt.Printf("Supported modes: %v\n", modes)
15
16
17 mode := dilithium.ModeByName("Dilithium3")
18 if mode == nil {
19 panic("Mode3 not supported")
20 }
21
22
23
24
25
26
27 pk, sk, err := mode.GenerateKey(nil)
28 if err != nil {
29 panic(err)
30 }
31
32
33
34
35 packedSk := sk.Bytes()
36 packedPk := pk.Bytes()
37
38
39 sk2 := mode.PrivateKeyFromBytes(packedSk)
40 pk2 := mode.PublicKeyFromBytes(packedPk)
41
42
43 msg := []byte("Some message")
44 signature := mode.Sign(sk2, msg)
45
46
47 if !mode.Verify(pk2, msg, signature) {
48 panic("incorrect signature")
49 }
50
51 fmt.Printf("O.K.")
52
53
54
55
56 }
57
View as plain text