OpenVPN 3 Core Library
Loading...
Searching...
No Matches
aead_usage_limit.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#ifndef OPENVPN_CRYPTO_CRYPTO_AEAD_USAGE_LIMIT_H
13#define OPENVPN_CRYPTO_CRYPTO_AEAD_USAGE_LIMIT_H
14
15#include <cstdint>
17
18namespace openvpn::Crypto {
19
23{
24 uint64_t invocations = 0;
25 uint64_t plaintext_blocks = 0;
28
29 public:
30 AEADUsageLimit() = default;
31
33 : limit(openvpn::CryptoAlgs::aead_usage_limit(type))
34 {
35 }
36
37 /* Since cipher_ctx_block_size() of OpenSSL is not reliable and will return 1 in many
38 * cases use a hardcoded blocksize instead. This is technically false for Chacha20-Poly1305 but
39 * Chacha20-Poly1305 also does not need the limit currently*/
40 static constexpr size_t aead_blocksize = 16;
41
43 void update(const std::size_t outlen)
44 {
45 /* update number of plaintext blocks encrypted. Use the x + (n-1)/n trick
46 * to round up the result to the number of blocked used */
49 }
50
52 [[nodiscard]] bool usage_limit_reached() const
53 {
54 if (limit == 0)
55 return false;
56
58 }
59
61 [[nodiscard]] bool usage_limit_warn() const
62 {
63 if (limit == 0)
64 return false;
65
66 return plaintext_blocks + invocations > limit / 8 * 7;
67 }
68};
69} // namespace openvpn::Crypto
70
71#endif
AEADUsageLimit(openvpn::CryptoAlgs::Type type)
void update(const std::size_t outlen)
static constexpr size_t aead_blocksize
static constexpr uint64_t gcm_limit