Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 1 | // 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 | |
| 14 | namespace privetd { |
| 15 | |
| 16 | chromeos::Blob HmacSha256(const chromeos::SecureBlob& key, |
| 17 | const chromeos::Blob& data) { |
| 18 | chromeos::Blob mac(kSha256OutputSize); |
| 19 | uint32_t len = 0; |
Vitaly Buka | 075b3d4 | 2015-06-09 08:34:25 -0700 | [diff] [blame] | 20 | CHECK(HMAC(EVP_sha256(), key.data(), key.size(), data.data(), data.size(), |
| 21 | mac.data(), &len)); |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 22 | CHECK_EQ(len, kSha256OutputSize); |
| 23 | return mac; |
| 24 | } |
| 25 | |
| 26 | } // namespace privetd |