| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "crypto/secure_hash.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/pickle.h" | |
| 11 #include "crypto/third_party/nss/chromium-blapi.h" | |
| 12 #include "crypto/third_party/nss/chromium-sha256.h" | |
| 13 | |
| 14 namespace crypto { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 class SecureHashSHA256NSS : public SecureHash { | |
| 19 public: | |
| 20 SecureHashSHA256NSS() { | |
| 21 SHA256_Begin(&ctx_); | |
| 22 } | |
| 23 | |
| 24 SecureHashSHA256NSS(const SecureHashSHA256NSS& other) { | |
| 25 SHA256_Clone(&ctx_, const_cast<SHA256Context*>(&other.ctx_)); | |
| 26 } | |
| 27 | |
| 28 ~SecureHashSHA256NSS() override { memset(&ctx_, 0, sizeof(ctx_)); } | |
| 29 | |
| 30 // SecureHash implementation: | |
| 31 void Update(const void* input, size_t len) override { | |
| 32 SHA256_Update(&ctx_, static_cast<const unsigned char*>(input), len); | |
| 33 } | |
| 34 | |
| 35 void Finish(void* output, size_t len) override { | |
| 36 SHA256_End(&ctx_, static_cast<unsigned char*>(output), NULL, | |
| 37 static_cast<unsigned int>(len)); | |
| 38 } | |
| 39 | |
| 40 SecureHash* Clone() const override { return new SecureHashSHA256NSS(*this); } | |
| 41 | |
| 42 size_t GetHashLength() const override { return SHA256_LENGTH; } | |
| 43 | |
| 44 private: | |
| 45 SHA256Context ctx_; | |
| 46 }; | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 50 SecureHash* SecureHash::Create(Algorithm algorithm) { | |
| 51 switch (algorithm) { | |
| 52 case SHA256: | |
| 53 return new SecureHashSHA256NSS(); | |
| 54 default: | |
| 55 NOTIMPLEMENTED(); | |
| 56 return NULL; | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 } // namespace crypto | |
| OLD | NEW |