blob: da51cc551f367788c05139d48cfd4dd179c7bb3b [file] [log] [blame]
[email protected]087b8c82011-04-11 10:28:461// Copyright (c) 2011 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
[email protected]7226b33c2011-08-18 08:44:227#include "base/memory/scoped_ptr.h"
[email protected]7286e3fc2011-07-19 22:13:248#include "base/stl_util.h"
[email protected]4b559b4d2011-04-14 17:37:149#include "crypto/secure_hash.h"
initial.commitd7cae122008-07-26 21:49:3810
[email protected]4b559b4d2011-04-14 17:37:1411namespace crypto {
initial.commitd7cae122008-07-26 21:49:3812
13void SHA256HashString(const std::string& str, void* output, size_t len) {
[email protected]4b559b4d2011-04-14 17:37:1414 scoped_ptr<SecureHash> ctx(SecureHash::Create(SecureHash::SHA256));
[email protected]087b8c82011-04-11 10:28:4615 ctx->Update(str.data(), str.length());
16 ctx->Finish(output, len);
initial.commitd7cae122008-07-26 21:49:3817}
18
[email protected]e1d6a592010-09-03 21:02:1519std::string SHA256HashString(const std::string& str) {
[email protected]ea73fc72011-09-22 21:24:5020 std::string output(kSHA256Length, 0);
[email protected]6c683f02010-09-24 17:45:2121 SHA256HashString(str, string_as_array(&output), output.size());
[email protected]e1d6a592010-09-03 21:02:1522 return output;
23}
24
[email protected]4b559b4d2011-04-14 17:37:1425} // namespace crypto