Kea  1.9.9-git
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>
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 
39 // Forward declaration for createHash()
40 class Hash;
41 
42 // Forward declaration for createHMAC()
43 class HMAC;
44 
45 // Forward declaration for getRNG()
46 class RNG;
47 typedef boost::shared_ptr<RNG> RNGPtr;
48 
51 class CryptoLinkError : public Exception {
52 public:
53  CryptoLinkError(const char* file, size_t line, const char* what) :
54  isc::Exception(file, line, what) {}
55 };
56 
60 public:
61  InitializationError(const char* file, size_t line, const char* what) :
62  CryptoLinkError(file, line, what) {}
63 };
64 
68 public:
69  UnsupportedAlgorithm(const char* file, size_t line, const char* what) :
70  CryptoLinkError(file, line, what) {}
71 };
72 
75 class BadKey : public CryptoLinkError {
76 public:
77  BadKey(const char* file, size_t line, const char* what) :
78  CryptoLinkError(file, line, what) {}
79 };
80 
85 class LibraryError : public CryptoLinkError {
86 public:
87  LibraryError(const char* file, size_t line, const char* what) :
88  CryptoLinkError(file, line, what) {}
89 };
90 
92 class CryptoLinkImpl;
93 class RNGImpl;
94 
131 // Internal note: we can use this class later to initialize and manage
132 // dynamic (PKCS#11) libs
133 class CryptoLink : private boost::noncopyable {
134 public:
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 
225 private:
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
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-dhcp-ddns.