OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "crypto/secure_hash.h" | 5 #include "crypto/secure_hash.h" |
6 | 6 |
7 #include <openssl/crypto.h> | 7 #include <openssl/crypto.h> |
8 #include <openssl/sha.h> | 8 #include <openssl/sha.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 static const int kSecureHashVersion = 1; | 23 static const int kSecureHashVersion = 1; |
24 | 24 |
25 SecureHashSHA256OpenSSL() { | 25 SecureHashSHA256OpenSSL() { |
26 SHA256_Init(&ctx_); | 26 SHA256_Init(&ctx_); |
27 } | 27 } |
28 | 28 |
29 virtual ~SecureHashSHA256OpenSSL() { | 29 virtual ~SecureHashSHA256OpenSSL() { |
30 OPENSSL_cleanse(&ctx_, sizeof(ctx_)); | 30 OPENSSL_cleanse(&ctx_, sizeof(ctx_)); |
31 } | 31 } |
32 | 32 |
33 virtual void Update(const void* input, size_t len) OVERRIDE { | 33 virtual void Update(const void* input, size_t len) override { |
34 SHA256_Update(&ctx_, static_cast<const unsigned char*>(input), len); | 34 SHA256_Update(&ctx_, static_cast<const unsigned char*>(input), len); |
35 } | 35 } |
36 | 36 |
37 virtual void Finish(void* output, size_t len) OVERRIDE { | 37 virtual void Finish(void* output, size_t len) override { |
38 ScopedOpenSSLSafeSizeBuffer<SHA256_DIGEST_LENGTH> result( | 38 ScopedOpenSSLSafeSizeBuffer<SHA256_DIGEST_LENGTH> result( |
39 static_cast<unsigned char*>(output), len); | 39 static_cast<unsigned char*>(output), len); |
40 SHA256_Final(result.safe_buffer(), &ctx_); | 40 SHA256_Final(result.safe_buffer(), &ctx_); |
41 } | 41 } |
42 | 42 |
43 virtual bool Serialize(Pickle* pickle) OVERRIDE; | 43 virtual bool Serialize(Pickle* pickle) override; |
44 virtual bool Deserialize(PickleIterator* data_iterator) OVERRIDE; | 44 virtual bool Deserialize(PickleIterator* data_iterator) override; |
45 | 45 |
46 private: | 46 private: |
47 SHA256_CTX ctx_; | 47 SHA256_CTX ctx_; |
48 }; | 48 }; |
49 | 49 |
50 bool SecureHashSHA256OpenSSL::Serialize(Pickle* pickle) { | 50 bool SecureHashSHA256OpenSSL::Serialize(Pickle* pickle) { |
51 if (!pickle) | 51 if (!pickle) |
52 return false; | 52 return false; |
53 | 53 |
54 if (!pickle->WriteInt(kSecureHashVersion) || | 54 if (!pickle->WriteInt(kSecureHashVersion) || |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 switch (algorithm) { | 93 switch (algorithm) { |
94 case SHA256: | 94 case SHA256: |
95 return new SecureHashSHA256OpenSSL(); | 95 return new SecureHashSHA256OpenSSL(); |
96 default: | 96 default: |
97 NOTIMPLEMENTED(); | 97 NOTIMPLEMENTED(); |
98 return NULL; | 98 return NULL; |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 } // namespace crypto | 102 } // namespace crypto |
OLD | NEW |