OpenVPN 3 Core Library
Loading...
Searching...
No Matches
ovpndcokocrypto.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// Copyright (C) 2020-2022 Lev Stipakov <lev@openvpn.net>
9//
10// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
11//
12
13
14// ovpn-dco crypto wrappers
15
16#pragma once
17
18namespace openvpn::KoRekey {
19
24class OvpnDcoKey : public Key
25{
26 public:
27 OvpnDcoKey(const CryptoDCInstance::RekeyType rktype, const Info &rkinfo)
28 {
29 std::memset(&kc, 0, sizeof(kc));
30
32
34 const CryptoAlgs::Alg &calg = CryptoAlgs::get(ci.cipher());
35 switch (ci.cipher())
36 {
40 break;
43 kc.encrypt.cipher_key_size = 128 / 8;
44 break;
47 kc.encrypt.cipher_key_size = 192 / 8;
48 break;
51 kc.encrypt.cipher_key_size = 256 / 8;
52 break;
55 kc.encrypt.cipher_key_size = 256 / 8;
56 break;
57 default:
58 OPENVPN_THROW(korekey_error,
59 "cipher alg " << calg.name()
60 << " is not currently supported by ovpn-dco");
61 break;
62 }
64
65 if (calg.mode() == CryptoAlgs::AEAD)
66 {
67 kc.encrypt.cipher_key = verify_key("cipher encrypt",
68 rkinfo.encrypt_cipher,
70 kc.decrypt.cipher_key = verify_key("cipher decrypt",
71 rkinfo.decrypt_cipher,
73
74 set_nonce_tail("AEAD nonce tail encrypt",
76 sizeof(kc.encrypt.nonce_tail),
77 rkinfo.encrypt_hmac);
78 set_nonce_tail("AEAD nonce tail decrypt",
80 sizeof(kc.decrypt.nonce_tail),
81 rkinfo.decrypt_hmac);
82 }
83
84 kc.key_id = rkinfo.key_id;
85 }
86
87 const struct KeyConfig *operator()() const
88 {
89 return &kc;
90 }
91
92 private:
93 struct KeyConfig kc;
94};
95
96} // namespace openvpn::KoRekey
const char * name() const
virtual CryptoDCSettingsData crypto_info()=0
CryptoAlgs::Type cipher() const
Definition cryptodc.hpp:120
const unsigned char * verify_key(const char *title, const StaticKey &sk, const size_t size_required)
Definition kocrypto.hpp:108
void set_nonce_tail(const char *title, unsigned char *dest, const size_t dest_size, const StaticKey &src)
Definition kocrypto.hpp:115
Parses key information into format consumed by ovpn-dco.
const struct KeyConfig * operator()() const
OvpnDcoKey(const CryptoDCInstance::RekeyType rktype, const Info &rkinfo)
#define OPENVPN_THROW(exc, stuff)
const Alg & get(const Type type)
@ OVPN_CIPHER_ALG_CHACHA20_POLY1305
Definition ovpn-dco.h:104
@ OVPN_CIPHER_ALG_AES_GCM
Definition ovpn-dco.h:103
@ OVPN_CIPHER_ALG_NONE
Definition ovpn-dco.h:102
unsigned int key_id
Definition kocrypto.hpp:47
CryptoDCContext::Ptr dc_context_delegate
Definition kocrypto.hpp:45
unsigned int cipher_alg
Definition key.hpp:32
KeyDirection encrypt
Definition key.hpp:27
KeyDirection decrypt
Definition key.hpp:28
const unsigned char * cipher_key
Definition key.hpp:20
unsigned int cipher_key_size
Definition key.hpp:22
unsigned char nonce_tail[8]
Definition key.hpp:21