| // 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. |
| |
| #ifndef COBALT_SRC_LIB_CRYPTO_UTIL_HASH_H_ |
| #define COBALT_SRC_LIB_CRYPTO_UTIL_HASH_H_ |
| |
| #include <cstddef> |
| #include <string> |
| |
| #include <openssl/sha.h> |
| |
| #include "src/lib/crypto_util/types.h" |
| |
| namespace cobalt::crypto::hash { |
| |
| static const size_t DIGEST_SIZE = SHA256_DIGEST_LENGTH; // SHA-256 outputs 32 bytes. |
| |
| // Computes the SHA256 digest of |data| and writes the result to |out| which |
| // will be automatically resized to |DIGEST_SIZE|. |
| // |
| // Returns true for success or false for failure. |
| bool Hash(const std::string &data, std::string *out); |
| |
| // Computes the SHA256 digest of |data| and writes the result to |out| which |
| // must have length |DIGEST_SIZE|. |
| // |
| // Returns true for success or false for failure. |
| bool Hash(const std::string &data, byte out[DIGEST_SIZE]); |
| |
| } // namespace cobalt::crypto::hash |
| |
| #endif // COBALT_SRC_LIB_CRYPTO_UTIL_HASH_H_ |