| 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
|
|
|