Kea 2.5.5
cryptolink.h
Go to the documentation of this file.
1// Copyright (C) 2011-2022 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
40class Hash;
41
43class HMAC;
44
46class RNG;
47
49typedef boost::shared_ptr<RNG> RNGPtr;
50
53class CryptoLinkError : public Exception {
54public:
55 CryptoLinkError(const char* file, size_t line, const char* what) :
56 isc::Exception(file, line, what) {}
57};
58
62public:
63 InitializationError(const char* file, size_t line, const char* what) :
64 CryptoLinkError(file, line, what) {}
65};
66
70public:
71 UnsupportedAlgorithm(const char* file, size_t line, const char* what) :
72 CryptoLinkError(file, line, what) {}
73};
74
77class BadKey : public CryptoLinkError {
78public:
79 BadKey(const char* file, size_t line, const char* what) :
80 CryptoLinkError(file, line, what) {}
81};
82
88public:
89 LibraryError(const char* file, size_t line, const char* what) :
90 CryptoLinkError(file, line, what) {}
91};
92
94class CryptoLinkImpl;
95
97typedef boost::shared_ptr<CryptoLinkImpl> CryptoLinkImplPtr;
98
100class RNGImpl;
101
135// Internal note: we can use this class later to initialize and manage
136// dynamic (PKCS#11) libs
137class CryptoLink : private boost::noncopyable {
138public:
150 static CryptoLink& getCryptoLink();
151
153 static std::string getVersion();
154
175 Hash* createHash(const HashAlgorithm hash_algorithm);
176
205 HMAC* createHMAC(const void* secret, size_t secret_len,
206 const HashAlgorithm hash_algorithm);
207
214 virtual RNGPtr& getRNG();
215
216private:
229 void initialize(CryptoLink& c);
230
231 // To prevent people constructing their own, we make the constructor
232 // private too.
233 CryptoLink() {
234 initialize(*this);
235 }
236 ~CryptoLink();
237
239 CryptoLinkImplPtr impl_;
240
242 RNGPtr rng_;
243};
244
245} // namespace cryptolink
246} // namespace isc
247
248#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.