Kea  2.3.2-git
crypto_hmac.cc
Go to the documentation of this file.
1 // Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 
9 #include <cryptolink.h>
10 #include <cryptolink/crypto_hmac.h>
11 
12 #include <boost/scoped_ptr.hpp>
13 
14 #include <cstring>
15 
16 namespace isc {
17 namespace cryptolink {
18 
19 void
20 signHMAC(const void* data, const size_t data_len, const void* secret,
21  size_t secret_len, const HashAlgorithm hash_algorithm,
22  isc::util::OutputBuffer& result, size_t len)
23 {
24  boost::scoped_ptr<HMAC> hmac(
25  CryptoLink::getCryptoLink().createHMAC(secret,
26  secret_len,
27  hash_algorithm));
28  hmac->update(data, data_len);
29  if (len == 0) {
30  len = hmac->getOutputLength();
31  }
32  hmac->sign(result, len);
33 }
34 
35 
36 bool
37 verifyHMAC(const void* data, const size_t data_len, const void* secret,
38  size_t secret_len, const HashAlgorithm hash_algorithm,
39  const void* sig, const size_t sig_len)
40 {
41  boost::scoped_ptr<HMAC> hmac(
42  CryptoLink::getCryptoLink().createHMAC(secret,
43  secret_len,
44  hash_algorithm));
45  hmac->update(data, data_len);
46  size_t len = sig_len;
47  if (len == 0) {
48  len = hmac->getOutputLength();
49  }
50  return (hmac->verify(sig, len));
51 }
52 
53 void
54 deleteHMAC(HMAC* hmac) {
55  delete hmac;
56 }
57 
58 } // namespace cryptolink
59 } // namespace isc
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
Defines the logger used by the top-level component of kea-lfc.