[email protected] | 087b8c8 | 2011-04-11 10:28:46 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 4 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 5 | #include "crypto/sha2.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 6 | |
[email protected] | 7226b33c | 2011-08-18 08:44:22 | [diff] [blame] | 7 | #include "base/memory/scoped_ptr.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 8 | #include "base/stl_util.h" |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 9 | #include "crypto/secure_hash.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 10 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 11 | namespace crypto { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 12 | |
13 | void SHA256HashString(const std::string& str, void* output, size_t len) { | ||||
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 14 | scoped_ptr<SecureHash> ctx(SecureHash::Create(SecureHash::SHA256)); |
[email protected] | 087b8c8 | 2011-04-11 10:28:46 | [diff] [blame] | 15 | ctx->Update(str.data(), str.length()); |
16 | ctx->Finish(output, len); | ||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 17 | } |
18 | |||||
[email protected] | e1d6a59 | 2010-09-03 21:02:15 | [diff] [blame] | 19 | std::string SHA256HashString(const std::string& str) { |
[email protected] | ea73fc7 | 2011-09-22 21:24:50 | [diff] [blame^] | 20 | std::string output(kSHA256Length, 0); |
[email protected] | 6c683f0 | 2010-09-24 17:45:21 | [diff] [blame] | 21 | SHA256HashString(str, string_as_array(&output), output.size()); |
[email protected] | e1d6a59 | 2010-09-03 21:02:15 | [diff] [blame] | 22 | return output; |
23 | } | ||||
24 | |||||
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 25 | } // namespace crypto |