aboutsummaryrefslogtreecommitdiff
path: root/crypto.go
blob: 546fc0a0892773492e6f6832f809d8d94a0144ea (plain)
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
package stfe

import (
	"fmt"
	"time"

	"crypto"
	"crypto/rand"
)

// genV1Sdi issues a new SignedDebugInfoV1 StItem from a serialized leaf value
func (lp *LogParameters) genV1Sdi(serialized []byte) (*StItem, error) {
	sig, err := lp.Signer.Sign(rand.Reader, serialized, crypto.Hash(0)) // ed25519
	if err != nil {
		return nil, fmt.Errorf("ed25519 signature failed: %v", err)
	}
	lastSdiTimestamp.Set(float64(time.Now().Unix()), lp.id())
	return NewSignedDebugInfoV1(lp.LogId, []byte("reserved"), sig), nil
}

// genV1Sth issues a new SignedTreeHeadV1 StItem from a TreeHeadV1 structure
func (lp *LogParameters) genV1Sth(th *TreeHeadV1) (*StItem, error) {
	serialized, err := th.Marshal()
	if err != nil {
		return nil, fmt.Errorf("failed tls marshaling tree head: %v", err)
	}
	sig, err := lp.Signer.Sign(rand.Reader, serialized, crypto.Hash(0)) // ed25519
	if err != nil {
		return nil, fmt.Errorf("ed25519 signature failed: %v", err)
	}
	lastSthTimestamp.Set(float64(time.Now().Unix()), lp.id())
	lastSthSize.Set(float64(th.TreeSize), lp.id())
	return NewSignedTreeHeadV1(th, lp.LogId, sig), nil
}