From: deraadt Date: Mon, 29 Nov 2021 06:43:42 +0000 (+0000) Subject: sys/param.h was included for MAX(), MIN() and roundup(). make local X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=d8ea035b5f3eea75c26be8376feb6b972ce72a90;p=openbsd sys/param.h was included for MAX(), MIN() and roundup(). make local copies of MAXIMUM() and MINIMUM() like we have done in 50+ other places, and also include a roundup() ok jsg --- diff --git a/sbin/iked/crypto.c b/sbin/iked/crypto.c index 4ecda337c00..ac0e4967d82 100644 --- a/sbin/iked/crypto.c +++ b/sbin/iked/crypto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crypto.c,v 1.36 2021/11/18 22:59:03 tb Exp $ */ +/* $OpenBSD: crypto.c,v 1.37 2021/11/29 06:43:42 deraadt Exp $ */ /* * Copyright (c) 2010-2013 Reyk Floeter @@ -16,7 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include /* roundup */ +#include #include #include #include diff --git a/sbin/iked/dh.c b/sbin/iked/dh.c index c29d7305837..ff3126e5147 100644 --- a/sbin/iked/dh.c +++ b/sbin/iked/dh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dh.c,v 1.29 2021/05/28 18:01:39 tobhe Exp $ */ +/* $OpenBSD: dh.c,v 1.30 2021/11/29 06:43:42 deraadt Exp $ */ /* * Copyright (c) 2010-2014 Reyk Floeter @@ -16,12 +16,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include /* roundup */ -#include +#include #include #include #include +#include #include #include @@ -271,7 +271,7 @@ const struct group_id ike_groups[] = { /* "Private use" extensions */ /* PQC KEM */ { GROUP_SNTRUP761X25519, 1035, - (MAX(crypto_kem_sntrup761_PUBLICKEYBYTES, + (MAXIMUM(crypto_kem_sntrup761_PUBLICKEYBYTES, crypto_kem_sntrup761_CIPHERTEXTBYTES) + CURVE25519_SIZE) * 8 } }; diff --git a/sbin/iked/iked.h b/sbin/iked/iked.h index 4ac27c1747d..019e8c12b98 100644 --- a/sbin/iked/iked.h +++ b/sbin/iked/iked.h @@ -1,4 +1,4 @@ -/* $OpenBSD: iked.h,v 1.199 2021/11/27 21:50:05 tobhe Exp $ */ +/* $OpenBSD: iked.h,v 1.200 2021/11/29 06:43:42 deraadt Exp $ */ /* * Copyright (c) 2019 Tobias Heider @@ -29,6 +29,10 @@ #include "types.h" #include "dh.h" +#define MAXIMUM(a,b) (((a)>(b))?(a):(b)) +#define MINIMUM(a,b) (((a)<(b))?(a):(b)) +#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) + #ifndef IKED_H #define IKED_H diff --git a/sbin/iked/ikev2.c b/sbin/iked/ikev2.c index 8cbbfcaa46d..4dcb12bca89 100644 --- a/sbin/iked/ikev2.c +++ b/sbin/iked/ikev2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ikev2.c,v 1.337 2021/11/27 21:50:05 tobhe Exp $ */ +/* $OpenBSD: ikev2.c,v 1.338 2021/11/29 06:43:42 deraadt Exp $ */ /* * Copyright (c) 2019 Tobias Heider @@ -17,7 +17,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include /* roundup */ +#include #include #include #include @@ -4177,7 +4177,7 @@ ikev2_nonce_cmp(struct ibuf *a, struct ibuf *b) alen = ibuf_length(a); blen = ibuf_length(b); - len = MIN(alen, blen); + len = MINIMUM(alen, blen); ret = memcmp(ibuf_data(a), ibuf_data(b), len); if (ret == 0) ret = (alen < blen ? -1 : 1); diff --git a/sbin/iked/ikev2_msg.c b/sbin/iked/ikev2_msg.c index d586e4f56f3..2d96f448360 100644 --- a/sbin/iked/ikev2_msg.c +++ b/sbin/iked/ikev2_msg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ikev2_msg.c,v 1.82 2021/11/27 21:50:05 tobhe Exp $ */ +/* $OpenBSD: ikev2_msg.c,v 1.83 2021/11/29 06:43:42 deraadt Exp $ */ /* * Copyright (c) 2019 Tobias Heider @@ -17,7 +17,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include /* roundup */ +#include #include #include #include @@ -852,7 +852,7 @@ ikev2_send_encrypted_fragments(struct iked *env, struct iked_sa *sa, /* Encrypt message and add as an E payload */ data = ibuf_seek(in, offset, 0); - if ((e = ibuf_new(data, MIN(left, max_len))) == NULL) { + if ((e = ibuf_new(data, MINIMUM(left, max_len))) == NULL) { goto done; } @@ -886,8 +886,8 @@ ikev2_send_encrypted_fragments(struct iked *env, struct iked_sa *sa, if (ikev2_msg_send(env, &resp) == -1) goto done; - offset += MIN(left, max_len); - left -= MIN(left, max_len); + offset += MINIMUM(left, max_len); + left -= MINIMUM(left, max_len); frag_num++; /* MUST be zero after first fragment */