1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "crypto/sha2.h"
11 #include "crypto/secure_hash.h"
12 #include "third_party/boringssl/src/include/openssl/sha.h"
16 std::array<uint8_t, kSHA256Length> SHA256Hash(base::span<const uint8_t> input) {
17 std::array<uint8_t, kSHA256Length> digest;
18 ::SHA256(input.data(), input.size(), digest.data());
22 void SHA256HashString(std::string_view str, void* output, size_t len) {
23 std::unique_ptr<SecureHash> ctx(SecureHash::Create(SecureHash::SHA256));
24 ctx->Update(str.data(), str.length());
25 ctx->Finish(output, len);
28 std::string SHA256HashString(std::string_view str) {
29 std::string output(kSHA256Length, 0);
30 SHA256HashString(str, std::data(output), output.size());