| OLD | NEW |
| (Empty) | |
| 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 #include "net/cert/merkle_audit_proof.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 |
| 9 namespace net { |
| 10 namespace ct { |
| 11 |
| 12 uint64_t CalculateAuditPathLength(uint64_t leaf_index, uint64_t tree_size) { |
| 13 // RFC6962, section 2.1.1, describes audit paths. |
| 14 // Algorithm taken from |
| 15 // https://github.com/google/certificate-transparency-rfcs/blob/c8844de6bd0b5d
3d16bac79865e6edef533d760b/dns/draft-ct-over-dns.md#retrieve-merkle-audit-proof-
from-log-by-leaf-hash. |
| 16 CHECK_LT(leaf_index, tree_size); |
| 17 uint64_t length = 0; |
| 18 uint64_t index = leaf_index; |
| 19 uint64_t last_node = tree_size - 1; |
| 20 |
| 21 while (last_node != 0) { |
| 22 if ((index % 2 != 0) || index != last_node) |
| 23 ++length; |
| 24 index /= 2; |
| 25 last_node /= 2; |
| 26 } |
| 27 |
| 28 return length; |
| 29 } |
| 30 |
| 31 MerkleAuditProof::MerkleAuditProof() {} |
| 32 |
| 33 MerkleAuditProof::MerkleAuditProof(const std::string& log_id, |
| 34 uint64_t leaf_index, |
| 35 const std::vector<std::string>& audit_path) |
| 36 : log_id(log_id), leaf_index(leaf_index), nodes(audit_path) {} |
| 37 |
| 38 MerkleAuditProof::~MerkleAuditProof() {} |
| 39 |
| 40 } // namespace ct |
| 41 } // namespace net |
| OLD | NEW |