Index: base/secure_hash_openssl.cc |
diff --git a/base/secure_hash_openssl.cc b/base/secure_hash_openssl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d0adf762232c4a224742483eeb08f034a135a1be |
--- /dev/null |
+++ b/base/secure_hash_openssl.cc |
@@ -0,0 +1,52 @@ |
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/secure_hash.h" |
+ |
+#include <openssl/ssl.h> |
+ |
+#include "base/basictypes.h" |
+#include "base/logging.h" |
+#include "base/openssl_util.h" |
+#include "base/stl_util-inl.h" |
wtc
2011/01/25 19:06:43
Remove this header.
bulach
2011/01/25 20:33:41
Done.
|
+ |
+namespace base { |
+ |
+namespace { |
+ |
+class SecureHashSHA256OpenSSL : public SecureHash { |
+ public: |
+ SecureHashSHA256OpenSSL() { |
+ SHA256_Init(&ctx_); |
+ } |
+ |
+ virtual ~SecureHashSHA256OpenSSL() { |
+ 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 |
+ |
+SecureHash* SecureHash::Create(Type type) { |
+ if (type == TYPE_SHA256) |
+ return new SecureHashSHA256OpenSSL(); |
+ NOTIMPLEMENTED(); |
+ return NULL; |
wtc
2011/01/25 19:06:43
Use a switch statement.
bulach
2011/01/25 20:33:41
Done.
|
+} |
+ |
+} // namespace base |