From ebd9efbf32065baa261b2af1625991100ed23bf7 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Sat, 5 Jun 2021 17:15:47 +0200 Subject: attached sign and verify methods to the basic types --- types/types.go | 40 +++++++++++++++++++++++++++++++++++++++- types/types_test.go | 5 +++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/types/types.go b/types/types.go index d031b29..405c825 100644 --- a/types/types.go +++ b/types/types.go @@ -1,9 +1,12 @@ package types import ( + "crypto" + "fmt" + "strings" + "crypto/ed25519" "crypto/sha256" - "strings" ) const ( @@ -113,3 +116,38 @@ type LeafRequest struct { type CosignatureRequest struct { SigIdent } + +// Sign signs the tree head using the log's signature scheme +func (th *TreeHead) Sign(signer crypto.Signer) (*SignedTreeHead, error) { + sig, err := signer.Sign(nil, th.Marshal(), crypto.Hash(0)) + if err != nil { + return nil, fmt.Errorf("Sign: %v", err) + } + + sigident := SigIdent{ + KeyHash: Hash(signer.Public().(ed25519.PublicKey)[:]), + Signature: &[SignatureSize]byte{}, + } + copy(sigident.Signature[:], sig) + return &SignedTreeHead{ + TreeHead: *th, + SigIdent: []*SigIdent{ + &sigident, + }, + }, nil +} + +// Verify verifies the tree head signature using the log's signature scheme +func (th *TreeHead) Verify(pub crypto.PublicKey) error { // TODO + return nil +} + +// Verify checks if a leaf is included in the log +func (p *InclusionProof) Verify(leaf *Leaf, th *TreeHead) error { // TODO + return nil +} + +// Verify checks if two tree heads are consistent +func (p *ConsistencyProof) Verify(oldTH, newTH *TreeHead) error { // TODO + return nil +} diff --git a/types/types_test.go b/types/types_test.go index 9d76c73..22a03d4 100644 --- a/types/types_test.go +++ b/types/types_test.go @@ -51,3 +51,8 @@ func TestEndpointPath(t *testing.T) { } } } + +func TestTreeHeadSign(t *testing.T) {} +func TestTreeHeadVerify(t *testing.T) {} +func TestInclusionProofVerify(t *testing.T) {} +func TestConsistencyProofVerify(t *testing.T) {} -- cgit v1.2.3