-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmldsa.go
More file actions
59 lines (50 loc) · 1.4 KB
/
Copy pathmldsa.go
File metadata and controls
59 lines (50 loc) · 1.4 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//go:build mldsa
// Run with "go run -tags mldsa -mod=mod ./cmd/litewitness/testdata/gentest"
// and re-run "go mod tidy" after use to clean up its dependencies.
package main
import (
"crypto/rand"
"encoding/base64"
"encoding/hex"
"flag"
"fmt"
"log"
"filippo.io/mldsa"
"filippo.io/torchwood"
"golang.org/x/mod/sumdb/tlog"
)
var seedFlag = flag.String("seed", "", "hex-encoded seed")
func main() {
origin := "example.com/mldsa-log"
flag.Parse()
var seed []byte
if *seedFlag == "" {
seed = make([]byte, 32)
if _, err := rand.Read(seed); err != nil {
log.Fatal(err)
}
} else {
seed = make([]byte, hex.DecodedLen(len(*seedFlag)))
if _, err := hex.Decode(seed, []byte(*seedFlag)); err != nil {
log.Fatal(err)
}
}
fmt.Printf("- seed: %x\n", seed)
logKey, err := mldsa.NewPrivateKey(mldsa.MLDSA44(), seed)
if err != nil {
log.Fatal(err)
}
signer, err := torchwood.NewCosignatureSigner(origin, logKey)
if err != nil {
log.Fatal(err)
}
fmt.Printf("- log vkey: %s\n", signer.Verifier().String())
// SignSubtree is used to get a deterministic timestamp (zero).
rootHash := tlog.RecordHash([]byte("testonly"))
checkpoint := fmt.Sprintf("%s\n%d\n%s\n", origin, 1, base64.StdEncoding.EncodeToString(rootHash[:]))
sigLine, err := signer.SignSubtree(origin, 0, 1, rootHash)
if err != nil {
log.Fatal(err)
}
fmt.Printf("- checkpoint (size 1):\n%s\n%s", checkpoint, string(sigLine))
}