Kea 2.7.5
cryptolink.h
Go to the documentation of this file.
1// Copyright (C) 2011-2024 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, // This value can be used in conversion
25 // functions, to be returned when the
26 // input is unknown (but a value MUST be
27 // returned), for instance when the input
28 // is a Name or a string, and the return
29 // value is a HashAlgorithm.
30 MD5 = 1, // MD5
31 SHA1 = 2, // SHA-1
32 SHA256 = 3, // SHA-256
33 SHA224 = 4, // SHA-224
34 SHA384 = 5, // SHA-384
35 SHA512 = 6 // SHA-512
36};
37
39class Hash;
40
42class HMAC;
43
45class RNG;
46
48typedef boost::shared_ptr<RNG> RNGPtr;
49
52class CryptoLinkError : public Exception {
53public:
54 CryptoLinkError(const char* file, size_t line, const char* what) :
55 isc::Exception(file, line, what) {}
56};
57
61public:
62 InitializationError(const char* file, size_t line, const char* what) :
63 CryptoLinkError(file, line, what) {}
64};
65
69public:
70 UnsupportedAlgorithm(const char* file, size_t line, const char* what) :
71 CryptoLinkError(file, line, what) {}
72};
73
76class BadKey : public CryptoLinkError {
77public:
78 BadKey(const char* file, size_t line, const char* what) :
79 CryptoLinkError(file, line, what) {}
80};
81
87public:
88 LibraryError(const char* file, size_t line, const char* what) :
89 CryptoLinkError(file, line, what) {}
90};
91
93class CryptoLinkImpl;
94
96typedef boost::shared_ptr<CryptoLinkImpl> CryptoLinkImplPtr;
97
99class RNGImpl;
100
136class CryptoLink : private boost::noncopyable {
137public:
149 static CryptoLink& getCryptoLink();
150
154 static std::string getVersion();
155
178 Hash* createHash(const HashAlgorithm hash_algorithm);
179
210 HMAC* createHMAC(const void* secret, size_t secret_len,
211 const HashAlgorithm hash_algorithm);
212
221 virtual RNGPtr const& getRNG() const;
222
223private:
236 void initialize(CryptoLink& c);
237
240 CryptoLink() {
241 initialize(*this);
242 }
243 ~CryptoLink();
244
246 CryptoLinkImplPtr impl_;
247
249 RNGPtr rng_;
250};
251
252} // namespace cryptolink
253} // namespace isc
254
255#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.