| 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/sha2.h" | 5 #include "crypto/sha2.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "crypto/secure_hash.h" | 9 #include "crypto/secure_hash.h" |
| 10 | 10 |
| 11 namespace crypto { | 11 namespace crypto { |
| 12 | 12 |
| 13 void SHA256HashString(const base::StringPiece& str, void* output, size_t len) { | 13 void SHA256HashString(const base::StringPiece& str, void* output, size_t len) { |
| 14 scoped_ptr<SecureHash> ctx(SecureHash::Create(SecureHash::SHA256)); | 14 SHA256HashBytes(reinterpret_cast<const uint8_t*>(str.data()), str.length(), |
| 15 ctx->Update(str.data(), str.length()); | 15 output, len); |
| 16 ctx->Finish(output, len); | |
| 17 } | 16 } |
| 18 | 17 |
| 19 std::string SHA256HashString(const base::StringPiece& str) { | 18 std::string SHA256HashString(const base::StringPiece& str) { |
| 20 std::string output(kSHA256Length, 0); | 19 std::string output(kSHA256Length, 0); |
| 21 SHA256HashString(str, string_as_array(&output), output.size()); | 20 SHA256HashString(str, string_as_array(&output), output.size()); |
| 22 return output; | 21 return output; |
| 23 } | 22 } |
| 24 | 23 |
| 24 void SHA256HashBytes(const uint8_t* data, |
| 25 size_t len, |
| 26 void* hash, |
| 27 size_t out_len) { |
| 28 scoped_ptr<SecureHash> ctx(SecureHash::Create(SecureHash::SHA256)); |
| 29 ctx->Update(data, len); |
| 30 ctx->Finish(hash, out_len); |
| 31 } |
| 32 |
| 25 } // namespace crypto | 33 } // namespace crypto |
| OLD | NEW |