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

Unified Diff: base/sha2_openssl.cc

Issue 6276002: Abstracts SHA256 context for NSS / OpenSSL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implements SHA256Context abstracting NSS / OpenSSL. Created 9 years, 11 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
Index: base/sha2_openssl.cc
diff --git a/base/sha2_openssl.cc b/base/sha2_openssl.cc
index afbce2f4f3485b530e9f4eea0fca471266f914f4..e54de6a501b6fa4401aa7855ff4b26d403efdf10 100644
--- a/base/sha2_openssl.cc
+++ b/base/sha2_openssl.cc
@@ -27,4 +27,37 @@ std::string SHA256HashString(const std::string& str) {
return output;
}
+namespace {
+
+class SHA256ContextOpenSSL : public SHA256Context {
+ public:
+ SHA256ContextOpenSSL() {
+ SHA256_Init(&ctx_);
+ }
+
+ virtual ~SHA256ContextOpenSSL() {
+ OPENSSL_cleanse(&ctx_, sizeof(ctx_));
+ }
+
+ virtual void Update(const std::string& str) {
+ SHA256_Update(&ctx_, reinterpret_cast<const unsigned char*>(str.data()),
+ str.size());
+ }
+
+ virtual void Finish(void* output, size_t len) {
+ ScopedOpenSSLSafeSizeBuffer<SHA256_DIGEST_LENGTH> result(
+ reinterpret_cast<unsigned char*>(output), len);
+ SHA256_Final(result.safe_buffer(), &ctx_);
+ }
+
+ private:
+ SHA256_CTX ctx_;
+};
+
+} // namespace
+
+SHA256Context* SHA256Context::Create() {
+ return new SHA256ContextOpenSSL();
+}
+
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698