Kea 2.0.2
cryptolink.h
Go to the documentation of this file.
1// Copyright (C) 2011-2018 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#ifndef ISC_CRYPTO_H
8#define ISC_CRYPTO_H
9
10#include <string>
11#include <util/buffer.h>
13
14#include <boost/noncopyable.hpp>
15#include <boost/shared_ptr.hpp>
16
17#include <memory>
18
19namespace isc {
20namespace cryptolink {
21
24 UNKNOWN_HASH = 0,
30 MD5 = 1,
31 SHA1 = 2,
32 SHA256 = 3,
33 SHA224 = 4,
34 SHA384 = 5,
35 SHA512 = 6
36
37};
38
39// Forward declaration for createHash()
40class Hash;
41
42// Forward declaration for createHMAC()
43class HMAC;
44
45// Forward declaration for getRNG()
46class RNG;
47typedef boost::shared_ptr<RNG> RNGPtr;
48
51class CryptoLinkError : public Exception {
52public:
53 CryptoLinkError(const char* file, size_t line, const char* what) :
54 isc::Exception(file, line, what) {}
55};
56
60public:
61 InitializationError(const char* file, size_t line, const char* what) :
62 CryptoLinkError(file, line, what) {}
63};
64
68public:
69 UnsupportedAlgorithm(const char* file, size_t line, const char* what) :
70 CryptoLinkError(file, line, what) {}
71};
72
75class BadKey : public CryptoLinkError {
76public:
77 BadKey(const char* file, size_t line, const char* what) :
78 CryptoLinkError(file, line, what) {}
79};
80
86public:
87 LibraryError(const char* file, size_t line, const char* what) :
88 CryptoLinkError(file, line, what) {}
89};
90
92class CryptoLinkImpl;
93class RNGImpl;
94
131// Internal note: we can use this class later to initialize and manage
132// dynamic (PKCS#11) libs
133class CryptoLink : private boost::noncopyable {
134public:
146 static CryptoLink& getCryptoLink();
147
159 static void initialize();
160
162 static std::string getVersion();
163
184 Hash* createHash(const HashAlgorithm hash_algorithm);
185
214 HMAC* createHMAC(const void* secret, size_t secret_len,
215 const HashAlgorithm hash_algorithm);
216
223 virtual RNGPtr& getRNG();
224
225private:
226 // To enable us to use an optional explicit initialization call,
227 // the 'real' instance getter is private
228 static CryptoLink& getCryptoLinkInternal();
229
230 // To prevent people constructing their own, we make the constructor
231 // private too.
232 CryptoLink() : impl_(NULL) {}
233 ~CryptoLink();
234
235 CryptoLinkImpl* impl_;
236
237 RNGPtr rng_;
238};
239
240} // namespace cryptolink
241} // namespace isc
242
243#endif // ISC_CRYPTO_H
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Defines the logger used by the top-level component of kea-lfc.