blob: aa1b6d0d0698e61c53d4c8402309956ec26a85d0 [file] [log] [blame]
Alex Vakulenkof6024732016-01-22 16:52:43 -08001// 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 Vakulenko24854742016-01-22 16:55:13 -08007#include <stddef.h>
8
Luis Hector Chavez94ffa552016-05-25 15:29:35 -07009#include <memory>
10
Alex Vakulenkof6024732016-01-22 16:52:43 -080011#include "base/stl_util.h"
12#include "crypto/secure_hash.h"
13
14namespace crypto {
15
Jakub Pawlowski86aa2252017-04-05 09:22:29 -070016void SHA256HashString(base::StringPiece str, void* output, size_t len) {
Luis Hector Chavez94ffa552016-05-25 15:29:35 -070017 std::unique_ptr<SecureHash> ctx(SecureHash::Create(SecureHash::SHA256));
Alex Vakulenkof6024732016-01-22 16:52:43 -080018 ctx->Update(str.data(), str.length());
19 ctx->Finish(output, len);
20}
21
Jakub Pawlowski86aa2252017-04-05 09:22:29 -070022std::string SHA256HashString(base::StringPiece str) {
Alex Vakulenkof6024732016-01-22 16:52:43 -080023 std::string output(kSHA256Length, 0);
Jakub Pawlowski86aa2252017-04-05 09:22:29 -070024 SHA256HashString(str, base::data(output), output.size());
Alex Vakulenkof6024732016-01-22 16:52:43 -080025 return output;
26}
27
28} // namespace crypto