blob: 2646d1bbd15e6583fb54827fadbed13eb5bc216d [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
[email protected]7226b33c2011-08-18 08:44:229#include "base/memory/scoped_ptr.h"
[email protected]7286e3fc2011-07-19 22:13:2410#include "base/stl_util.h"
[email protected]4b559b4d2011-04-14 17:37:1411#include "crypto/secure_hash.h"
initial.commitd7cae122008-07-26 21:49:3812
[email protected]4b559b4d2011-04-14 17:37:1413namespace crypto {
initial.commitd7cae122008-07-26 21:49:3814
[email protected]da7582b72012-01-10 19:10:3315void SHA256HashString(const base::StringPiece& str, void* output, size_t len) {
[email protected]4b559b4d2011-04-14 17:37:1416 scoped_ptr<SecureHash> ctx(SecureHash::Create(SecureHash::SHA256));
[email protected]087b8c82011-04-11 10:28:4617 ctx->Update(str.data(), str.length());
18 ctx->Finish(output, len);
initial.commitd7cae122008-07-26 21:49:3819}
20
[email protected]da7582b72012-01-10 19:10:3321std::string SHA256HashString(const base::StringPiece& str) {
[email protected]ea73fc72011-09-22 21:24:5022 std::string output(kSHA256Length, 0);
[email protected]6c683f02010-09-24 17:45:2123 SHA256HashString(str, string_as_array(&output), output.size());
[email protected]e1d6a592010-09-03 21:02:1524 return output;
25}
26
[email protected]4b559b4d2011-04-14 17:37:1427} // namespace crypto