blob: c4cdb872a1e251fc4a0ff848c3b3a8e617545ae8 [file] [log] [blame]
[email protected]da7582b72012-01-10 19:10:331// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:384
[email protected]4b559b4d2011-04-14 17:37:145#include "crypto/sha2.h"
initial.commitd7cae122008-07-26 21:49:386
avidd373b8b2015-12-21 21:34:437#include <stddef.h>
8
thakisd1a18472016-04-08 22:30:419#include <memory>
10
[email protected]7286e3fc2011-07-19 22:13:2411#include "base/stl_util.h"
[email protected]4b559b4d2011-04-14 17:37:1412#include "crypto/secure_hash.h"
initial.commitd7cae122008-07-26 21:49:3813
[email protected]4b559b4d2011-04-14 17:37:1414namespace crypto {
initial.commitd7cae122008-07-26 21:49:3815
David Benjamincda45eb2017-11-06 18:16:5216void SHA256HashString(base::StringPiece str, void* output, size_t len) {
thakisd1a18472016-04-08 22:30:4117 std::unique_ptr<SecureHash> ctx(SecureHash::Create(SecureHash::SHA256));
[email protected]087b8c82011-04-11 10:28:4618 ctx->Update(str.data(), str.length());
19 ctx->Finish(output, len);
initial.commitd7cae122008-07-26 21:49:3820}
21
David Benjamincda45eb2017-11-06 18:16:5222std::string SHA256HashString(base::StringPiece str) {
[email protected]ea73fc72011-09-22 21:24:5023 std::string output(kSHA256Length, 0);
skyostil8ef165b2016-08-12 13:05:0024 SHA256HashString(str, base::string_as_array(&output), output.size());
[email protected]e1d6a592010-09-03 21:02:1525 return output;
26}
27
[email protected]4b559b4d2011-04-14 17:37:1428} // namespace crypto