diff --git a/merkletree/merkletree.go b/merkletree/merkletree.go index eb83a3a..ea23d3b 100644 --- a/merkletree/merkletree.go +++ b/merkletree/merkletree.go @@ -44,8 +44,8 @@ func (m *MerkleTree) Get(lookupIndex []byte) *AuthenticationPath { nodePointer = m.root authPath := &AuthenticationPath{ - treeNonce: m.nonce, - lookupIndex: lookupIndex, + TreeNonce: m.nonce, + LookupIndex: lookupIndex, } for { @@ -59,11 +59,11 @@ func (m *MerkleTree) Get(lookupIndex []byte) *AuthenticationPath { } direction := lookupIndexBits[depth] if direction { - authPath.prunedHashes = append(authPath.prunedHashes, + authPath.PrunedTree = append(authPath.PrunedTree, nodePointer.(*interiorNode).leftHash) nodePointer = nodePointer.(*interiorNode).rightChild } else { - authPath.prunedHashes = append(authPath.prunedHashes, + authPath.PrunedTree = append(authPath.PrunedTree, nodePointer.(*interiorNode).rightHash) nodePointer = nodePointer.(*interiorNode).leftChild } @@ -76,7 +76,7 @@ func (m *MerkleTree) Get(lookupIndex []byte) *AuthenticationPath { switch nodePointer.(type) { case *userLeafNode: pNode := nodePointer.(*userLeafNode).Clone(nil).(*userLeafNode) - authPath.leaf = pNode + authPath.Leaf = pNode if bytes.Equal(nodePointer.(*userLeafNode).index, lookupIndex) { return authPath } @@ -85,7 +85,7 @@ func (m *MerkleTree) Get(lookupIndex []byte) *AuthenticationPath { pNode.value = nil return authPath case *emptyNode: - authPath.leaf = nodePointer.(*emptyNode).Clone(nil).(*emptyNode) + authPath.Leaf = nodePointer.(*emptyNode).Clone(nil).(*emptyNode) return authPath } panic(ErrorInvalidTree) @@ -212,10 +212,6 @@ func (m *MerkleTree) recomputeHash() { m.hash = m.root.Hash(m) } -func (m *MerkleTree) GetHash() []byte { - return m.hash -} - func (m *MerkleTree) Clone() *MerkleTree { return &MerkleTree{ nonce: m.nonce, diff --git a/merkletree/merkletree_test.go b/merkletree/merkletree_test.go index f18d6f4..8e51285 100644 --- a/merkletree/merkletree_test.go +++ b/merkletree/merkletree_test.go @@ -46,18 +46,18 @@ func TestOneEntry(t *testing.T) { } r := m.Get(index) - if r.Leaf().Value() == nil { + if r.Leaf.Value() == nil { t.Error("Cannot find value of key:", key) return } - v := r.Leaf().Value() + v := r.Leaf.Value() if !bytes.Equal(v, val) { t.Errorf("Value mismatch %v / %v", v, val) } // Check leaf node hash h.Reset() - h.Write(r.Leaf().(*userLeafNode).salt) + h.Write(r.Leaf.(*userLeafNode).salt) h.Write([]byte(key)) h.Write(val) h.Read(commit[:]) @@ -77,7 +77,7 @@ func TestOneEntry(t *testing.T) { } r = m.Get([]byte("abc")) - if r.Leaf().Value() != nil { + if r.Leaf.Value() != nil { t.Error("Invalid look-up operation:", key) return } @@ -104,21 +104,21 @@ func TestTwoEntries(t *testing.T) { } ap1 := m.Get(index1) - if ap1.Leaf().Value() == nil { + if ap1.Leaf.Value() == nil { t.Error("Cannot find key:", key1) return } ap2 := m.Get(index2) - if ap2.Leaf().Value() == nil { + if ap2.Leaf.Value() == nil { t.Error("Cannot find key:", key2) return } - if !bytes.Equal(ap1.Leaf().Value(), []byte("value1")) { + if !bytes.Equal(ap1.Leaf.Value(), []byte("value1")) { t.Error(key1, "value mismatch") } - if !bytes.Equal(ap2.Leaf().Value(), []byte("value2")) { + if !bytes.Equal(ap2.Leaf.Value(), []byte("value2")) { t.Error(key2, "value mismatch") } } @@ -150,42 +150,42 @@ func TestThreeEntries(t *testing.T) { } ap1 := m.Get(index1) - if ap1.Leaf().Value() == nil { + if ap1.Leaf.Value() == nil { t.Error("Cannot find key:", index1) return } ap2 := m.Get(index2) - if ap2.Leaf().Value() == nil { + if ap2.Leaf.Value() == nil { t.Error("Cannot find key:", index2) return } ap3 := m.Get(index3) - if ap3.Leaf().Value() == nil { + if ap3.Leaf.Value() == nil { t.Error("Cannot find key:", index3) return } /* // since the first bit of ap2 index is false and the one of ap1 & ap3 are true - if ap2.Leaf().Level() != 1 { + if ap2.Leaf.Level() != 1 { t.Error("Malformed tree insertion") } // since n1 and n3 share first 2 bits - if ap1.Leaf().Level() != 3 { + if ap1.Leaf.Level() != 3 { t.Error("Malformed tree insertion") } - if ap3.Leaf().Level() != 3 { + if ap3.Leaf.Level() != 3 { t.Error("Malformed tree insertion") } */ - if !bytes.Equal(ap1.Leaf().Value(), []byte("value1")) { + if !bytes.Equal(ap1.Leaf.Value(), []byte("value1")) { t.Error(key1, "value mismatch") } - if !bytes.Equal(ap2.Leaf().Value(), []byte("value2")) { + if !bytes.Equal(ap2.Leaf.Value(), []byte("value2")) { t.Error(key2, "value mismatch") } - if !bytes.Equal(ap3.Leaf().Value(), []byte("value3")) { + if !bytes.Equal(ap3.Leaf.Value(), []byte("value3")) { t.Error(key3, "value mismatch") } } @@ -210,17 +210,17 @@ func TestInsertExistedKey(t *testing.T) { } ap := m.Get(index1) - if ap.Leaf().Value() == nil { + if ap.Leaf.Value() == nil { t.Error("Cannot find key:", key1) return } - if !bytes.Equal(ap.Leaf().Value(), []byte("new value")) { + if !bytes.Equal(ap.Leaf.Value(), []byte("new value")) { t.Error(index1, "value mismatch\n") } - if !bytes.Equal(ap.Leaf().Value(), val2) { - t.Errorf("Value mismatch %v / %v", ap.Leaf().Value(), val2) + if !bytes.Equal(ap.Leaf.Value(), val2) { + t.Errorf("Value mismatch %v / %v", ap.Leaf.Value(), val2) } val3 := []byte("new value 2") @@ -229,13 +229,13 @@ func TestInsertExistedKey(t *testing.T) { } ap = m.Get(index1) - if ap.Leaf().Value() == nil { + if ap.Leaf.Value() == nil { t.Error("Cannot find key:", key1) return } - if !bytes.Equal(ap.Leaf().Value(), val3) { - t.Errorf("Value mismatch %v / %v", ap.Leaf().Value(), val3) + if !bytes.Equal(ap.Leaf.Value(), val3) { + t.Errorf("Value mismatch %v / %v", ap.Leaf.Value(), val3) } } @@ -276,20 +276,20 @@ func TestTreeClone(t *testing.T) { // lookup ap := m2.Get(index1) - if ap.Leaf().Value() == nil { + if ap.Leaf.Value() == nil { t.Error("Cannot find key:", key1) return } - if !bytes.Equal(ap.Leaf().Value(), []byte("value1")) { + if !bytes.Equal(ap.Leaf.Value(), []byte("value1")) { t.Error(key1, "value mismatch\n") } ap = m2.Get(index2) - if ap.Leaf().Value() == nil { + if ap.Leaf.Value() == nil { t.Error("Cannot find key:", key2) return } - if !bytes.Equal(ap.Leaf().Value(), []byte("value2")) { + if !bytes.Equal(ap.Leaf.Value(), []byte("value2")) { t.Error(key2, "value mismatch\n") } } diff --git a/merkletree/pad.go b/merkletree/pad.go index e9fde82..51ab08a 100644 --- a/merkletree/pad.go +++ b/merkletree/pad.go @@ -54,7 +54,7 @@ func (pad *PAD) signTreeRoot(m *MerkleTree, epoch uint64) { panic(err) } } else { - prevStrHash = crypto.Digest(pad.latestSTR.sig) + prevStrHash = crypto.Digest(pad.latestSTR.Signature) } pad.latestSTR = NewSTR(pad.key, pad.policies, m, epoch, prevStrHash) } @@ -89,7 +89,7 @@ func (pad *PAD) Update(policies Policies) { pad.loadedEpochs = append(pad.loadedEpochs[:0], pad.loadedEpochs[n:]...) } - pad.updateInternal(policies, pad.latestSTR.epoch+1) + pad.updateInternal(policies, pad.latestSTR.Epoch+1) } func (pad *PAD) Set(key string, value []byte) error { @@ -98,7 +98,7 @@ func (pad *PAD) Set(key string, value []byte) error { } func (pad *PAD) Lookup(key string) (*AuthenticationPath, error) { - return pad.LookupInEpoch(key, pad.latestSTR.epoch) + return pad.LookupInEpoch(key, pad.latestSTR.Epoch) } func (pad *PAD) LookupInEpoch(key string, epoch uint64) (*AuthenticationPath, error) { @@ -106,14 +106,14 @@ func (pad *PAD) LookupInEpoch(key string, epoch uint64) (*AuthenticationPath, er if str == nil { return nil, ErrorSTRNotFound } - lookupIndex, proof := pad.computePrivateIndex(key, str.policies.vrfPrivate()) + lookupIndex, proof := pad.computePrivateIndex(key, str.Policies.vrfPrivate()) ap := str.tree.Get(lookupIndex) - ap.vrfProof = proof + ap.VrfProof = proof return ap, nil } func (pad *PAD) GetSTR(epoch uint64) *SignedTreeRoot { - if epoch >= pad.latestSTR.epoch { + if epoch >= pad.latestSTR.Epoch { return pad.latestSTR } return pad.snapshots[epoch] @@ -122,7 +122,7 @@ func (pad *PAD) GetSTR(epoch uint64) *SignedTreeRoot { func (pad *PAD) TB(key string, value []byte) (*TemporaryBinding, error) { str := pad.latestSTR index, _ := pad.computePrivateIndex(key, pad.policies.vrfPrivate()) - tb := str.sig + tb := str.Signature tb = append(tb, index...) tb = append(tb, value...) sig := crypto.Sign(pad.key, tb) @@ -130,9 +130,9 @@ func (pad *PAD) TB(key string, value []byte) (*TemporaryBinding, error) { err := pad.tree.Set(index, key, value) return &TemporaryBinding{ - index: index, - value: value, - sig: sig, + Index: index, + Value: value, + Signature: sig, }, err } diff --git a/merkletree/pad_test.go b/merkletree/pad_test.go index c145170..f8e9d51 100644 --- a/merkletree/pad_test.go +++ b/merkletree/pad_test.go @@ -66,8 +66,8 @@ func TestPADHashChain(t *testing.T) { t.Fatal("Malformed PAD Update") } - if str.epoch != uint64(i) { - t.Fatal("Got invalid STR", "want", i, "got", str.epoch) + if str.Epoch != uint64(i) { + t.Fatal("Got invalid STR", "want", i, "got", str.Epoch) } } @@ -76,62 +76,62 @@ func TestPADHashChain(t *testing.T) { t.Error("Cannot get STR") } - if str.epoch != 3 { - t.Error("Got invalid STR", "want", 3, "got", str.epoch) + if str.Epoch != 3 { + t.Error("Got invalid STR", "want", 3, "got", str.Epoch) } // lookup ap, _ := pad.Lookup(key1) - if ap.Leaf().Value() == nil { + if ap.Leaf.Value() == nil { t.Error("Cannot find key:", key1) return } - if !bytes.Equal(ap.Leaf().Value(), val1) { + if !bytes.Equal(ap.Leaf.Value(), val1) { t.Error(key1, "value mismatch") } ap, _ = pad.Lookup(key2) - if ap.Leaf().Value() == nil { + if ap.Leaf.Value() == nil { t.Error("Cannot find key:", key2) return } - if !bytes.Equal(ap.Leaf().Value(), val2) { + if !bytes.Equal(ap.Leaf.Value(), val2) { t.Error(key2, "value mismatch") } ap, _ = pad.Lookup(key3) - if ap.Leaf().Value() == nil { + if ap.Leaf.Value() == nil { t.Error("Cannot find key:", key3) return } - if !bytes.Equal(ap.Leaf().Value(), val3) { + if !bytes.Equal(ap.Leaf.Value(), val3) { t.Error(key3, "value mismatch") } ap, err = pad.LookupInEpoch(key2, 1) if err != nil { t.Error(err) - } else if ap.Leaf().Value() != nil { + } else if ap.Leaf.Value() != nil { t.Error("Found unexpected key", key2, "in STR #", 1) } ap, err = pad.LookupInEpoch(key2, 2) if err != nil { t.Error(err) - } else if ap.Leaf().Value() == nil { + } else if ap.Leaf.Value() == nil { t.Error("Cannot find key", key2, "in STR #", 2) } ap, err = pad.LookupInEpoch(key3, 2) if err != nil { t.Error(err) - } else if ap.Leaf().Value() != nil { + } else if ap.Leaf.Value() != nil { t.Error("Found unexpected key", key3, "in STR #", 2) } ap, err = pad.LookupInEpoch(key3, 3) if err != nil { t.Error(err) - } else if ap.Leaf().Value() == nil { + } else if ap.Leaf.Value() == nil { t.Error("Cannot find key", key3, "in STR #", 3) } } @@ -201,25 +201,25 @@ func TestPoliciesChange(t *testing.T) { pad.Update(nil) ap, _ := pad.Lookup(key1) - if ap.Leaf().Value() == nil { + if ap.Leaf.Value() == nil { t.Error("Cannot find key:", key1) } - if !bytes.Equal(ap.Leaf().Value(), val1) { + if !bytes.Equal(ap.Leaf.Value(), val1) { t.Error(key1, "value mismatch") } ap, _ = pad.Lookup(key2) - if ap.Leaf().Value() == nil { + if ap.Leaf.Value() == nil { t.Error("Cannot find key:", key2) } - if !bytes.Equal(ap.Leaf().Value(), val2) { + if !bytes.Equal(ap.Leaf.Value(), val2) { t.Error(key2, "value mismatch") } ap, err = pad.LookupInEpoch(key1, 1) if err != nil { t.Error(err) - } else if !bytes.Equal(ap.Leaf().Value(), val1) { + } else if !bytes.Equal(ap.Leaf.Value(), val1) { t.Error(key1, "value mismatch") } ap, err = pad.LookupInEpoch(key2, 2) @@ -229,9 +229,9 @@ func TestPoliciesChange(t *testing.T) { ap, err = pad.LookupInEpoch(key3, 3) if err != nil { t.Error(err) - } else if ap.Leaf().Value() == nil { + } else if ap.Leaf.Value() == nil { t.Error("Cannot find key", key3, "in STR #", 3) - } else if !bytes.Equal(ap.Leaf().Value(), val3) { + } else if !bytes.Equal(ap.Leaf.Value(), val3) { t.Error(key3, "value mismatch") } } diff --git a/merkletree/policy.go b/merkletree/policy.go index 2f937d6..dbdb21c 100644 --- a/merkletree/policy.go +++ b/merkletree/policy.go @@ -9,21 +9,20 @@ import ( type TimeStamp uint64 type Policies interface { - EpochDeadline() TimeStamp Serialize() []byte vrfPrivate() *[vrf.SecretKeySize]byte } type ConiksPolicies struct { vrfPrivateKey *[vrf.SecretKeySize]byte - epochDeadline TimeStamp + EpochDeadline TimeStamp } var _ Policies = (*ConiksPolicies)(nil) func NewPolicies(epDeadline TimeStamp, vrfPrivKey *[vrf.SecretKeySize]byte) Policies { return &ConiksPolicies{ - epochDeadline: epDeadline, + EpochDeadline: epDeadline, vrfPrivateKey: vrfPrivKey, } } @@ -34,7 +33,7 @@ func (p *ConiksPolicies) Serialize() []byte { var bs []byte bs = append(bs, []byte(Version)...) // lib Version bs = append(bs, []byte(crypto.HashID)...) // cryptographic algorithms in use - bs = append(bs, util.ULongToBytes(uint64(p.epochDeadline))...) // epoch deadline + bs = append(bs, util.ULongToBytes(uint64(p.EpochDeadline))...) // epoch deadline bs = append(bs, vrf.Public(p.vrfPrivateKey)...) // vrf public key return bs } @@ -42,7 +41,3 @@ func (p *ConiksPolicies) Serialize() []byte { func (p *ConiksPolicies) vrfPrivate() *[vrf.SecretKeySize]byte { return p.vrfPrivateKey } - -func (p *ConiksPolicies) EpochDeadline() TimeStamp { - return p.epochDeadline -} diff --git a/merkletree/proof.go b/merkletree/proof.go index d7b506e..4dfce10 100644 --- a/merkletree/proof.go +++ b/merkletree/proof.go @@ -1,31 +1,11 @@ package merkletree type AuthenticationPath struct { - treeNonce []byte - prunedHashes [][]byte - lookupIndex []byte - vrfProof []byte - leaf ProofNode -} - -func (ap *AuthenticationPath) TreeNonce() []byte { - return ap.treeNonce -} - -func (ap *AuthenticationPath) PrunedTree() [][]byte { - return ap.prunedHashes -} - -func (ap *AuthenticationPath) LookupIndex() []byte { - return ap.lookupIndex -} - -func (ap *AuthenticationPath) VrfProof() []byte { - return ap.vrfProof -} - -func (ap *AuthenticationPath) Leaf() ProofNode { - return ap.leaf + TreeNonce []byte + PrunedTree [][]byte + LookupIndex []byte + VrfProof []byte + Leaf ProofNode } type ProofNode interface { diff --git a/merkletree/proof_test.go b/merkletree/proof_test.go index b82ab38..1f8e13a 100644 --- a/merkletree/proof_test.go +++ b/merkletree/proof_test.go @@ -10,12 +10,12 @@ import ( ) func computeLeafHash(ap *AuthenticationPath) (leafHash []byte) { - leaf := ap.Leaf() + leaf := ap.Leaf if !leaf.IsEmpty() { // user leaf node leafHash = crypto.Digest( []byte{LeafIdentifier}, // K_leaf - []byte(ap.TreeNonce()), // K_n + []byte(ap.TreeNonce), // K_n []byte(leaf.Index()), // i []byte(util.IntToBytes(leaf.Level())), // l []byte(leaf.Commitment()), // commit(key|| value) @@ -24,7 +24,7 @@ func computeLeafHash(ap *AuthenticationPath) (leafHash []byte) { // empty leaf node leafHash = crypto.Digest( []byte{EmptyBranchIdentifier}, // K_empty - []byte(ap.TreeNonce()), // K_n + []byte(ap.TreeNonce), // K_n []byte(leaf.Index()), // i []byte(util.IntToBytes(leaf.Level())), // l ) @@ -33,10 +33,10 @@ func computeLeafHash(ap *AuthenticationPath) (leafHash []byte) { } func authPathHash(ap *AuthenticationPath) []byte { - prunedHashes := ap.PrunedTree() + prunedHashes := ap.PrunedTree hash := computeLeafHash(ap) - depth := ap.Leaf().Level() - 1 - indexBits := util.ToBits(ap.Leaf().Index()) + depth := ap.Leaf.Level() - 1 + indexBits := util.ToBits(ap.Leaf.Index()) for depth > -1 { if indexBits[depth] { // right child hash = crypto.Digest(prunedHashes[depth], hash) @@ -55,33 +55,33 @@ func verifyProof(t *testing.T, ap *AuthenticationPath, treeHash []byte, key stri } // step 1. Verify the auth path of the returned leaf - if bytes.Equal(ap.Leaf().Index(), ap.LookupIndex()) { + if bytes.Equal(ap.Leaf.Index(), ap.LookupIndex) { // proof of inclusion // make sure we got a userLeafNode - if _, ok := ap.Leaf().(*userLeafNode); !ok { + if _, ok := ap.Leaf.(*userLeafNode); !ok { t.Error("Expect a user leaf node in returned path") } } else { // proof of absence // step 2. vrf_verify(i, alice) == true // we probably want to use vrf.Verify() here instead - if !bytes.Equal(vrf.Compute([]byte(key), vrfPrivKey1), ap.LookupIndex()) { + if !bytes.Equal(vrf.Compute([]byte(key), vrfPrivKey1), ap.LookupIndex) { t.Error("VRF verify returns false") } // step 3. Check that where i and j differ is at bit l - indexBits := util.ToBits(ap.Leaf().Index()) - lookupIndexBits := util.ToBits(ap.LookupIndex()) + indexBits := util.ToBits(ap.Leaf.Index()) + lookupIndexBits := util.ToBits(ap.LookupIndex) - for i := 0; i < ap.Leaf().Level(); i++ { + for i := 0; i < ap.Leaf.Level(); i++ { if indexBits[i] != lookupIndexBits[i] { t.Error("Invalid proof of absence. Expect indecies share the same prefix", - "lookup index: ", indexBits[:ap.Leaf().Level()], - "leaf index: ", lookupIndexBits[:ap.Leaf().Level()]) + "lookup index: ", indexBits[:ap.Leaf.Level()], + "leaf index: ", lookupIndexBits[:ap.Leaf.Level()]) } } - if indexBits[ap.Leaf().Level()+1] == lookupIndexBits[ap.Leaf().Level()+1] { - t.Error("Invalid proof of absence. Expect indecies differ is at bit", ap.Leaf().Level()+1) + if indexBits[ap.Leaf.Level()+1] == lookupIndexBits[ap.Leaf.Level()+1] { + t.Error("Invalid proof of absence. Expect indecies differ is at bit", ap.Leaf.Level()+1) } } } @@ -115,42 +115,42 @@ func TestVerifyProof(t *testing.T) { m.recomputeHash() ap1 := m.Get(index1) - if ap1.Leaf().Value() == nil { + if ap1.Leaf.Value() == nil { t.Error("Cannot find key:", key1) return } ap2 := m.Get(index2) - if ap2.Leaf().Value() == nil { + if ap2.Leaf.Value() == nil { t.Error("Cannot find key:", key2) return } ap3 := m.Get(index3) - if ap3.Leaf().Value() == nil { + if ap3.Leaf.Value() == nil { t.Error("Cannot find key:", key3) return } // proof of inclusion proof := m.Get(index3) - verifyProof(t, proof, m.GetHash(), key3) + verifyProof(t, proof, m.hash, key3) hash := authPathHash(proof) - if !bytes.Equal(m.GetHash(), hash) { + if !bytes.Equal(m.hash, hash) { t.Error("Invalid proof of inclusion") } // proof of absence absentIndex := vrf.Compute([]byte("123"), vrfPrivKey1) proof = m.Get(absentIndex) // shares the same prefix with an empty node - verifyProof(t, proof, m.GetHash(), "123") + verifyProof(t, proof, m.hash, "123") authPathHash(proof) - if _, ok := proof.Leaf().(*emptyNode); !ok { + if _, ok := proof.Leaf.(*emptyNode); !ok { t.Error("Invalid proof of absence. Expect an empty node in returned path") } /*proof = m.Get([]byte("key4")) // shares the same prefix with leaf node n2 - verifyProof(t, proof, m.GetHash(), "key4") + verifyProof(t, proof, m.Hash, "key4") authPathHash(proof) - if _, ok := proof.Leaf().(*userLeafNode); !ok { + if _, ok := proof.Leaf.(*userLeafNode); !ok { t.Error("Invalid proof of absence. Expect a user leaf node in returned path") }*/ } diff --git a/merkletree/str.go b/merkletree/str.go index 712aca1..0f43438 100644 --- a/merkletree/str.go +++ b/merkletree/str.go @@ -18,12 +18,12 @@ var ( // previous STR, and its signature. // STR should be final type SignedTreeRoot struct { - tree *MerkleTree - epoch uint64 - prevEpoch uint64 - prevStrHash []byte - sig []byte - policies Policies + tree *MerkleTree + Epoch uint64 + PreviousEpoch uint64 + PreviousSTRHash []byte + Signature []byte + Policies Policies } func NewSTR(key crypto.SigningKey, policies Policies, m *MerkleTree, epoch uint64, prevHash []byte) *SignedTreeRoot { @@ -35,14 +35,14 @@ func NewSTR(key crypto.SigningKey, policies Policies, m *MerkleTree, epoch uint6 prevEpoch = 0 } str := &SignedTreeRoot{ - tree: m, - epoch: epoch, - prevEpoch: prevEpoch, - prevStrHash: prevHash, - policies: policies, + tree: m, + Epoch: epoch, + PreviousEpoch: prevEpoch, + PreviousSTRHash: prevHash, + Policies: policies, } bytesPreSig := str.Serialize() - str.sig = crypto.Sign(key, bytesPreSig) + str.Signature = crypto.Sign(key, bytesPreSig) return str } @@ -50,32 +50,16 @@ func NewSTR(key crypto.SigningKey, policies Policies, m *MerkleTree, epoch uint6 // [epoch, previous epoch, tree hash, previous STR hash, policies serialization] func (str *SignedTreeRoot) Serialize() []byte { var strBytes []byte - strBytes = append(strBytes, util.ULongToBytes(str.epoch)...) // t - epoch number - if str.epoch > 0 { - strBytes = append(strBytes, util.ULongToBytes(str.prevEpoch)...) // t_prev - previous epoch number + strBytes = append(strBytes, util.ULongToBytes(str.Epoch)...) // t - epoch number + if str.Epoch > 0 { + strBytes = append(strBytes, util.ULongToBytes(str.PreviousEpoch)...) // t_prev - previous epoch number } strBytes = append(strBytes, str.tree.hash...) // root - strBytes = append(strBytes, str.prevStrHash...) // previous STR hash - strBytes = append(strBytes, str.policies.Serialize()...) // P + strBytes = append(strBytes, str.PreviousSTRHash...) // previous STR hash + strBytes = append(strBytes, str.Policies.Serialize()...) // P return strBytes } func (str *SignedTreeRoot) Root() []byte { return str.tree.hash } - -func (str *SignedTreeRoot) Epoch() uint64 { - return str.epoch -} - -func (str *SignedTreeRoot) PreviousEpoch() uint64 { - return str.prevEpoch -} - -func (str *SignedTreeRoot) PreviousSTRHash() []byte { - return str.prevStrHash -} - -func (str *SignedTreeRoot) Signature() []byte { - return str.sig -} diff --git a/merkletree/tb.go b/merkletree/tb.go index 3ba2047..ae1f0a4 100644 --- a/merkletree/tb.go +++ b/merkletree/tb.go @@ -1,19 +1,7 @@ package merkletree type TemporaryBinding struct { - index []byte - value []byte - sig []byte -} - -func (tb *TemporaryBinding) Index() []byte { - return tb.index -} - -func (tb *TemporaryBinding) Value() []byte { - return tb.value -} - -func (tb *TemporaryBinding) Signature() []byte { - return tb.sig + Index []byte + Value []byte + Signature []byte }