Kea: crypto_hmac.cc Source File

| Kea 3.2.0-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
16namespace isc {
17namespace cryptolink {
18
19void
20signHMAC(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
36bool
37verifyHMAC(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
53void
54deleteHMAC(HMAC* hmac) {
55 delete hmac;
56}
57
58} // namespace cryptolink
59} // namespace isc
isc::cryptolink::CryptoLink::getCryptoLink
static CryptoLink & getCryptoLink()
Returns a reference to the singleton instance.
Definition cryptolink.cc:17
isc::cryptolink::HMAC
HMAC support.
Definition crypto_hmac.h:27
isc::util::OutputBuffer
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:346
crypto_hmac.h
cryptolink.h
isc::cryptolink
Definition botan_common.h:8
isc::cryptolink::verifyHMAC
bool verifyHMAC(const void *data, const size_t data_len, const void *secret, size_t secret_len, const HashAlgorithm hash_algorithm, const void *sig, const size_t sig_len)
Verify an HMAC signature for the given data.
Definition crypto_hmac.cc:37
isc::cryptolink::signHMAC
void signHMAC(const void *data, const size_t data_len, const void *secret, size_t secret_len, const HashAlgorithm hash_algorithm, isc::util::OutputBuffer &result, size_t len)
Create an HMAC signature for the given data.
Definition crypto_hmac.cc:20
isc::cryptolink::deleteHMAC
void deleteHMAC(HMAC *hmac)
Delete an HMAC object.
Definition crypto_hmac.cc:54
isc::cryptolink::HashAlgorithm
HashAlgorithm
Hash algorithm identifiers.
Definition cryptolink.h:23
isc::data
Definition base_stamped_element.cc:12
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18