blob: bcaf4229c5983111fd6d778dce21c238fe16932a [file] [log] [blame]
Vitaly Buka7ce499f2015-06-09 08:04:11 -07001// Copyright 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "buffet/privet/openssl_utils.h"
6
7#include <algorithm>
8
9#include <openssl/evp.h>
10#include <openssl/hmac.h>
11
12#include <base/logging.h>
13
14namespace privetd {
15
16chromeos::Blob HmacSha256(const chromeos::SecureBlob& key,
17 const chromeos::Blob& data) {
18 chromeos::Blob mac(kSha256OutputSize);
19 uint32_t len = 0;
Vitaly Buka075b3d42015-06-09 08:34:25 -070020 CHECK(HMAC(EVP_sha256(), key.data(), key.size(), data.data(), data.size(),
21 mac.data(), &len));
Vitaly Buka7ce499f2015-06-09 08:04:11 -070022 CHECK_EQ(len, kSha256OutputSize);
23 return mac;
24}
25
26} // namespace privetd