Alex Vakulenko | f602473 | 2016-01-22 16:52:43 -0800 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "crypto/sha2.h" |
| 6 | |
Alex Vakulenko | 2485474 | 2016-01-22 16:55:13 -0800 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
Luis Hector Chavez | 94ffa55 | 2016-05-25 15:29:35 -0700 | [diff] [blame] | 9 | #include <memory> |
| 10 | |
Alex Vakulenko | f602473 | 2016-01-22 16:52:43 -0800 | [diff] [blame] | 11 | #include "base/stl_util.h" |
| 12 | #include "crypto/secure_hash.h" |
| 13 | |
| 14 | namespace crypto { |
| 15 | |
Jakub Pawlowski | 86aa225 | 2017-04-05 09:22:29 -0700 | [diff] [blame] | 16 | void SHA256HashString(base::StringPiece str, void* output, size_t len) { |
Luis Hector Chavez | 94ffa55 | 2016-05-25 15:29:35 -0700 | [diff] [blame] | 17 | std::unique_ptr<SecureHash> ctx(SecureHash::Create(SecureHash::SHA256)); |
Alex Vakulenko | f602473 | 2016-01-22 16:52:43 -0800 | [diff] [blame] | 18 | ctx->Update(str.data(), str.length()); |
| 19 | ctx->Finish(output, len); |
| 20 | } |
| 21 | |
Jakub Pawlowski | 86aa225 | 2017-04-05 09:22:29 -0700 | [diff] [blame] | 22 | std::string SHA256HashString(base::StringPiece str) { |
Alex Vakulenko | f602473 | 2016-01-22 16:52:43 -0800 | [diff] [blame] | 23 | std::string output(kSHA256Length, 0); |
Jakub Pawlowski | 86aa225 | 2017-04-05 09:22:29 -0700 | [diff] [blame] | 24 | SHA256HashString(str, base::data(output), output.size()); |
Alex Vakulenko | f602473 | 2016-01-22 16:52:43 -0800 | [diff] [blame] | 25 | return output; |
| 26 | } |
| 27 | |
| 28 | } // namespace crypto |