blob: 17ebf70d7323045ab6afa6d27dcc05dcc6b71cc3 [file] [log] [blame]
Vitaly Buka4615e0d2015-10-14 15:35:12 -07001// Copyright 2015 The Weave Authors. All rights reserved.
Vitaly Buka7ce499f2015-06-09 08:04:11 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Stefan Sauer2d16dfa2015-09-25 17:08:35 +02005#include "src/privet/openssl_utils.h"
Vitaly Buka7ce499f2015-06-09 08:04:11 -07006
7#include <algorithm>
8
Vitaly Buka7ce499f2015-06-09 08:04:11 -07009#include <base/logging.h>
10
Vitaly Buka47fe6f82015-12-01 14:37:24 -080011extern "C" {
12#include "third_party/libuweave/src/crypto_hmac.h"
13}
14
Vitaly Bukab6f015a2015-07-09 14:59:23 -070015namespace weave {
16namespace privet {
Vitaly Buka7ce499f2015-06-09 08:04:11 -070017
Vitaly Bukaa04405e2015-08-13 18:28:14 -070018std::vector<uint8_t> HmacSha256(const std::vector<uint8_t>& key,
19 const std::vector<uint8_t>& data) {
20 std::vector<uint8_t> mac(kSha256OutputSize);
Vitaly Bukaa821f2e2016-01-27 11:44:02 -080021 const UwCryptoHmacMsg messages[] = {{data.data(), data.size()}};
22 CHECK(uw_crypto_hmac_(key.data(), key.size(), messages, arraysize(messages),
23 mac.data(), mac.size()));
Vitaly Buka7ce499f2015-06-09 08:04:11 -070024 return mac;
25}
26
Vitaly Bukab6f015a2015-07-09 14:59:23 -070027} // namespace privet
28} // namespace weave