Source file
src/crypto/mlkem/example_test.go
1
2
3
4
5 package mlkem_test
6
7 import (
8 "crypto/mlkem"
9 "log"
10 )
11
12 func Example() {
13
14 dk, err := mlkem.GenerateKey768()
15 if err != nil {
16 log.Fatal(err)
17 }
18 encapsulationKey := dk.EncapsulationKey().Bytes()
19
20
21
22 ciphertext := Bob(encapsulationKey)
23
24
25 sharedSecret, err := dk.Decapsulate(ciphertext)
26 if err != nil {
27 log.Fatal(err)
28 }
29
30
31 _ = sharedSecret
32 }
33
34 func Bob(encapsulationKey []byte) (ciphertext []byte) {
35
36 ek, err := mlkem.NewEncapsulationKey768(encapsulationKey)
37 if err != nil {
38 log.Fatal(err)
39 }
40 sharedSecret, ciphertext := ek.Encapsulate()
41
42
43 _ = sharedSecret
44
45
46 return ciphertext
47 }
48
View as plain text