From: "plaisthos (Code Review)" Date: Mon, 11 Nov 2024 01:59:48 +0000 References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="AlyZ8apNdx0="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Split init_key_ctx_bi into send/recv init List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --AlyZ8apNdx0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/799?usp=3Demail to review the following change. Change subject: Split init_key_ctx_bi into send/recv init ...................................................................... Split init_key_ctx_bi into send/recv init This allows for only initialising one of the keys. This is needed for epoch keys where key rotation of send/recv key can happen at different time points. Change-Id: If9e029bdac264dcc05b2d256c4d323315904a92b Signed-off-by: Arne Schwabe --- M src/openvpn/crypto.c M src/openvpn/crypto.h 2 files changed, 38 insertions(+), 5 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/99/799/1 diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index a366474..f0b60a3 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -939,8 +939,8 @@ } void -init_key_ctx_bi(struct key_ctx_bi *ctx, const struct key2 *key2, - int key_direction, const struct key_type *kt, const char *= name) +init_key_bi_ctx_send(struct key_ctx *ctx, const struct key2 *key2, + int key_direction, const struct key_type *kt, const c= har *name) { char log_prefix[128] =3D { 0 }; struct key_direction_state kds; @@ -948,13 +948,32 @@ key_direction_state_init(&kds, key_direction); snprintf(log_prefix, sizeof(log_prefix), "Outgoing %s", name); - init_key_ctx(&ctx->encrypt, &key2->keys[kds.out_key], kt, + init_key_ctx(ctx, &key2->keys[kds.out_key], kt, OPENVPN_OP_ENCRYPT, log_prefix); +} + +void +init_key_bi_ctx_recv(struct key_ctx *ctx, const struct key2 *key2, + int key_direction, const struct key_type *kt, const c= har *name) +{ + char log_prefix[128] =3D { 0 }; + struct key_direction_state kds; + + key_direction_state_init(&kds, key_direction); + snprintf(log_prefix, sizeof(log_prefix), "Incoming %s", name); - init_key_ctx(&ctx->decrypt, &key2->keys[kds.in_key], kt, + init_key_ctx(ctx, &key2->keys[kds.in_key], kt, OPENVPN_OP_DECRYPT, log_prefix); +} + +void +init_key_ctx_bi(struct key_ctx_bi *ctx, const struct key2 *key2, + int key_direction, const struct key_type *kt, const char *= name) +{ + init_key_bi_ctx_send(&ctx->encrypt, key2, key_direction, kt, name); + init_key_bi_ctx_recv(&ctx->decrypt, key2, key_direction, kt, name); ctx->initialized =3D true; } @@ -972,6 +991,8 @@ hmac_ctx_free(ctx->hmac); ctx->hmac =3D NULL; } + CLEAR(ctx->implicit_iv); + ctx->plaintext_blocks =3D 0; } void diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h index 0ae86f4..3331672 100644 --- a/src/openvpn/crypto.h +++ b/src/openvpn/crypto.h @@ -189,7 +189,9 @@ int n; /**< The number of \c key objects stored * in the \c key2.keys array. */ struct key keys[2]; /**< Two unidirectional sets of %key - * material. */ + * material. The first key is the client + * (encrypts) to server (decrypts), the + * second the server to client key. */ }; /** @@ -342,6 +344,16 @@ const struct key_type *kt, int enc, const char *prefix); +void +init_key_bi_ctx_send(struct key_ctx *ctx, const struct key2 *key2, + int key_direction, const struct key_type *kt, + const char *name); + +void +init_key_bi_ctx_recv(struct key_ctx *ctx, const struct key2 *key2, + int key_direction, const struct key_type *kt, + const char *name); + void free_key_ctx(struct key_ctx *ctx); =20 void init_key_ctx_bi(struct key_ctx_bi *ctx, const struct key2 *key2, -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/799?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: If9e029bdac264dcc05b2d256c4d323315904a92b Gerrit-Change-Number: 799 Gerrit-PatchSet: 1 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --AlyZ8apNdx0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld.

plaisthos would like flichtenheld to review this change.

Vi= ew Change

Split init_key_ctx_bi into send/recv init

This allows = for only initialising one of the keys. This is needed
for epoch keys whe= re key rotation of send/recv key can happen at
different time points.
Change-Id: If9e029bdac264dcc05b2d256c4d323315904a92b
Signed-off-by:= Arne Schwabe <arne@...1227...>
---
M src/openvpn/crypto.c
M= src/openvpn/crypto.h
2 files changed, 38 insertions(+), 5 deletions(-)<= br>
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/99/7=
99/1
diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index a366474..f0b60a3 100644
--- a/src/openvpn/= crypto.c
+++ b/src/openvpn/crypto.c
@@ -939= ,8 +939,8 @@
}

void
-init_key_ctx_bi(struct ke= y_ctx_bi *ctx, const struct key2 *key2,
- int key_direction, const struct key_type = *kt, const char *name)
+ int = key_direction, const struct key_type *kt, const char *name)
{

char log_prefix[128] =3D { 0 };
= struct key_direction_state kds;
@@ -948,13 +948,32 @@
key_direction_state_init(&kds, key_direction);

snprintf(log_prefix, sizeof(log_prefix), = "Outgoing %s", name);
- init_key_ctx(&ctx->encrypt, &key2->keys[kds.out= _key], kt,
+ init_= key_ctx(ctx, &key2->keys[kds.out_key], kt,
= OPENVPN_OP_ENCRYPT, log_prefix);

+}

+
+init_key_bi_= ctx_recv(struct key_ctx *ctx, const struct key2 *key2,
+ int key_direction, = const struct key_type *kt, const char *name)
+{
+ char log_prefix[128] =3D { 0 };
+ struct key_direction_state kds;
+
+ key_direction_state_init(&kds, key_direction);<= /span>
+
= snprintf(log_prefix, sizeof(log_prefix), "Incoming %s", name);<= /span>
- init_key_ctx(&= ctx->decrypt, &key2->keys[kds.in_key], kt,
+ init_key_ctx(ctx, &key2->keys[= kds.in_key], kt,
OPENVPN_OP_DECRYPT, log_= prefix);

+}
+
= +void
+init_key_ctx_bi(struct key_ctx_bi *ctx, const= struct key2 *key2,
+= int key_direction, const struct key_type *kt, const char *n= ame)
+{
+ init_key_bi_ctx_send(&ctx= ->encrypt, key2, key_direction, kt, name);

+ init_key_bi_ctx_recv(&ctx->decrypt, ke= y2, key_direction, kt, name);
ctx->initialized =3D = true;
}

@@ -972,6 +991,8= @@
hmac_ctx_free(ctx->hmac);
= ctx->hmac =3D NULL;
}
+ CLEAR(ctx->implicit_iv);+ ctx->plaintext_blocks = =3D 0;
}

voiddiff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h
<= span>index 0ae86f4..3331672 100644

--- a/src/openvpn/crypto= .h
+++ b/src/openvpn/crypto.h
@@ -189,7 +18= 9,9 @@
int n; /**< The number = of \c key objects stored
= * in the \c key2.keys array. */
struct key keys[2]; = /**< Two unidirectional sets of %key
- * material. */=
+ = * material. The first key is the client
+ * (e= ncrypts) to server (decrypts), the
+ * second the server to cl= ient key. */
};

/**
@@ -342,6 +344,16 @@
const = struct key_type *kt, int enc,
const char= *prefix);

+void
+init_k= ey_bi_ctx_send(struct key_ctx *ctx, const struct key2 *key2,
+ int key_direc= tion, const struct key_type *kt,

+ const char *name);
+
+void
+= init_key_bi_ctx_recv(struct key_ctx *ctx, const struct key2 *key2,+ int key= _direction, const struct key_type *kt,
+ const char *name);
+
void free_key_ctx(= struct key_ctx *ctx);

void init_key_ctx_= bi(struct key_ctx_bi *ctx, const struct key2 *key2,
=

To view, visit change 799. To unsubscribe, or for help writing mail= filters, visit settings= .

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If9e029bdac264dcc05b2d256c4d= 323315904a92b
Gerrit-Change-Number: 799
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--AlyZ8apNdx0=--