1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <config.h>

#include <cryptolink/cryptolink.h>
#include <cryptolink/crypto_hash.h>
#include <cryptolink/crypto_hmac.h>
#include <cryptolink/crypto_rng.h>

#include <botan/exceptn.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <botan/version.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <botan/auto_rng.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace isc {
namespace cryptolink {

// For Botan, we use the CryptoLink class object in RAII style
class CryptoLinkImpl {
    // empty class
};

CryptoLink::~CryptoLink() {
}

/// \brief Botan implementation of RNG.
class RNGImpl : public RNG {
public:
    RNGImpl() {
        rng.reset(new Botan::AutoSeeded_RNG());
    }

    ~RNGImpl() {<--- Destructor in derived class
    }

private:
    std::vector<uint8_t> random(size_t len) {<--- Function in derived class
        std::vector<uint8_t> data;
        if (len > 0) {
            data.resize(len);
            try {
                rng->randomize(&data[0], len);
            } catch (const Botan::Exception& ex) {
                isc_throw(isc::cryptolink::LibraryError,
                          "Botan error: " << ex.what());
            }
        }
        return (data);
    }

    boost::shared_ptr<Botan::RandomNumberGenerator> rng;
};

void
CryptoLink::initialize(CryptoLink& c) {
    if (!c.impl_) {
        try {
            c.impl_.reset(new CryptoLinkImpl());
        } catch (const Botan::Exception& ex) {
            isc_throw(InitializationError, "Botan error: " << ex.what());
        }
    }
    if (!c.rng_) {
        try {
            c.rng_.reset(new RNGImpl());
        } catch (const Botan::Exception& ex) {
            isc_throw(InitializationError, "Botan error: " << ex.what());
        }
    }
}

std::string
CryptoLink::getVersion() {
    return (Botan::version_string());
}

} // namespace cryptolink
} // namespace isc