xref: /aosp_15_r20/external/cronet/net/cert/merkle_audit_proof.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2016 The Chromium Authors
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 "net/base/net_export.h"
14 
15 namespace net::ct {
16 
17 // Returns the length of the audit path for a leaf at |leaf_index| in a Merkle
18 // tree containing |tree_size| leaves.
19 // The |leaf_index| must be less than the |tree_size|.
20 NET_EXPORT uint64_t CalculateAuditPathLength(uint64_t leaf_index,
21                                              uint64_t tree_size);
22 
23 // Audit proof for a Merkle tree leaf, as defined in section 2.1.1. of RFC6962.
24 struct NET_EXPORT MerkleAuditProof {
25   MerkleAuditProof();
26   MerkleAuditProof(const MerkleAuditProof& other);
27   MerkleAuditProof(uint64_t leaf_index,
28                    uint64_t tree_size,
29                    const std::vector<std::string>& audit_path);
30   ~MerkleAuditProof();
31 
32   // Index of the tree leaf in the log.
33   // Must be provided when fetching the proof from the log.
34   uint64_t leaf_index = 0;
35 
36   // The proof works only in conjunction with an STH for this tree size.
37   // Must be provided when fetching the proof from the log.
38   uint64_t tree_size = 0;
39 
40   // Audit path nodes.
41   // Using the leaf hash and these nodes, the STH hash can be reconstructed to
42   // prove that leaf was included in the log's tree.
43   std::vector<std::string> nodes;
44 };
45 
46 }  // namespace net::ct
47 
48 #endif  // NET_CERT_MERKLE_AUDIT_PROOF_H_
49