Vitaly Buka | 4615e0d | 2015-10-14 15:35:12 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Weave Authors. All rights reserved. |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Stefan Sauer | 2d16dfa | 2015-09-25 17:08:35 +0200 | [diff] [blame] | 5 | #include "src/privet/openssl_utils.h" |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 6 | |
| 7 | #include <algorithm> |
| 8 | |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 9 | #include <base/logging.h> |
| 10 | |
Vitaly Buka | 47fe6f8 | 2015-12-01 14:37:24 -0800 | [diff] [blame] | 11 | extern "C" { |
| 12 | #include "third_party/libuweave/src/crypto_hmac.h" |
| 13 | } |
| 14 | |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 15 | namespace weave { |
| 16 | namespace privet { |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 17 | |
Vitaly Buka | a04405e | 2015-08-13 18:28:14 -0700 | [diff] [blame] | 18 | std::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 Buka | a821f2e | 2016-01-27 11:44:02 -0800 | [diff] [blame] | 21 | 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 Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 24 | return mac; |
| 25 | } |
| 26 | |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 27 | } // namespace privet |
| 28 | } // namespace weave |