Kea 2.7.5
openssl_common.h
Go to the documentation of this file.
1// Copyright (C) 2014-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
7namespace isc {
8namespace cryptolink {
9namespace ossl {
10
16const EVP_MD*
18
22template<typename T>
23class SecBuf {
24public:
25 typedef typename std::vector<T>::iterator iterator;
26
27 typedef typename std::vector<T>::const_iterator const_iterator;
28
29 explicit SecBuf() : vec_() {}
30
31 explicit SecBuf(size_t n, const T& value = T()) : vec_(n, value) {}
32
33 SecBuf(iterator first, iterator last) : vec_(first, last) {}
34
35 SecBuf(const_iterator first, const_iterator last) : vec_(first, last) {}
36
37 SecBuf(const std::vector<T>& x) : vec_(x) {}
38
40 // Resize to its largest capacity and fill the whole memory with zeros.
41 vec_.resize(vec_.capacity());
42 std::fill(vec_.begin(), vec_.end(), 0);
43 };
44
46 return (vec_.begin());
47 };
48
50 return (vec_.begin());
51 };
52
54 return (vec_.end());
55 };
56
58 return (vec_.end());
59 };
60
61 size_t size() const {
62 return (vec_.size());
63 };
64
65 void resize(size_t sz) {
66 vec_.resize(sz);
67 };
68
69 void clear() {
70 // Resize to its largest capacity and fill the whole memory with zeros.
71 vec_.resize(vec_.capacity());
72 std::fill(vec_.begin(), vec_.end(), 0);
73
74 // Remove all elements.
75 vec_.clear();
76 }
77
78 SecBuf& operator=(const SecBuf& x) {
79 if (&x != *this) {
80 vec_ = x.vec_;
81 }
82 return (*this);
83 };
84
85 T& operator[](size_t n) {
86 return (vec_[n]);
87 };
88
89 const T& operator[](size_t n) const {
90 return (vec_[n]);
91 };
92
93 // constant time comparison against timing attacks
94 // (same type than XXX::verify() so const void* (vs. const T*) x)
95 bool same(const void* x, size_t len) const {
96 bool ret = true;
97 const T* p = static_cast<const T*>(x);
98 for (size_t i = 0; i < len; ++i)
99 ret = ret && (vec_[i] == p[i]);
100 return ret;
101 };
102
103private:
104 std::vector<T> vec_;
105};
106
107} // namespace ossl
108} // namespace cryptolink
109} // namespace isc
Defines the logger used by the top-level component of kea-lfc.