Kea: cryptolink.h Source File

| Kea 2.2.0

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
19namespace isc {
20namespace cryptolink {
21
23 enum HashAlgorithm {
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
49 typedef boost::shared_ptr<RNG> RNGPtr;
50
53 class CryptoLinkError : public Exception {
54public:
55 CryptoLinkError(const char* file, size_t line, const char* what) :
56 isc::Exception(file, line, what) {}
57};
58
61 class InitializationError : public CryptoLinkError {
62public:
63 InitializationError(const char* file, size_t line, const char* what) :
64 CryptoLinkError(file, line, what) {}
65};
66
69 class UnsupportedAlgorithm : public CryptoLinkError {
70public:
71 UnsupportedAlgorithm(const char* file, size_t line, const char* what) :
72 CryptoLinkError(file, line, what) {}
73};
74
77 class BadKey : public CryptoLinkError {
78public:
79 BadKey(const char* file, size_t line, const char* what) :
80 CryptoLinkError(file, line, what) {}
81};
82
87 class LibraryError : public CryptoLinkError {
88public:
89 LibraryError(const char* file, size_t line, const char* what) :
90 CryptoLinkError(file, line, what) {}
91};
92
94class CryptoLinkImpl;
95
97 typedef 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
137 class 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
buffer.h
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::cryptolink::BadKey
This exception is thrown when the underlying library could not handle the key data.
Definition: cryptolink.h:77
isc::cryptolink::BadKey::BadKey
BadKey(const char *file, size_t line, const char *what)
Definition: cryptolink.h:79
isc::cryptolink::CryptoLinkError
General exception class that is the base for all crypto-related exceptions.
Definition: cryptolink.h:53
isc::cryptolink::CryptoLinkError::CryptoLinkError
CryptoLinkError(const char *file, size_t line, const char *what)
Definition: cryptolink.h:55
isc::cryptolink::CryptoLink
Singleton entry point and factory class.
Definition: cryptolink.h:137
isc::cryptolink::CryptoLink::createHash
Hash * createHash(const HashAlgorithm hash_algorithm)
Factory function for Hash objects.
Definition: cryptolink.cc:23
isc::cryptolink::CryptoLink::getCryptoLink
static CryptoLink & getCryptoLink()
Returns a reference to the singleton instance.
Definition: cryptolink.cc:17
isc::cryptolink::CryptoLink::createHMAC
HMAC * createHMAC(const void *secret, size_t secret_len, const HashAlgorithm hash_algorithm)
Factory function for HMAC objects.
Definition: cryptolink.cc:28
isc::cryptolink::CryptoLink::getVersion
static std::string getVersion()
Get version string.
Definition: botan_link.cc:78
isc::cryptolink::CryptoLink::getRNG
virtual RNGPtr & getRNG()
Get the global RNG.
Definition: cryptolink.cc:34
isc::cryptolink::HMAC
HMAC support.
Definition: crypto_hmac.h:27
isc::cryptolink::Hash
Hash support.
Definition: crypto_hash.h:27
isc::cryptolink::InitializationError
This exception is thrown if there was a problem initializing the crypto library.
Definition: cryptolink.h:61
isc::cryptolink::InitializationError::InitializationError
InitializationError(const char *file, size_t line, const char *what)
Definition: cryptolink.h:63
isc::cryptolink::LibraryError
This exception is raised when a general error that was not specifically caught is thrown by the under...
Definition: cryptolink.h:87
isc::cryptolink::LibraryError::LibraryError
LibraryError(const char *file, size_t line, const char *what)
Definition: cryptolink.h:89
isc::cryptolink::RNGImpl
Botan implementation of RNG.
Definition: botan_link.cc:30
isc::cryptolink::UnsupportedAlgorithm
This exception is thrown when a cryptographic action is requested for an algorithm that is not suppor...
Definition: cryptolink.h:69
isc::cryptolink::UnsupportedAlgorithm::UnsupportedAlgorithm
UnsupportedAlgorithm(const char *file, size_t line, const char *what)
Definition: cryptolink.h:71
exceptions.h
isc::cryptolink::RNGPtr
boost::shared_ptr< RNG > RNGPtr
Type representing the pointer to the RNG.
Definition: cryptolink.h:46
isc::cryptolink::CryptoLinkImplPtr
boost::shared_ptr< CryptoLinkImpl > CryptoLinkImplPtr
Type representing the pointer to the CryptoLinkImpl.
Definition: cryptolink.h:94
isc::cryptolink::HashAlgorithm
HashAlgorithm
Hash algorithm identifiers.
Definition: cryptolink.h:23
isc::cryptolink::MD5
@ MD5
MD5.
Definition: cryptolink.h:30
isc::cryptolink::SHA1
@ SHA1
SHA-1.
Definition: cryptolink.h:31
isc::cryptolink::SHA512
@ SHA512
SHA-512.
Definition: cryptolink.h:35
isc::cryptolink::SHA224
@ SHA224
SHA-224.
Definition: cryptolink.h:33
isc::cryptolink::SHA256
@ SHA256
SHA-256.
Definition: cryptolink.h:32
isc::cryptolink::SHA384
@ SHA384
SHA-384.
Definition: cryptolink.h:34
isc::cryptolink::UNKNOWN_HASH
@ UNKNOWN_HASH
This value can be used in conversion functions, to be returned when the input is unknown (but a value...
Definition: cryptolink.h:24
isc
Defines the logger used by the top-level component of kea-lfc.
Definition: agent_parser.cc:143