From: "cron2 (Code Review)" Date: Sun, 22 Dec 2024 11:53:47 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <918288eec3c24d7a8c822871b991805d82be0c93-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="2+48z9gTNp0="; 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: plaisthos , flichtenheld Cc: openvpn-devel --2+48z9gTNp0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#9) to the change originally created by= plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/799?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 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 Acked-by: Gert Doering Message-Id: <20241221223905.18820-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30= 151.html Signed-off-by: Gert Doering --- 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/9 diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index faf69fc..982fb01 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -938,8 +938,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; @@ -947,13 +947,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; } @@ -971,6 +990,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 4579b65..b3612fb 100644 --- a/src/openvpn/crypto.h +++ b/src/openvpn/crypto.h @@ -196,7 +196,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. */ }; /** @@ -349,6 +351,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); 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: 9 Gerrit-Owner: plaisthos Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --2+48z9gTNp0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #9 to the change originally cr= eated by plaisthos.

View Change

The following approvals got outdated= and were removed: Code-Review+2 by cron2

Split init_key_ctx_bi into send/recv init

Thi= s 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 p= oints.

Change-Id: If9e029bdac264dcc05b2d256c4d323315904a92b
Signe= d-off-by: Arne Schwabe <arne@...1227...>
Acked-by: Gert Doering &l= t;gert@...1296...>
Message-Id: <20241221223905.18820-1-gert@...1826...= 6...>
URL: https://www.mail-archive.com/openvpn-devel@...1768...= ge.net/msg30151.html
Signed-off-by: Gert Doering <gert@...1296...>=
---
M src/openvpn/crypto.c
M src/openvpn/crypto.h
2 files chan= ged, 38 insertions(+), 5 deletions(-)

git pull ssh://gerrit.openv=
pn.net:29418/openvpn refs/changes/99/799/9
diff --git a/src/openvpn=
/crypto.c b/src/openvpn/crypto.c
index faf69fc..982fb01 100= 644
--- a/src/openvpn/crypto.c
+++ b/src/op= envpn/crypto.c
@@ -938,8 +938,8 @@
}

void
-init_key_ctx_bi(struct key_ctx_bi *ctx, const struct key2 *key= 2,
- int= key_direction, const struct key_type *kt, const char *name)
+init_key_bi_ctx_send(struct key_ct= x *ctx, const struct key2 *key2,

+ int key_direction, const struct key_type = *kt, const char *name)
{
char log_pre= fix[128] =3D { 0 };
struct key_direction_state kds;
@@ -947,13 +947,32 @@
key_direction_stat= e_init(&kds, key_direction);

snp= rintf(log_prefix, sizeof(log_prefix), "Outgoing %s", name);
- init_key_ctx(&ctx-&= gt;encrypt, &key2->keys[kds.out_key], kt,
+ init_key_ctx(ctx, &key2->keys[kds.o= ut_key], kt,
OPENVPN_OP_ENCRYPT, log_pref= ix);

+
+void

+init_key_bi_ctx_recv(struct key_ctx *ctx, const s= truct 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);
+
snprintf(log_prefix, sizeof(log_pre= fix), "Incoming %s", name);
- init_key_ctx(&ctx->decrypt, &key2->keys[k= ds.in_key], kt,
+ = init_key_ctx(ctx, &key2->keys[kds.in_key], kt,
= OPENVPN_OP_DECRYPT, log_prefix);

<= span style=3D"color: hsl(120, 100%, 40%);">+}

+
+void
+init_key= _ctx_bi(struct key_ctx_bi *ctx, const struct key2 *key2,
+ int key_direction, con= st 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;
}

@@ -971,6 +990,8 @@
hmac_ctx_= free(ctx->hmac);
ctx->hmac =3D NULL;<= br> }
+ = CLEAR(ctx->implicit_iv);
+ ctx->plaintext_blocks =3D 0;
}

void
diff --git a/src/openvpn/crypto= .h b/src/openvpn/crypto.h
index 4579b65..b3612fb 100644

--- a/src/openvpn/crypto.h
+++ b/src/openvpn/c= rypto.h
@@ -196,7 +196,9 @@
int n; = /**< The number of \c key objects stored
* in the \c key2.keys array. */
struct key keys[2]; /**< Two unidirectional set= s of %key
- = * material. */
+ * material. The first = key is the client
+ = * (encrypts) to server (decrypts), the

+ = * second the server to client key. */
};

/**
@@ -349,6 +351,16 @@
const struct key_type *kt, int enc, const char *prefix);
+void
+init_key_bi_ctx_send(struct key_ctx *ctx, co= nst struct key2 *key2,
+ cons= t char *name);
+
+void
+init_key_bi_ctx_recv(struct key_ctx *ct= x, const struct key2 *key2,
+ int key_direction, const struct key_type *kt,<= /span>
+ = 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 u= nsubscribe, 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: 9
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--2+48z9gTNp0=--