| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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_)); | 27 memset(&ctx_, 0, sizeof(ctx_)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 // SecureHash implementation: | 30 // SecureHash implementation: |
| 31 virtual void Update(const void* input, size_t len) OVERRIDE { | 31 virtual void Update(const void* input, size_t len) override { |
| 32 SHA256_Update(&ctx_, static_cast<const unsigned char*>(input), len); | 32 SHA256_Update(&ctx_, static_cast<const unsigned char*>(input), len); |
| 33 } | 33 } |
| 34 | 34 |
| 35 virtual void Finish(void* output, size_t len) OVERRIDE { | 35 virtual void Finish(void* output, size_t len) override { |
| 36 SHA256_End(&ctx_, static_cast<unsigned char*>(output), NULL, | 36 SHA256_End(&ctx_, static_cast<unsigned char*>(output), NULL, |
| 37 static_cast<unsigned int>(len)); | 37 static_cast<unsigned int>(len)); |
| 38 } | 38 } |
| 39 | 39 |
| 40 virtual bool Serialize(Pickle* pickle) OVERRIDE; | 40 virtual bool Serialize(Pickle* pickle) override; |
| 41 virtual bool Deserialize(PickleIterator* data_iterator) OVERRIDE; | 41 virtual bool Deserialize(PickleIterator* data_iterator) override; |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 SHA256Context ctx_; | 44 SHA256Context ctx_; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 bool SecureHashSHA256NSS::Serialize(Pickle* pickle) { | 47 bool SecureHashSHA256NSS::Serialize(Pickle* pickle) { |
| 48 if (!pickle) | 48 if (!pickle) |
| 49 return false; | 49 return false; |
| 50 | 50 |
| 51 if (!pickle->WriteInt(kSecureHashVersion) || | 51 if (!pickle->WriteInt(kSecureHashVersion) || |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 switch (algorithm) { | 87 switch (algorithm) { |
| 88 case SHA256: | 88 case SHA256: |
| 89 return new SecureHashSHA256NSS(); | 89 return new SecureHashSHA256NSS(); |
| 90 default: | 90 default: |
| 91 NOTIMPLEMENTED(); | 91 NOTIMPLEMENTED(); |
| 92 return NULL; | 92 return NULL; |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace crypto | 96 } // namespace crypto |
| OLD | NEW |