[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 | |||||
thakis | d1a1847 | 2016-04-08 22:30:41 | [diff] [blame] | 9 | #include <memory> |
10 | |||||
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 11 | #include "base/stl_util.h" |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 12 | #include "crypto/secure_hash.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 13 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 14 | namespace crypto { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 15 | |
David Benjamin | cda45eb | 2017-11-06 18:16:52 | [diff] [blame^] | 16 | void SHA256HashString(base::StringPiece str, void* output, size_t len) { |
thakis | d1a1847 | 2016-04-08 22:30:41 | [diff] [blame] | 17 | std::unique_ptr<SecureHash> ctx(SecureHash::Create(SecureHash::SHA256)); |
[email protected] | 087b8c8 | 2011-04-11 10:28:46 | [diff] [blame] | 18 | ctx->Update(str.data(), str.length()); |
19 | ctx->Finish(output, len); | ||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 20 | } |
21 | |||||
David Benjamin | cda45eb | 2017-11-06 18:16:52 | [diff] [blame^] | 22 | std::string SHA256HashString(base::StringPiece str) { |
[email protected] | ea73fc7 | 2011-09-22 21:24:50 | [diff] [blame] | 23 | std::string output(kSHA256Length, 0); |
skyostil | 8ef165b | 2016-08-12 13:05:00 | [diff] [blame] | 24 | SHA256HashString(str, base::string_as_array(&output), output.size()); |
[email protected] | e1d6a59 | 2010-09-03 21:02:15 | [diff] [blame] | 25 | return output; |
26 | } | ||||
27 | |||||
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 28 | } // namespace crypto |