| // Copyright 2017 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "src/lib/crypto_util/hash.h" |
| |
| #include <string> |
| |
| #include <openssl/sha.h> |
| |
| namespace cobalt::crypto::hash { |
| |
| bool Hash(const std::string &data, std::string *out) { |
| out->resize(SHA256_DIGEST_LENGTH); |
| return Hash(data, reinterpret_cast<byte *>(&out->front())); |
| } |
| |
| bool Hash(const std::string &data, byte out[SHA256_DIGEST_LENGTH]) { |
| SHA256_CTX sha256; |
| if (SHA256_Init(&sha256) != 1) { |
| return false; |
| } |
| if (SHA256_Update(&sha256, data.c_str(), data.size()) != 1) { |
| return false; |
| } |
| return SHA256_Final(out, &sha256) == 1; |
| } |
| |
| } // namespace cobalt::crypto::hash |