return false;
}
-/* Choose the key with which to encrypt a data packet */
-void
-tls_pre_encrypt(struct tls_multi *multi,
- struct buffer *buf, struct crypto_options **opt)
+struct key_state *tls_select_encryption_key(struct tls_multi *multi)
{
- multi->save_ks = NULL;
- if (buf->len <= 0)
- {
- buf->len = 0;
- *opt = NULL;
- return;
- }
-
struct key_state *ks_select = NULL;
for (int i = 0; i < KEY_SCAN_SIZE; ++i)
{
struct key_state *ks = get_key_scan(multi, i);
if (ks->state >= S_ACTIVE
- && (ks->authenticated == KS_AUTH_TRUE)
- && ks->crypto_options.key_ctx_bi.initialized
- )
+ && ks->authenticated == KS_AUTH_TRUE
+ && ks->crypto_options.key_ctx_bi.initialized)
{
if (!ks_select)
{
}
}
}
+ return ks_select;
+}
+
+
+/* Choose the key with which to encrypt a data packet */
+void
+tls_pre_encrypt(struct tls_multi *multi,
+ struct buffer *buf, struct crypto_options **opt)
+{
+ multi->save_ks = NULL;
+ if (buf->len <= 0)
+ {
+ buf->len = 0;
+ *opt = NULL;
+ return;
+ }
+
+ struct key_state *ks_select = tls_select_encryption_key(multi);
if (ks_select)
{
void tls_pre_encrypt(struct tls_multi *multi,
struct buffer *buf, struct crypto_options **opt);
+/**
+ * Selects the primary encryption that should be used to encrypt data of an
+ * outgoing packet.
+ * @ingroup data_crypto
+ *
+ * If no key is found NULL is returned instead.
+ *
+ * @param multi - The TLS state for this packet's destination VPN tunnel.
+ */
+struct key_state *tls_select_encryption_key(struct tls_multi *multi);
/**
* Prepend a one-byte OpenVPN data channel P_DATA_V1 opcode to the packet.