blob: 319e0310b551df11161edd9a8fb10ef8a79cd99f [file] [log] [blame]
// 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 "peridot/bin/ledger/encryption/primitives/hmac.h"
#include <openssl/digest.h>
#include <openssl/hmac.h>
#include <openssl/sha.h>
namespace encryption {
std::string SHA256HMAC(fxl::StringView key, fxl::StringView data) {
FXL_CHECK(key.size() >= SHA256_DIGEST_LENGTH);
std::string result;
unsigned int result_size;
const uint8_t* out =
HMAC(EVP_sha256(),, key.size(),
reinterpret_cast<const uint8_t*>(, data.size(),
reinterpret_cast<uint8_t*>(&result[0]), &result_size);
FXL_DCHECK(result_size == SHA256_DIGEST_LENGTH);
return result;
} // namespace encryption