summaryrefslogtreecommitdiff
path: root/sbin/iked
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2023-07-16 15:21:47 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2023-07-16 15:21:47 +0000
commitce6d8fa379ba418a90b8e754100b4bf4d9a786c4 (patch)
tree706946a2ea10913db18d488c4eefb7eeb9d8dd32 /sbin/iked
parentbbab6324bd52e9be47050e3da87f99e1daaa29a8 (diff)
Merge ibuf_get() with ibuf_getdata() and rename it to ibuf_getdata().
Also replace a ibuf_reserve() call with ibuf_add_zero() and remove a buf->buf == NULL check in ibuf_length() since it is not necessary. OK tobhe@ tb@
Diffstat (limited to 'sbin/iked')
-rw-r--r--sbin/iked/iked.h5
-rw-r--r--sbin/iked/ikev2.c30
-rw-r--r--sbin/iked/imsg_util.c19
3 files changed, 23 insertions, 31 deletions
diff --git a/sbin/iked/iked.h b/sbin/iked/iked.h
index dc97f6560f9..c08f35bd52f 100644
--- a/sbin/iked/iked.h
+++ b/sbin/iked/iked.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: iked.h,v 1.220 2023/06/28 14:10:24 tobhe Exp $ */
+/* $OpenBSD: iked.h,v 1.221 2023/07/16 15:21:46 claudio Exp $ */
/*
* Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de>
@@ -1271,9 +1271,8 @@ struct ibuf *
int ibuf_cat(struct ibuf *, struct ibuf *);
size_t ibuf_length(struct ibuf *);
int ibuf_setsize(struct ibuf *, size_t);
-void *ibuf_getdata(struct ibuf *, size_t);
struct ibuf *
- ibuf_get(struct ibuf *, size_t);
+ ibuf_getdata(struct ibuf *, size_t);
struct ibuf *
ibuf_dup(struct ibuf *);
struct ibuf *
diff --git a/sbin/iked/ikev2.c b/sbin/iked/ikev2.c
index 88e7ad54318..349e16a40da 100644
--- a/sbin/iked/ikev2.c
+++ b/sbin/iked/ikev2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ikev2.c,v 1.372 2023/06/28 14:10:24 tobhe Exp $ */
+/* $OpenBSD: ikev2.c,v 1.373 2023/07/16 15:21:46 claudio Exp $ */
/*
* Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de>
@@ -5829,16 +5829,20 @@ ikev2_sa_keys(struct iked *env, struct iked_sa *sa, struct ibuf *key)
goto done;
}
- /* ibuf_get() returns a new buffer from the next read offset */
- if ((sa->sa_key_d = ibuf_get(t, hash_length(prf))) == NULL ||
+ /* ibuf_getdata() returns a new buffer from the next read offset */
+ if ((sa->sa_key_d = ibuf_getdata(t, hash_length(prf))) == NULL ||
(!isaead &&
- (sa->sa_key_iauth = ibuf_get(t, hash_keylength(integr))) == NULL) ||
+ (sa->sa_key_iauth = ibuf_getdata(t, hash_keylength(integr))) ==
+ NULL) ||
(!isaead &&
- (sa->sa_key_rauth = ibuf_get(t, hash_keylength(integr))) == NULL) ||
- (sa->sa_key_iencr = ibuf_get(t, cipher_keylength(encr))) == NULL ||
- (sa->sa_key_rencr = ibuf_get(t, cipher_keylength(encr))) == NULL ||
- (sa->sa_key_iprf = ibuf_get(t, hash_length(prf))) == NULL ||
- (sa->sa_key_rprf = ibuf_get(t, hash_length(prf))) == NULL) {
+ (sa->sa_key_rauth = ibuf_getdata(t, hash_keylength(integr))) ==
+ NULL) ||
+ (sa->sa_key_iencr = ibuf_getdata(t, cipher_keylength(encr))) ==
+ NULL ||
+ (sa->sa_key_rencr = ibuf_getdata(t, cipher_keylength(encr))) ==
+ NULL ||
+ (sa->sa_key_iprf = ibuf_getdata(t, hash_length(prf))) == NULL ||
+ (sa->sa_key_rprf = ibuf_getdata(t, hash_length(prf))) == NULL) {
log_debug("%s: failed to get SA keys", SPI_SA(sa, __func__));
goto done;
}
@@ -6307,13 +6311,13 @@ ikev2_childsa_negotiate(struct iked *env, struct iked_sa *sa,
csa->csa_spi.spi_size = 4;
}
- if (encrxf && (csa->csa_encrkey = ibuf_get(keymat,
+ if (encrxf && (csa->csa_encrkey = ibuf_getdata(keymat,
encrxf->xform_keylength / 8)) == NULL) {
log_debug("%s: failed to get CHILD SA encryption key",
__func__);
goto done;
}
- if (integrxf && (csa->csa_integrkey = ibuf_get(keymat,
+ if (integrxf && (csa->csa_integrkey = ibuf_getdata(keymat,
integrxf->xform_keylength / 8)) == NULL) {
log_debug("%s: failed to get CHILD SA integrity key",
__func__);
@@ -6340,13 +6344,13 @@ ikev2_childsa_negotiate(struct iked *env, struct iked_sa *sa,
csb->csa_local = csa->csa_peer;
csb->csa_peer = csa->csa_local;
- if (encrxf && (csb->csa_encrkey = ibuf_get(keymat,
+ if (encrxf && (csb->csa_encrkey = ibuf_getdata(keymat,
encrxf->xform_keylength / 8)) == NULL) {
log_debug("%s: failed to get CHILD SA encryption key",
__func__);
goto done;
}
- if (integrxf && (csb->csa_integrkey = ibuf_get(keymat,
+ if (integrxf && (csb->csa_integrkey = ibuf_getdata(keymat,
integrxf->xform_keylength / 8)) == NULL) {
log_debug("%s: failed to get CHILD SA integrity key",
__func__);
diff --git a/sbin/iked/imsg_util.c b/sbin/iked/imsg_util.c
index eab8eea72bc..7c4a4d8eec3 100644
--- a/sbin/iked/imsg_util.c
+++ b/sbin/iked/imsg_util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg_util.c,v 1.19 2023/06/19 17:19:50 claudio Exp $ */
+/* $OpenBSD: imsg_util.c,v 1.20 2023/07/16 15:21:46 claudio Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -55,7 +55,7 @@ ibuf_new(const void *data, size_t len)
return (buf);
if (data == NULL) {
- if (ibuf_reserve(buf, len) == NULL) {
+ if (ibuf_add_zero(buf, len) != 0) {
ibuf_free(buf);
return (NULL);
}
@@ -78,12 +78,12 @@ ibuf_static(void)
size_t
ibuf_length(struct ibuf *buf)
{
- if (buf == NULL || buf->buf == NULL)
+ if (buf == NULL)
return (0);
return (ibuf_size(buf));
}
-void *
+struct ibuf *
ibuf_getdata(struct ibuf *buf, size_t len)
{
void *data;
@@ -92,17 +92,6 @@ ibuf_getdata(struct ibuf *buf, size_t len)
return (NULL);
buf->rpos += len;
- return (data);
-}
-
-struct ibuf *
-ibuf_get(struct ibuf *buf, size_t len)
-{
- void *data;
-
- if ((data = ibuf_getdata(buf, len)) == NULL)
- return (NULL);
-
return (ibuf_new(data, len));
}