[email protected] | da7582b7 | 2012-01-10 19:10:33 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | |
avi | dd373b8b | 2015-12-21 21:34:43 | [diff] [blame^] | 7 | #include <stddef.h> |
8 | |||||
[email protected] | 7226b33c | 2011-08-18 08:44:22 | [diff] [blame] | 9 | #include "base/memory/scoped_ptr.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 10 | #include "base/stl_util.h" |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 11 | #include "crypto/secure_hash.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 12 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 13 | namespace crypto { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 14 | |
[email protected] | da7582b7 | 2012-01-10 19:10:33 | [diff] [blame] | 15 | void SHA256HashString(const base::StringPiece& str, void* output, size_t len) { |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 16 | scoped_ptr<SecureHash> ctx(SecureHash::Create(SecureHash::SHA256)); |
[email protected] | 087b8c8 | 2011-04-11 10:28:46 | [diff] [blame] | 17 | ctx->Update(str.data(), str.length()); |
18 | ctx->Finish(output, len); | ||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 19 | } |
20 | |||||
[email protected] | da7582b7 | 2012-01-10 19:10:33 | [diff] [blame] | 21 | std::string SHA256HashString(const base::StringPiece& str) { |
[email protected] | ea73fc7 | 2011-09-22 21:24:50 | [diff] [blame] | 22 | std::string output(kSHA256Length, 0); |
[email protected] | 6c683f0 | 2010-09-24 17:45:21 | [diff] [blame] | 23 | SHA256HashString(str, string_as_array(&output), output.size()); |
[email protected] | e1d6a59 | 2010-09-03 21:02:15 | [diff] [blame] | 24 | return output; |
25 | } | ||||
26 | |||||
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 27 | } // namespace crypto |