Chromium Code Reviews| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
| 9 #include "crypto/third_party/nss/chromium-blapi.h" | 9 #include "crypto/third_party/nss/chromium-blapi.h" |
| 10 #include "crypto/third_party/nss/chromium-sha256.h" | 10 #include "crypto/third_party/nss/chromium-sha256.h" |
| 11 | 11 |
| 12 namespace crypto { | 12 namespace crypto { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 const char kSHA256Descriptor[] = "NSS"; | 16 const char kSHA256Descriptor[] = "NSS"; |
| 17 | 17 |
| 18 class SecureHashSHA256NSS : public SecureHash { | 18 class SecureHashSHA256NSS : public SecureHash { |
| 19 public: | 19 public: |
| 20 static const int kSecureHashVersion = 1; | 20 static const int kSecureHashVersion = 1; |
| 21 | 21 |
| 22 SecureHashSHA256NSS() { | 22 SecureHashSHA256NSS() { |
| 23 SHA256_Begin(&ctx_); | 23 SHA256_Begin(&ctx_); |
| 24 } | 24 } |
| 25 | 25 |
| 26 virtual ~SecureHashSHA256NSS() { | 26 virtual ~SecureHashSHA256NSS() { |
| 27 memset(&ctx_, 0, sizeof(ctx_)); | |
|
wtc
2012/11/28 20:49:30
This matches what the SecureHashSHA256OpenSSL dest
agl
2012/11/28 21:25:30
I believe that there is a significant chance that
Ryan Sleevi
2012/11/28 22:17:08
Agreed. It's gonna be a nop on -O2 and higher.
Se
wtc
2012/11/28 22:39:36
Thanks for pointing this out. We should add a func
| |
| 27 } | 28 } |
| 28 | 29 |
| 29 // SecureHash implementation: | 30 // SecureHash implementation: |
| 30 virtual void Update(const void* input, size_t len) OVERRIDE { | 31 virtual void Update(const void* input, size_t len) OVERRIDE { |
| 31 SHA256_Update(&ctx_, static_cast<const unsigned char*>(input), len); | 32 SHA256_Update(&ctx_, static_cast<const unsigned char*>(input), len); |
| 32 } | 33 } |
| 33 | 34 |
| 34 virtual void Finish(void* output, size_t len) OVERRIDE { | 35 virtual void Finish(void* output, size_t len) OVERRIDE { |
| 35 SHA256_End(&ctx_, static_cast<unsigned char*>(output), NULL, | 36 SHA256_End(&ctx_, static_cast<unsigned char*>(output), NULL, |
| 36 static_cast<unsigned int>(len)); | 37 static_cast<unsigned int>(len)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 switch (algorithm) { | 87 switch (algorithm) { |
| 87 case SHA256: | 88 case SHA256: |
| 88 return new SecureHashSHA256NSS(); | 89 return new SecureHashSHA256NSS(); |
| 89 default: | 90 default: |
| 90 NOTIMPLEMENTED(); | 91 NOTIMPLEMENTED(); |
| 91 return NULL; | 92 return NULL; |
| 92 } | 93 } |
| 93 } | 94 } |
| 94 | 95 |
| 95 } // namespace crypto | 96 } // namespace crypto |
| OLD | NEW |