OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 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 "base/secure_hash.h" | |
6 | |
7 #include <openssl/ssl.h> | |
8 | |
9 #include "base/basictypes.h" | |
10 #include "base/logging.h" | |
11 #include "base/openssl_util.h" | |
12 #include "base/stl_util-inl.h" | |
wtc
2011/01/25 19:06:43
Remove this header.
bulach
2011/01/25 20:33:41
Done.
| |
13 | |
14 namespace base { | |
15 | |
16 namespace { | |
17 | |
18 class SecureHashSHA256OpenSSL : public SecureHash { | |
19 public: | |
20 SecureHashSHA256OpenSSL() { | |
21 SHA256_Init(&ctx_); | |
22 } | |
23 | |
24 virtual ~SecureHashSHA256OpenSSL() { | |
25 OPENSSL_cleanse(&ctx_, sizeof(ctx_)); | |
26 } | |
27 | |
28 virtual void Update(const std::string& str) { | |
29 SHA256_Update(&ctx_, reinterpret_cast<const unsigned char*>(str.data()), | |
30 str.size()); | |
31 } | |
32 | |
33 virtual void Finish(void* output, size_t len) { | |
34 ScopedOpenSSLSafeSizeBuffer<SHA256_DIGEST_LENGTH> result( | |
35 reinterpret_cast<unsigned char*>(output), len); | |
36 SHA256_Final(result.safe_buffer(), &ctx_); | |
37 } | |
38 | |
39 private: | |
40 SHA256_CTX ctx_; | |
41 }; | |
42 | |
43 } // namespace | |
44 | |
45 SecureHash* SecureHash::Create(Type type) { | |
46 if (type == TYPE_SHA256) | |
47 return new SecureHashSHA256OpenSSL(); | |
48 NOTIMPLEMENTED(); | |
49 return NULL; | |
wtc
2011/01/25 19:06:43
Use a switch statement.
bulach
2011/01/25 20:33:41
Done.
| |
50 } | |
51 | |
52 } // namespace base | |
OLD | NEW |