1// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_CERT_MERKLE_AUDIT_PROOF_H_
6#define NET_CERT_MERKLE_AUDIT_PROOF_H_
7
8#include <stdint.h>
9
10#include <string>
11#include <vector>
12
13#include "base/macros.h"
14#include "net/base/net_export.h"
15
16namespace net {
17namespace ct {
18
19// Returns the length of the audit path for a leaf at |leaf_index| in a Merkle
20// tree containing |tree_size| leaves.
21// The |leaf_index| must be less than the |tree_size|.
22NET_EXPORT uint64_t CalculateAuditPathLength(uint64_t leaf_index,
23 uint64_t tree_size);
24
25// Audit proof for a Merkle tree leaf, as defined in section 2.1.1. of RFC6962.
26struct NET_EXPORT MerkleAuditProof {
27 MerkleAuditProof();
28 MerkleAuditProof(const MerkleAuditProof& other);
29 MerkleAuditProof(uint64_t leaf_index,
30 uint64_t tree_size,
31 const std::vector<std::string>& audit_path);
32 ~MerkleAuditProof();
33
34 // Index of the tree leaf in the log.
35 // Must be provided when fetching the proof from the log.
36 uint64_t leaf_index = 0;
37
38 // The proof works only in conjunction with an STH for this tree size.
39 // Must be provided when fetching the proof from the log.
40 uint64_t tree_size = 0;
41
42 // Audit path nodes.
43 // Using the leaf hash and these nodes, the STH hash can be reconstructed to
44 // prove that leaf was included in the log's tree.
45 std::vector<std::string> nodes;
46};
47
48} // namespace ct
49} // namespace net
50
51#endif // NET_CERT_MERKLE_AUDIT_PROOF_H_
52