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 <openssl/mem.h> | 7 #include <openssl/mem.h> |
| 8 #include <openssl/sha.h> | 8 #include <openssl/sha.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/pickle.h" | 12 #include "base/pickle.h" |
| 13 #include "crypto/openssl_util.h" | 13 #include "crypto/openssl_util.h" |
| 14 | 14 |
| 15 namespace crypto { | 15 namespace crypto { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 class SecureHashSHA256 : public SecureHash { | 19 class SecureHashSHA256 : public SecureHash { |
| 20 public: | 20 public: |
| 21 SecureHashSHA256() { | 21 SecureHashSHA256() { |
| 22 SHA256_Init(&ctx_); | 22 SHA256_Init(&ctx_); |
| 23 } | 23 } |
| 24 | 24 |
| 25 SecureHashSHA256(const SecureHashSHA256& other) { | 25 SecureHashSHA256(const SecureHashSHA256& other) : SecureHash() { |
|
Ryan Sleevi
2016/05/21 10:33:33
Why. The existing code is doing the right thing.
Luis Héctor Chávez
2016/05/24 15:27:53
Nevermind, I realized the branch I was building th
| |
| 26 memcpy(&ctx_, &other.ctx_, sizeof(ctx_)); | 26 memcpy(&ctx_, &other.ctx_, sizeof(ctx_)); |
| 27 } | 27 } |
| 28 | 28 |
| 29 ~SecureHashSHA256() override { | 29 ~SecureHashSHA256() override { |
| 30 OPENSSL_cleanse(&ctx_, sizeof(ctx_)); | 30 OPENSSL_cleanse(&ctx_, sizeof(ctx_)); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void Update(const void* input, size_t len) override { | 33 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 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 56 switch (algorithm) { | 56 switch (algorithm) { |
| 57 case SHA256: | 57 case SHA256: |
| 58 return new SecureHashSHA256(); | 58 return new SecureHashSHA256(); |
| 59 default: | 59 default: |
| 60 NOTIMPLEMENTED(); | 60 NOTIMPLEMENTED(); |
| 61 return NULL; | 61 return NULL; |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 } // namespace crypto | 65 } // namespace crypto |
| OLD | NEW |