Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Unified Diff: net/cert/merkle_tree_leaf.cc

Issue 1945183005: Adds function for generating MerkleTreeLeaf hash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ct_merkle_tree_leaf_encode
Patch Set: Rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/cert/merkle_tree_leaf.h ('k') | net/cert/merkle_tree_leaf_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert/merkle_tree_leaf.cc
diff --git a/net/cert/merkle_tree_leaf.cc b/net/cert/merkle_tree_leaf.cc
index 6d67255e36f49d630f55ed352d7d33a9e93d2ad4..21e2814402cacc2adfb1aa90d90ec38472e1bf11 100644
--- a/net/cert/merkle_tree_leaf.cc
+++ b/net/cert/merkle_tree_leaf.cc
@@ -4,7 +4,9 @@
#include "net/cert/merkle_tree_leaf.h"
+#include "crypto/sha2.h"
#include "net/cert/ct_objects_extractor.h"
+#include "net/cert/ct_serialization.h"
#include "net/cert/x509_certificate.h"
namespace net {
@@ -15,6 +17,16 @@ MerkleTreeLeaf::MerkleTreeLeaf() {}
MerkleTreeLeaf::~MerkleTreeLeaf() {}
+bool Hash(const MerkleTreeLeaf& tree_leaf, std::string* out) {
+ // Prepend 0 byte as per RFC 6962, section-2.1
+ std::string leaf_in_tls_format("\x00", 1);
+ if (!EncodeTreeLeaf(tree_leaf, &leaf_in_tls_format))
+ return false;
+
+ *out = crypto::SHA256HashString(leaf_in_tls_format);
+ return true;
+}
+
bool GetMerkleTreeLeaf(const X509Certificate* cert,
const SignedCertificateTimestamp* sct,
MerkleTreeLeaf* merkle_tree_leaf) {
« no previous file with comments | « net/cert/merkle_tree_leaf.h ('k') | net/cert/merkle_tree_leaf_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698