Kea  2.1.7-git
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>
12 #include <exceptions/exceptions.h>
13 
14 #include <boost/noncopyable.hpp>
15 #include <boost/shared_ptr.hpp>
16 
17 #include <memory>
18 
19 namespace isc {
20 namespace cryptolink {
21 
25  MD5 = 1,
31  SHA1 = 2,
32  SHA256 = 3,
33  SHA224 = 4,
34  SHA384 = 5,
35  SHA512 = 6
36 
37 };
38 
40 class Hash;
41 
43 class HMAC;
44 
46 class RNG;
47 
49 typedef boost::shared_ptr<RNG> RNGPtr;
50 
53 class CryptoLinkError : public Exception {
54 public:
55  CryptoLinkError(const char* file, size_t line, const char* what) :
56  isc::Exception(file, line, what) {}
57 };
58 
62 public:
63  InitializationError(const char* file, size_t line, const char* what) :
64  CryptoLinkError(file, line, what) {}
65 };
66 
70 public:
71  UnsupportedAlgorithm(const char* file, size_t line, const char* what) :
72  CryptoLinkError(file, line, what) {}
73 };
74 
77 class BadKey : public CryptoLinkError {
78 public:
79  BadKey(const char* file, size_t line, const char* what) :
80  CryptoLinkError(file, line, what) {}
81 };
82 
87 class LibraryError : public CryptoLinkError {
88 public:
89  LibraryError(const char* file, size_t line, const char* what) :
90  CryptoLinkError(file, line, what) {}
91 };
92 
95 
97 typedef boost::shared_ptr<CryptoLinkImpl> CryptoLinkImplPtr;
98 
100 class RNGImpl;
101 
135 // Internal note: we can use this class later to initialize and manage
136 // dynamic (PKCS#11) libs
137 class CryptoLink : private boost::noncopyable {
138 public:
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 
216 private:
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
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.