From 38a9ea224af706f08463ce910700930cbbfa714d Mon Sep 17 00:00:00 2001 From: purplerain Date: Sat, 30 Mar 2024 10:36:50 +0000 Subject: [PATCH] sync with OpenBSD -current --- etc/rc | 8 +- lib/libc/arch/sparc64/fpu/fpu_add.c | 3 +- lib/libc/arch/sparc64/fpu/fpu_compare.c | 3 +- lib/libc/arch/sparc64/fpu/fpu_div.c | 3 +- lib/libc/arch/sparc64/fpu/fpu_explode.c | 3 +- lib/libc/arch/sparc64/fpu/fpu_implode.c | 3 +- lib/libc/arch/sparc64/fpu/fpu_mul.c | 4 +- lib/libc/arch/sparc64/fpu/fpu_sqrt.c | 4 +- lib/libc/arch/sparc64/fpu/fpu_subr.c | 3 +- lib/libc/stdlib/malloc.c | 22 +- lib/libcrypto/Symbols.namespace | 37 ++ lib/libcrypto/aes/aes.c | 11 +- lib/libcrypto/aes/aes_cbc.c | 65 ---- lib/libcrypto/aes/aes_cfb.c | 84 ----- lib/libcrypto/aes/aes_core.c | 6 +- lib/libcrypto/aes/aes_ctr.c | 62 ---- lib/libcrypto/aes/aes_ecb.c | 69 ---- lib/libcrypto/aes/aes_ige.c | 3 +- lib/libcrypto/aes/aes_ofb.c | 61 ---- lib/libcrypto/aes/aes_wrap.c | 133 -------- lib/libcrypto/camellia/camellia.c | 12 +- lib/libcrypto/cms/cms.h | 6 +- lib/libcrypto/cms/cms_ess.c | 6 +- lib/libcrypto/cms/cms_io.c | 6 +- lib/libcrypto/cms/cms_lib.c | 3 +- lib/libcrypto/hidden/openssl/aes.h | 43 +++ lib/libcrypto/hidden/openssl/camellia.h | 39 +++ lib/libcrypto/hidden/openssl/cms.h | 11 +- lib/libcrypto/hidden/openssl/whrlpool.h | 34 ++ lib/libcrypto/rsa/rsa_pk1.c | 132 ++++++-- lib/libcrypto/whrlpool/whirlpool.c | 7 +- libexec/ld.so/sparc64/rtld_machine.c | 4 +- regress/lib/libcrypto/dsa/Makefile | 14 +- regress/lib/libcrypto/free/freenull.c.tail | 4 +- regress/lib/libcrypto/rsa/Makefile | 15 +- regress/lib/libcrypto/rsa/rsa_padding_test.c | 335 +++++++++++++++++++ regress/usr.sbin/btrace/if.bt | 29 ++ regress/usr.sbin/btrace/if.ok | 4 + sys/dev/fdt/dwiic_fdt.c | 44 ++- usr.bin/ssh/PROTOCOL.key | 4 +- usr.bin/ssh/readpass.c | 9 +- usr.sbin/btrace/bt_parse.y | 20 +- usr.sbin/btrace/bt_parser.h | 10 +- usr.sbin/btrace/btrace.c | 34 +- 44 files changed, 791 insertions(+), 621 deletions(-) delete mode 100644 lib/libcrypto/aes/aes_cbc.c delete mode 100644 lib/libcrypto/aes/aes_cfb.c delete mode 100644 lib/libcrypto/aes/aes_ctr.c delete mode 100644 lib/libcrypto/aes/aes_ecb.c delete mode 100644 lib/libcrypto/aes/aes_ofb.c delete mode 100644 lib/libcrypto/aes/aes_wrap.c create mode 100644 lib/libcrypto/hidden/openssl/aes.h create mode 100644 lib/libcrypto/hidden/openssl/camellia.h create mode 100644 lib/libcrypto/hidden/openssl/whrlpool.h create mode 100644 regress/lib/libcrypto/rsa/rsa_padding_test.c diff --git a/etc/rc b/etc/rc index 9d87fac8c..0ea912fa7 100644 --- a/etc/rc +++ b/etc/rc @@ -1,4 +1,4 @@ -# $OpenBSD: rc,v 1.572 2023/10/01 20:15:23 naddy Exp $ +# $OpenBSD: rc,v 1.573 2024/03/30 07:35:01 deraadt Exp $ # System startup script run by init on autoboot or after single-user. # Output and error are redirected to console by init, and the console is the @@ -251,7 +251,11 @@ reorder_libs() { if [[ -f $_bint ]]; then echo " $_binn" tar xf $_bint - make -f Makefile.relink relink >/dev/null 2>&1 + if [[ -f install.sh ]]; then + sh install.sh >/dev/null 2>&1 + else + make -f Makefile.relink relink >/dev/null 2>&1 + fi fi ) || { _error=true; break; } done diff --git a/lib/libc/arch/sparc64/fpu/fpu_add.c b/lib/libc/arch/sparc64/fpu/fpu_add.c index 3f96b40bc..72bf0f688 100644 --- a/lib/libc/arch/sparc64/fpu/fpu_add.c +++ b/lib/libc/arch/sparc64/fpu/fpu_add.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fpu_add.c,v 1.4 2021/09/17 15:12:28 deraadt Exp $ */ +/* $OpenBSD: fpu_add.c,v 1.5 2024/03/29 21:02:11 miod Exp $ */ /* * Copyright (c) 1992, 1993 @@ -53,7 +53,6 @@ #include -#include #include #include diff --git a/lib/libc/arch/sparc64/fpu/fpu_compare.c b/lib/libc/arch/sparc64/fpu/fpu_compare.c index d5521f0aa..c49935d20 100644 --- a/lib/libc/arch/sparc64/fpu/fpu_compare.c +++ b/lib/libc/arch/sparc64/fpu/fpu_compare.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fpu_compare.c,v 1.3 2019/03/15 05:42:38 kevlo Exp $ */ +/* $OpenBSD: fpu_compare.c,v 1.4 2024/03/29 21:02:11 miod Exp $ */ /* * Copyright (c) 1992, 1993 @@ -54,7 +54,6 @@ #include -#include #include #include "fpu_arith.h" diff --git a/lib/libc/arch/sparc64/fpu/fpu_div.c b/lib/libc/arch/sparc64/fpu/fpu_div.c index e86369bf2..f9e8d82a2 100644 --- a/lib/libc/arch/sparc64/fpu/fpu_div.c +++ b/lib/libc/arch/sparc64/fpu/fpu_div.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fpu_div.c,v 1.4 2019/03/15 05:42:38 kevlo Exp $ */ +/* $OpenBSD: fpu_div.c,v 1.5 2024/03/29 21:02:11 miod Exp $ */ /* * Copyright (c) 1992, 1993 @@ -51,7 +51,6 @@ #include -#include #include #include "fpu_arith.h" diff --git a/lib/libc/arch/sparc64/fpu/fpu_explode.c b/lib/libc/arch/sparc64/fpu/fpu_explode.c index 987882e9d..0e118e447 100644 --- a/lib/libc/arch/sparc64/fpu/fpu_explode.c +++ b/lib/libc/arch/sparc64/fpu/fpu_explode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fpu_explode.c,v 1.11 2021/09/17 15:12:28 deraadt Exp $ */ +/* $OpenBSD: fpu_explode.c,v 1.12 2024/03/29 21:02:11 miod Exp $ */ /* * Copyright (c) 1992, 1993 @@ -52,7 +52,6 @@ #include -#include #include #include #include diff --git a/lib/libc/arch/sparc64/fpu/fpu_implode.c b/lib/libc/arch/sparc64/fpu/fpu_implode.c index 07498976b..63f9677fe 100644 --- a/lib/libc/arch/sparc64/fpu/fpu_implode.c +++ b/lib/libc/arch/sparc64/fpu/fpu_implode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fpu_implode.c,v 1.7 2021/09/17 15:12:28 deraadt Exp $ */ +/* $OpenBSD: fpu_implode.c,v 1.8 2024/03/29 21:02:11 miod Exp $ */ /* * Copyright (c) 1992, 1993 @@ -52,7 +52,6 @@ #include -#include #include #include #include diff --git a/lib/libc/arch/sparc64/fpu/fpu_mul.c b/lib/libc/arch/sparc64/fpu/fpu_mul.c index 6f2092d38..259478b62 100644 --- a/lib/libc/arch/sparc64/fpu/fpu_mul.c +++ b/lib/libc/arch/sparc64/fpu/fpu_mul.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fpu_mul.c,v 1.3 2019/03/15 05:42:38 kevlo Exp $ */ +/* $OpenBSD: fpu_mul.c,v 1.4 2024/03/29 21:02:11 miod Exp $ */ /* * Copyright (c) 1992, 1993 @@ -51,8 +51,6 @@ #include -#include - #include "fpu_arith.h" #include "fpu_emu.h" #include "fpu_extern.h" diff --git a/lib/libc/arch/sparc64/fpu/fpu_sqrt.c b/lib/libc/arch/sparc64/fpu/fpu_sqrt.c index e44f10fc2..26b840bd1 100644 --- a/lib/libc/arch/sparc64/fpu/fpu_sqrt.c +++ b/lib/libc/arch/sparc64/fpu/fpu_sqrt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fpu_sqrt.c,v 1.6 2022/12/27 17:10:06 jmc Exp $ */ +/* $OpenBSD: fpu_sqrt.c,v 1.7 2024/03/29 21:02:11 miod Exp $ */ /* * Copyright (c) 1992, 1993 @@ -51,8 +51,6 @@ #include -#include - #include "fpu_arith.h" #include "fpu_emu.h" #include "fpu_extern.h" diff --git a/lib/libc/arch/sparc64/fpu/fpu_subr.c b/lib/libc/arch/sparc64/fpu/fpu_subr.c index 530550de3..3ef37a1a6 100644 --- a/lib/libc/arch/sparc64/fpu/fpu_subr.c +++ b/lib/libc/arch/sparc64/fpu/fpu_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fpu_subr.c,v 1.4 2021/09/17 15:12:28 deraadt Exp $ */ +/* $OpenBSD: fpu_subr.c,v 1.5 2024/03/29 21:02:11 miod Exp $ */ /* * Copyright (c) 1992, 1993 @@ -51,7 +51,6 @@ #include -#include #include #include diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 5c0ab9978..53133956e 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.c,v 1.295 2023/12/19 06:59:28 otto Exp $ */ +/* $OpenBSD: malloc.c,v 1.296 2024/03/30 07:50:39 miod Exp $ */ /* * Copyright (c) 2008, 2010, 2011, 2016, 2023 Otto Moerbeek * Copyright (c) 2012 Matthew Dempsky @@ -1428,7 +1428,7 @@ _malloc_init(int from_rthreads) } if (!mopts.malloc_canary) { char *p; - size_t sz, d_avail; + size_t sz, roundup_sz, d_avail; omalloc_init(); /* @@ -1436,20 +1436,20 @@ _malloc_init(int from_rthreads) * randomise offset inside the page at which the dir_infos * lay (subject to alignment by 1 << MALLOC_MINSHIFT) */ - sz = mopts.malloc_mutexes * sizeof(*d) + 2 * MALLOC_PAGESIZE; - if ((p = MMAPNONE(sz, 0)) == MAP_FAILED) + sz = mopts.malloc_mutexes * sizeof(*d); + roundup_sz = (sz + MALLOC_PAGEMASK) & ~MALLOC_PAGEMASK; + if ((p = MMAPNONE(roundup_sz + 2 * MALLOC_PAGESIZE, 0)) == + MAP_FAILED) wrterror(NULL, "malloc_init mmap1 failed"); - if (mprotect(p + MALLOC_PAGESIZE, mopts.malloc_mutexes * - sizeof(*d), PROT_READ | PROT_WRITE)) + if (mprotect(p + MALLOC_PAGESIZE, roundup_sz, + PROT_READ | PROT_WRITE)) wrterror(NULL, "malloc_init mprotect1 failed"); - if (mimmutable(p, sz)) + if (mimmutable(p, roundup_sz + 2 * MALLOC_PAGESIZE)) wrterror(NULL, "malloc_init mimmutable1 failed"); - d_avail = (((mopts.malloc_mutexes * sizeof(*d) + - MALLOC_PAGEMASK) & ~MALLOC_PAGEMASK) - - (mopts.malloc_mutexes * sizeof(*d))) >> MALLOC_MINSHIFT; + d_avail = (roundup_sz - sz) >> MALLOC_MINSHIFT; d = (struct dir_info *)(p + MALLOC_PAGESIZE + (arc4random_uniform(d_avail) << MALLOC_MINSHIFT)); - STATS_ADD(d[1].malloc_used, sz); + STATS_ADD(d[1].malloc_used, roundup_sz + 2 * MALLOC_PAGESIZE); for (i = 0; i < mopts.malloc_mutexes; i++) mopts.malloc_pool[i] = &d[i]; mopts.internal_funcs = 1; diff --git a/lib/libcrypto/Symbols.namespace b/lib/libcrypto/Symbols.namespace index 511cd626b..a9ac044b7 100644 --- a/lib/libcrypto/Symbols.namespace +++ b/lib/libcrypto/Symbols.namespace @@ -2591,3 +2591,40 @@ _libre_BF_ecb_encrypt _libre_BF_cbc_encrypt _libre_BF_cfb64_encrypt _libre_BF_ofb64_encrypt +_libre_PEM_read_bio_CMS +_libre_PEM_read_CMS +_libre_PEM_write_bio_CMS +_libre_PEM_write_CMS +_libre_CMS_get1_ReceiptRequest +_libre_CMS_ReceiptRequest_create0 +_libre_CMS_add1_ReceiptRequest +_libre_CMS_ReceiptRequest_get0_values +_libre_WHIRLPOOL_Init +_libre_WHIRLPOOL_Update +_libre_WHIRLPOOL_BitUpdate +_libre_WHIRLPOOL_Final +_libre_WHIRLPOOL +_libre_Camellia_set_key +_libre_Camellia_encrypt +_libre_Camellia_decrypt +_libre_Camellia_ecb_encrypt +_libre_Camellia_cbc_encrypt +_libre_Camellia_cfb128_encrypt +_libre_Camellia_cfb1_encrypt +_libre_Camellia_cfb8_encrypt +_libre_Camellia_ofb128_encrypt +_libre_Camellia_ctr128_encrypt +_libre_AES_set_encrypt_key +_libre_AES_set_decrypt_key +_libre_AES_encrypt +_libre_AES_decrypt +_libre_AES_ecb_encrypt +_libre_AES_cbc_encrypt +_libre_AES_cfb128_encrypt +_libre_AES_cfb1_encrypt +_libre_AES_cfb8_encrypt +_libre_AES_ofb128_encrypt +_libre_AES_ctr128_encrypt +_libre_AES_ige_encrypt +_libre_AES_wrap_key +_libre_AES_unwrap_key diff --git a/lib/libcrypto/aes/aes.c b/lib/libcrypto/aes/aes.c index 9b25a21f4..4d040ea5f 100644 --- a/lib/libcrypto/aes/aes.c +++ b/lib/libcrypto/aes/aes.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aes.c,v 1.2 2024/03/28 12:52:58 jsing Exp $ */ +/* $OpenBSD: aes.c,v 1.3 2024/03/30 05:14:12 joshua Exp $ */ /* ==================================================================== * Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved. * @@ -83,6 +83,7 @@ AES_cbc_encrypt(const unsigned char *in, unsigned char *out, { aes_cbc_encrypt_internal(in, out, len, key, ivec, enc); } +LCRYPTO_ALIAS(AES_cbc_encrypt); /* * The input and output encrypted as though 128bit cfb mode is being @@ -97,6 +98,7 @@ AES_cfb128_encrypt(const unsigned char *in, unsigned char *out, size_t length, CRYPTO_cfb128_encrypt(in, out, length, key, ivec, num, enc, (block128_f)AES_encrypt); } +LCRYPTO_ALIAS(AES_cfb128_encrypt); /* N.B. This expects the input to be packed, MS bit first */ void @@ -106,6 +108,7 @@ AES_cfb1_encrypt(const unsigned char *in, unsigned char *out, size_t length, CRYPTO_cfb128_1_encrypt(in, out, length, key, ivec, num, enc, (block128_f)AES_encrypt); } +LCRYPTO_ALIAS(AES_cfb1_encrypt); void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out, size_t length, @@ -114,6 +117,7 @@ AES_cfb8_encrypt(const unsigned char *in, unsigned char *out, size_t length, CRYPTO_cfb128_8_encrypt(in, out, length, key, ivec, num, enc, (block128_f)AES_encrypt); } +LCRYPTO_ALIAS(AES_cfb8_encrypt); void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, @@ -123,6 +127,7 @@ AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, CRYPTO_ctr128_encrypt(in, out, length, key, ivec, ecount_buf, num, (block128_f)AES_encrypt); } +LCRYPTO_ALIAS(AES_ctr128_encrypt); void AES_ecb_encrypt(const unsigned char *in, unsigned char *out, @@ -133,6 +138,7 @@ AES_ecb_encrypt(const unsigned char *in, unsigned char *out, else AES_decrypt(in, out, key); } +LCRYPTO_ALIAS(AES_ecb_encrypt); void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, size_t length, @@ -141,6 +147,7 @@ AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, size_t length, CRYPTO_ofb128_encrypt(in, out, length, key, ivec, num, (block128_f)AES_encrypt); } +LCRYPTO_ALIAS(AES_ofb128_encrypt); int AES_wrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out, @@ -176,6 +183,7 @@ AES_wrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out, memcpy(out, A, 8); return inlen + 8; } +LCRYPTO_ALIAS(AES_wrap_key); int AES_unwrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out, @@ -213,3 +221,4 @@ AES_unwrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out, } return inlen; } +LCRYPTO_ALIAS(AES_unwrap_key); diff --git a/lib/libcrypto/aes/aes_cbc.c b/lib/libcrypto/aes/aes_cbc.c deleted file mode 100644 index 45c1f327b..000000000 --- a/lib/libcrypto/aes/aes_cbc.c +++ /dev/null @@ -1,65 +0,0 @@ -/* $OpenBSD: aes_cbc.c,v 1.12 2014/06/12 15:49:27 deraadt Exp $ */ -/* ==================================================================== - * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * openssl-core@openssl.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.openssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - */ - -#include -#include - -void -AES_cbc_encrypt(const unsigned char *in, unsigned char *out, - size_t len, const AES_KEY *key, unsigned char *ivec, const int enc) -{ - if (enc) - CRYPTO_cbc128_encrypt(in, out, len, key, ivec, - (block128_f)AES_encrypt); - else - CRYPTO_cbc128_decrypt(in, out, len, key, ivec, - (block128_f)AES_decrypt); -} diff --git a/lib/libcrypto/aes/aes_cfb.c b/lib/libcrypto/aes/aes_cfb.c deleted file mode 100644 index 6fc05054c..000000000 --- a/lib/libcrypto/aes/aes_cfb.c +++ /dev/null @@ -1,84 +0,0 @@ -/* $OpenBSD: aes_cfb.c,v 1.8 2014/06/12 15:49:27 deraadt Exp $ */ -/* ==================================================================== - * Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * openssl-core@openssl.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.openssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - */ - -#include -#include - -/* The input and output encrypted as though 128bit cfb mode is being - * used. The extra state information to record how much of the - * 128bit block we have used is contained in *num; - */ - -void -AES_cfb128_encrypt(const unsigned char *in, unsigned char *out, size_t length, - const AES_KEY *key, unsigned char *ivec, int *num, const int enc) -{ - CRYPTO_cfb128_encrypt(in, out, length, key, ivec, num, enc, - (block128_f)AES_encrypt); -} - -/* N.B. This expects the input to be packed, MS bit first */ -void -AES_cfb1_encrypt(const unsigned char *in, unsigned char *out, size_t length, - const AES_KEY *key, unsigned char *ivec, int *num, const int enc) -{ - CRYPTO_cfb128_1_encrypt(in, out, length, key, ivec, num, enc, - (block128_f)AES_encrypt); -} - -void -AES_cfb8_encrypt(const unsigned char *in, unsigned char *out, size_t length, - const AES_KEY *key, unsigned char *ivec, int *num, const int enc) -{ - CRYPTO_cfb128_8_encrypt(in, out, length, key, ivec, num, enc, - (block128_f)AES_encrypt); -} - diff --git a/lib/libcrypto/aes/aes_core.c b/lib/libcrypto/aes/aes_core.c index 23211dfcd..335b1dba5 100644 --- a/lib/libcrypto/aes/aes_core.c +++ b/lib/libcrypto/aes/aes_core.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aes_core.c,v 1.22 2024/03/29 11:19:01 jsing Exp $ */ +/* $OpenBSD: aes_core.c,v 1.23 2024/03/30 05:14:12 joshua Exp $ */ /** * rijndael-alg-fst.c * @@ -746,6 +746,7 @@ AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) { return aes_set_encrypt_key_internal(userKey, bits, key); } +LCRYPTO_ALIAS(AES_set_encrypt_key); #ifdef HAVE_AES_SET_DECRYPT_KEY_INTERNAL int aes_set_decrypt_key_internal(const unsigned char *userKey, const int bits, @@ -818,6 +819,7 @@ AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) { return aes_set_decrypt_key_internal(userKey, bits, key); } +LCRYPTO_ALIAS(AES_set_decrypt_key); #ifdef HAVE_AES_ENCRYPT_INTERNAL void aes_encrypt_internal(const unsigned char *in, unsigned char *out, @@ -1020,6 +1022,7 @@ AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) { return aes_encrypt_internal(in, out, key); } +LCRYPTO_ALIAS(AES_encrypt); #ifdef HAVE_AES_DECRYPT_INTERNAL void aes_decrypt_internal(const unsigned char *in, unsigned char *out, @@ -1222,3 +1225,4 @@ AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) { return aes_decrypt_internal(in, out, key); } +LCRYPTO_ALIAS(AES_decrypt); diff --git a/lib/libcrypto/aes/aes_ctr.c b/lib/libcrypto/aes/aes_ctr.c deleted file mode 100644 index 87e41d23a..000000000 --- a/lib/libcrypto/aes/aes_ctr.c +++ /dev/null @@ -1,62 +0,0 @@ -/* $OpenBSD: aes_ctr.c,v 1.9 2014/06/12 15:49:27 deraadt Exp $ */ -/* ==================================================================== - * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * openssl-core@openssl.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.openssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - */ - -#include -#include - -void -AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, - size_t length, const AES_KEY *key, unsigned char ivec[AES_BLOCK_SIZE], - unsigned char ecount_buf[AES_BLOCK_SIZE], unsigned int *num) -{ - CRYPTO_ctr128_encrypt(in, out, length, key, ivec, ecount_buf, num, - (block128_f)AES_encrypt); -} diff --git a/lib/libcrypto/aes/aes_ecb.c b/lib/libcrypto/aes/aes_ecb.c deleted file mode 100644 index 109010bcb..000000000 --- a/lib/libcrypto/aes/aes_ecb.c +++ /dev/null @@ -1,69 +0,0 @@ -/* $OpenBSD: aes_ecb.c,v 1.7 2022/11/26 16:08:50 tb Exp $ */ -/* ==================================================================== - * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * openssl-core@openssl.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.openssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - */ - -#ifndef AES_DEBUG -# ifndef NDEBUG -# define NDEBUG -# endif -#endif - -#include -#include "aes_local.h" - -void -AES_ecb_encrypt(const unsigned char *in, unsigned char *out, - const AES_KEY *key, const int enc) -{ - if (AES_ENCRYPT == enc) - AES_encrypt(in, out, key); - else - AES_decrypt(in, out, key); -} diff --git a/lib/libcrypto/aes/aes_ige.c b/lib/libcrypto/aes/aes_ige.c index 5b28c061c..541a32062 100644 --- a/lib/libcrypto/aes/aes_ige.c +++ b/lib/libcrypto/aes/aes_ige.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aes_ige.c,v 1.9 2022/11/26 16:08:50 tb Exp $ */ +/* $OpenBSD: aes_ige.c,v 1.10 2024/03/30 05:14:12 joshua Exp $ */ /* ==================================================================== * Copyright (c) 2006 The OpenSSL Project. All rights reserved. * @@ -192,3 +192,4 @@ AES_ige_encrypt(const unsigned char *in, unsigned char *out, size_t length, } } } +LCRYPTO_ALIAS(AES_ige_encrypt); diff --git a/lib/libcrypto/aes/aes_ofb.c b/lib/libcrypto/aes/aes_ofb.c deleted file mode 100644 index 89df6dcf1..000000000 --- a/lib/libcrypto/aes/aes_ofb.c +++ /dev/null @@ -1,61 +0,0 @@ -/* $OpenBSD: aes_ofb.c,v 1.6 2014/06/12 15:49:27 deraadt Exp $ */ -/* ==================================================================== - * Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * openssl-core@openssl.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.openssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - */ - -#include -#include - -void -AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, size_t length, - const AES_KEY *key, unsigned char *ivec, int *num) -{ - CRYPTO_ofb128_encrypt(in, out, length, key, ivec, num, - (block128_f)AES_encrypt); -} diff --git a/lib/libcrypto/aes/aes_wrap.c b/lib/libcrypto/aes/aes_wrap.c deleted file mode 100644 index 4497161fb..000000000 --- a/lib/libcrypto/aes/aes_wrap.c +++ /dev/null @@ -1,133 +0,0 @@ -/* $OpenBSD: aes_wrap.c,v 1.12 2018/11/07 18:31:16 tb Exp $ */ -/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL - * project. - */ -/* ==================================================================== - * Copyright (c) 2008 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * licensing@OpenSSL.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ - -#include - -#include -#include - -static const unsigned char default_iv[] = { - 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, -}; - -int -AES_wrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out, - const unsigned char *in, unsigned int inlen) -{ - unsigned char *A, B[16], *R; - unsigned int i, j, t; - - if ((inlen & 0x7) || (inlen < 16)) - return -1; - A = B; - t = 1; - memmove(out + 8, in, inlen); - if (!iv) - iv = default_iv; - - memcpy(A, iv, 8); - - for (j = 0; j < 6; j++) { - R = out + 8; - for (i = 0; i < inlen; i += 8, t++, R += 8) { - memcpy(B + 8, R, 8); - AES_encrypt(B, B, key); - A[7] ^= (unsigned char)(t & 0xff); - if (t > 0xff) { - A[6] ^= (unsigned char)((t >> 8) & 0xff); - A[5] ^= (unsigned char)((t >> 16) & 0xff); - A[4] ^= (unsigned char)((t >> 24) & 0xff); - } - memcpy(R, B + 8, 8); - } - } - memcpy(out, A, 8); - return inlen + 8; -} - -int -AES_unwrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out, - const unsigned char *in, unsigned int inlen) -{ - unsigned char *A, B[16], *R; - unsigned int i, j, t; - - if ((inlen & 0x7) || (inlen < 24)) - return -1; - inlen -= 8; - A = B; - t = 6 * (inlen >> 3); - memcpy(A, in, 8); - memmove(out, in + 8, inlen); - for (j = 0; j < 6; j++) { - R = out + inlen - 8; - for (i = 0; i < inlen; i += 8, t--, R -= 8) { - A[7] ^= (unsigned char)(t & 0xff); - if (t > 0xff) { - A[6] ^= (unsigned char)((t >> 8) & 0xff); - A[5] ^= (unsigned char)((t >> 16) & 0xff); - A[4] ^= (unsigned char)((t >> 24) & 0xff); - } - memcpy(B + 8, R, 8); - AES_decrypt(B, B, key); - memcpy(R, B + 8, 8); - } - } - if (!iv) - iv = default_iv; - if (memcmp(A, iv, 8)) { - explicit_bzero(out, inlen); - return 0; - } - return inlen; -} diff --git a/lib/libcrypto/camellia/camellia.c b/lib/libcrypto/camellia/camellia.c index 625988aad..a1e71104f 100644 --- a/lib/libcrypto/camellia/camellia.c +++ b/lib/libcrypto/camellia/camellia.c @@ -1,4 +1,4 @@ -/* $OpenBSD: camellia.c,v 1.13 2024/03/29 07:26:21 jsing Exp $ */ +/* $OpenBSD: camellia.c,v 1.14 2024/03/30 04:58:12 joshua Exp $ */ /* ==================================================================== * Copyright 2006 NTT (Nippon Telegraph and Telephone Corporation) . * ALL RIGHTS RESERVED. @@ -591,6 +591,7 @@ Camellia_set_key(const unsigned char *userKey, const int bits, key->grand_rounds = Camellia_Ekeygen(bits, userKey, key->u.rd_key); return 0; } +LCRYPTO_ALIAS(Camellia_set_key); void Camellia_encrypt(const unsigned char *in, unsigned char *out, @@ -598,6 +599,7 @@ Camellia_encrypt(const unsigned char *in, unsigned char *out, { Camellia_EncryptBlock_Rounds(key->grand_rounds, in, key->u.rd_key, out); } +LCRYPTO_ALIAS(Camellia_encrypt); void Camellia_decrypt(const unsigned char *in, unsigned char *out, @@ -605,6 +607,7 @@ Camellia_decrypt(const unsigned char *in, unsigned char *out, { Camellia_DecryptBlock_Rounds(key->grand_rounds, in, key->u.rd_key, out); } +LCRYPTO_ALIAS(Camellia_decrypt); void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out, size_t len, @@ -617,6 +620,7 @@ Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out, size_t len, CRYPTO_cbc128_decrypt(in, out, len, key, ivec, (block128_f)Camellia_decrypt); } +LCRYPTO_ALIAS(Camellia_cbc_encrypt); /* * The input and output encrypted as though 128bit cfb mode is being @@ -632,6 +636,7 @@ Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out, CRYPTO_cfb128_encrypt(in, out, length, key, ivec, num, enc, (block128_f)Camellia_encrypt); } +LCRYPTO_ALIAS(Camellia_cfb128_encrypt); /* N.B. This expects the input to be packed, MS bit first */ void @@ -642,6 +647,7 @@ Camellia_cfb1_encrypt(const unsigned char *in, unsigned char *out, CRYPTO_cfb128_1_encrypt(in, out, length, key, ivec, num, enc, (block128_f)Camellia_encrypt); } +LCRYPTO_ALIAS(Camellia_cfb1_encrypt); void Camellia_cfb8_encrypt(const unsigned char *in, unsigned char *out, @@ -651,6 +657,7 @@ Camellia_cfb8_encrypt(const unsigned char *in, unsigned char *out, CRYPTO_cfb128_8_encrypt(in, out, length, key, ivec, num, enc, (block128_f)Camellia_encrypt); } +LCRYPTO_ALIAS(Camellia_cfb8_encrypt); void Camellia_ctr128_encrypt(const unsigned char *in, unsigned char *out, @@ -661,6 +668,7 @@ Camellia_ctr128_encrypt(const unsigned char *in, unsigned char *out, CRYPTO_ctr128_encrypt(in, out, length, key, ivec, ecount_buf, num, (block128_f)Camellia_encrypt); } +LCRYPTO_ALIAS(Camellia_ctr128_encrypt); void Camellia_ecb_encrypt(const unsigned char *in, unsigned char *out, @@ -671,6 +679,7 @@ Camellia_ecb_encrypt(const unsigned char *in, unsigned char *out, else Camellia_decrypt(in, out, key); } +LCRYPTO_ALIAS(Camellia_ecb_encrypt); /* * The input and output encrypted as though 128bit ofb mode is being @@ -684,3 +693,4 @@ Camellia_ofb128_encrypt(const unsigned char *in, unsigned char *out, CRYPTO_ofb128_encrypt(in, out, length, key, ivec, num, (block128_f)Camellia_encrypt); } +LCRYPTO_ALIAS(Camellia_ofb128_encrypt); diff --git a/lib/libcrypto/cms/cms.h b/lib/libcrypto/cms/cms.h index 75983cee3..90030bdde 100644 --- a/lib/libcrypto/cms/cms.h +++ b/lib/libcrypto/cms/cms.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cms.h,v 1.17 2024/03/29 02:28:50 jsing Exp $ */ +/* $OpenBSD: cms.h,v 1.18 2024/03/30 00:35:15 joshua Exp $ */ /* * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. @@ -315,8 +315,6 @@ int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si, const char *attrname, void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid, int lastpos, int type); -#ifdef HEADER_X509V3_H - int CMS_get1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest **prr); CMS_ReceiptRequest *CMS_ReceiptRequest_create0(unsigned char *id, int idlen, int allorfirst, STACK_OF(GENERAL_NAMES) *receiptList, @@ -325,7 +323,7 @@ int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr); void CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr, ASN1_STRING **pcid, int *pallorfirst, STACK_OF(GENERAL_NAMES) **plist, STACK_OF(GENERAL_NAMES) **prto); -#endif + int CMS_RecipientInfo_kari_get0_alg(CMS_RecipientInfo *ri, X509_ALGOR **palg, ASN1_OCTET_STRING **pukm); STACK_OF(CMS_RecipientEncryptedKey) * diff --git a/lib/libcrypto/cms/cms_ess.c b/lib/libcrypto/cms/cms_ess.c index 16b54c199..cced99854 100644 --- a/lib/libcrypto/cms/cms_ess.c +++ b/lib/libcrypto/cms/cms_ess.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cms_ess.c,v 1.24 2024/01/14 18:40:24 tb Exp $ */ +/* $OpenBSD: cms_ess.c,v 1.25 2024/03/30 01:53:05 joshua Exp $ */ /* * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. @@ -118,6 +118,7 @@ CMS_get1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest **prr) return 1; } +LCRYPTO_ALIAS(CMS_get1_ReceiptRequest); CMS_ReceiptRequest * CMS_ReceiptRequest_create0(unsigned char *id, int idlen, int allorfirst, @@ -155,6 +156,7 @@ CMS_ReceiptRequest_create0(unsigned char *id, int idlen, int allorfirst, return NULL; } +LCRYPTO_ALIAS(CMS_ReceiptRequest_create0); int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr) @@ -180,6 +182,7 @@ CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr) return r; } +LCRYPTO_ALIAS(CMS_add1_ReceiptRequest); void CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr, ASN1_STRING **pcid, @@ -202,6 +205,7 @@ CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr, ASN1_STRING **pcid, if (prto) *prto = rr->receiptsTo; } +LCRYPTO_ALIAS(CMS_ReceiptRequest_get0_values); /* Digest a SignerInfo structure for msgSigDigest attribute processing */ diff --git a/lib/libcrypto/cms/cms_io.c b/lib/libcrypto/cms/cms_io.c index ceb4ce8ec..84ada47c4 100644 --- a/lib/libcrypto/cms/cms_io.c +++ b/lib/libcrypto/cms/cms_io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cms_io.c,v 1.20 2023/07/08 08:26:26 beck Exp $ */ +/* $OpenBSD: cms_io.c,v 1.21 2024/03/30 01:53:05 joshua Exp $ */ /* * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. @@ -105,6 +105,7 @@ PEM_read_bio_CMS(BIO *bp, CMS_ContentInfo **x, pem_password_cb *cb, void *u) return PEM_ASN1_read_bio((d2i_of_void *)d2i_CMS_ContentInfo, PEM_STRING_CMS, bp, (void **)x, cb, u); } +LCRYPTO_ALIAS(PEM_read_bio_CMS); CMS_ContentInfo * PEM_read_CMS(FILE *fp, CMS_ContentInfo **x, pem_password_cb *cb, void *u) @@ -112,6 +113,7 @@ PEM_read_CMS(FILE *fp, CMS_ContentInfo **x, pem_password_cb *cb, void *u) return PEM_ASN1_read((d2i_of_void *)d2i_CMS_ContentInfo, PEM_STRING_CMS, fp, (void **)x, cb, u); } +LCRYPTO_ALIAS(PEM_read_CMS); int PEM_write_bio_CMS(BIO *bp, const CMS_ContentInfo *x) @@ -119,6 +121,7 @@ PEM_write_bio_CMS(BIO *bp, const CMS_ContentInfo *x) return PEM_ASN1_write_bio((i2d_of_void *)i2d_CMS_ContentInfo, PEM_STRING_CMS, bp, (void *)x, NULL, NULL, 0, NULL, NULL); } +LCRYPTO_ALIAS(PEM_write_bio_CMS); int PEM_write_CMS(FILE *fp, const CMS_ContentInfo *x) @@ -126,6 +129,7 @@ PEM_write_CMS(FILE *fp, const CMS_ContentInfo *x) return PEM_ASN1_write((i2d_of_void *)i2d_CMS_ContentInfo, PEM_STRING_CMS, fp, (void *)x, NULL, NULL, 0, NULL, NULL); } +LCRYPTO_ALIAS(PEM_write_CMS); BIO * BIO_new_CMS(BIO *out, CMS_ContentInfo *cms) diff --git a/lib/libcrypto/cms/cms_lib.c b/lib/libcrypto/cms/cms_lib.c index 8a8fdbc8d..37eb3e294 100644 --- a/lib/libcrypto/cms/cms_lib.c +++ b/lib/libcrypto/cms/cms_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cms_lib.c,v 1.24 2023/08/24 04:56:36 tb Exp $ */ +/* $OpenBSD: cms_lib.c,v 1.25 2024/03/30 01:53:05 joshua Exp $ */ /* * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. @@ -314,6 +314,7 @@ CMS_get0_content(CMS_ContentInfo *cms) return NULL; } } +LCRYPTO_ALIAS(CMS_get0_content); /* * Return an ASN1_OBJECT pointer to content type. This allows it to be diff --git a/lib/libcrypto/hidden/openssl/aes.h b/lib/libcrypto/hidden/openssl/aes.h new file mode 100644 index 000000000..0ec5a8d54 --- /dev/null +++ b/lib/libcrypto/hidden/openssl/aes.h @@ -0,0 +1,43 @@ +/* $OpenBSD: aes.h,v 1.1 2024/03/30 05:14:12 joshua Exp $ */ +/* + * Copyright (c) 2024 Joshua Sing + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _LIBCRYPTO_AES_H +#define _LIBCRYPTO_AES_H + +#ifndef _MSC_VER +#include_next +#else +#include "../include/openssl/aes.h" +#endif +#include "crypto_namespace.h" + +LCRYPTO_USED(AES_set_encrypt_key); +LCRYPTO_USED(AES_set_decrypt_key); +LCRYPTO_USED(AES_encrypt); +LCRYPTO_USED(AES_decrypt); +LCRYPTO_USED(AES_ecb_encrypt); +LCRYPTO_USED(AES_cbc_encrypt); +LCRYPTO_USED(AES_cfb128_encrypt); +LCRYPTO_USED(AES_cfb1_encrypt); +LCRYPTO_USED(AES_cfb8_encrypt); +LCRYPTO_USED(AES_ofb128_encrypt); +LCRYPTO_USED(AES_ctr128_encrypt); +LCRYPTO_USED(AES_ige_encrypt); +LCRYPTO_USED(AES_wrap_key); +LCRYPTO_USED(AES_unwrap_key); + +#endif /* _LIBCRYPTO_AES_H */ diff --git a/lib/libcrypto/hidden/openssl/camellia.h b/lib/libcrypto/hidden/openssl/camellia.h new file mode 100644 index 000000000..bf7f43b1b --- /dev/null +++ b/lib/libcrypto/hidden/openssl/camellia.h @@ -0,0 +1,39 @@ +/* $OpenBSD: camellia.h,v 1.1 2024/03/30 04:58:12 joshua Exp $ */ +/* + * Copyright (c) 2024 Joshua Sing + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _LIBCRYPTO_CAMELLIA_H +#define _LIBCRYPTO_CAMELLIA_H + +#ifndef _MSC_VER +#include_next +#else +#include "../include/openssl/camellia.h" +#endif +#include "crypto_namespace.h" + +LCRYPTO_USED(Camellia_set_key); +LCRYPTO_USED(Camellia_encrypt); +LCRYPTO_USED(Camellia_decrypt); +LCRYPTO_USED(Camellia_ecb_encrypt); +LCRYPTO_USED(Camellia_cbc_encrypt); +LCRYPTO_USED(Camellia_cfb128_encrypt); +LCRYPTO_USED(Camellia_cfb1_encrypt); +LCRYPTO_USED(Camellia_cfb8_encrypt); +LCRYPTO_USED(Camellia_ofb128_encrypt); +LCRYPTO_USED(Camellia_ctr128_encrypt); + +#endif /* _LIBCRYPTO_CAMELLIA_H */ diff --git a/lib/libcrypto/hidden/openssl/cms.h b/lib/libcrypto/hidden/openssl/cms.h index 0f450e603..430b2c535 100644 --- a/lib/libcrypto/hidden/openssl/cms.h +++ b/lib/libcrypto/hidden/openssl/cms.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cms.h,v 1.2 2023/07/28 10:28:02 tb Exp $ */ +/* $OpenBSD: cms.h,v 1.3 2024/03/30 01:53:05 joshua Exp $ */ /* * Copyright (c) 2023 Bob Beck * @@ -39,8 +39,13 @@ LCRYPTO_USED(CMS_get_version); LCRYPTO_USED(CMS_SignerInfo_get_version); LCRYPTO_USED(CMS_dataInit); LCRYPTO_USED(CMS_dataFinal); +LCRYPTO_USED(CMS_get0_content); LCRYPTO_USED(CMS_is_detached); LCRYPTO_USED(CMS_set_detached); +LCRYPTO_USED(PEM_read_bio_CMS); +LCRYPTO_USED(PEM_read_CMS); +LCRYPTO_USED(PEM_write_bio_CMS); +LCRYPTO_USED(PEM_write_CMS); LCRYPTO_USED(CMS_stream); LCRYPTO_USED(d2i_CMS_bio); LCRYPTO_USED(i2d_CMS_bio); @@ -133,6 +138,10 @@ LCRYPTO_USED(CMS_unsigned_add1_attr_by_OBJ); LCRYPTO_USED(CMS_unsigned_add1_attr_by_NID); LCRYPTO_USED(CMS_unsigned_add1_attr_by_txt); LCRYPTO_USED(CMS_unsigned_get0_data_by_OBJ); +LCRYPTO_USED(CMS_get1_ReceiptRequest); +LCRYPTO_USED(CMS_ReceiptRequest_create0); +LCRYPTO_USED(CMS_add1_ReceiptRequest); +LCRYPTO_USED(CMS_ReceiptRequest_get0_values); LCRYPTO_USED(CMS_RecipientInfo_kari_get0_alg); LCRYPTO_USED(CMS_RecipientInfo_kari_get0_reks); LCRYPTO_USED(CMS_RecipientInfo_kari_get0_orig_id); diff --git a/lib/libcrypto/hidden/openssl/whrlpool.h b/lib/libcrypto/hidden/openssl/whrlpool.h new file mode 100644 index 000000000..c3e4a51d3 --- /dev/null +++ b/lib/libcrypto/hidden/openssl/whrlpool.h @@ -0,0 +1,34 @@ +/* $OpenBSD: whrlpool.h,v 1.1 2024/03/30 03:45:47 joshua Exp $ */ +/* + * Copyright (c) 2024 Joshua Sing + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _LIBCRYPTO_WHRLPOOL_H +#define _LIBCRYPTO_WHRLPOOL_H + +#ifndef _MSC_VER +#include_next +#else +#include "../include/openssl/whrlpool.h" +#endif +#include "crypto_namespace.h" + +LCRYPTO_USED(WHIRLPOOL_Init); +LCRYPTO_USED(WHIRLPOOL_Update); +LCRYPTO_USED(WHIRLPOOL_BitUpdate); +LCRYPTO_USED(WHIRLPOOL_Final); +LCRYPTO_USED(WHIRLPOOL); + +#endif /* _LIBCRYPTO_WHRLPOOL_H */ diff --git a/lib/libcrypto/rsa/rsa_pk1.c b/lib/libcrypto/rsa/rsa_pk1.c index 38f7c0be0..8e56a8c4c 100644 --- a/lib/libcrypto/rsa/rsa_pk1.c +++ b/lib/libcrypto/rsa/rsa_pk1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rsa_pk1.c,v 1.16 2023/07/08 12:26:45 beck Exp $ */ +/* $OpenBSD: rsa_pk1.c,v 1.17 2024/03/30 04:34:17 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -64,31 +64,61 @@ #include #include +#include "bytestring.h" + int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, const unsigned char *from, int flen) { - int j; - unsigned char *p; + CBB cbb; + int i; + int ret = 0; - if (flen > (tlen - RSA_PKCS1_PADDING_SIZE)) { + /* + * Pad data block with PKCS1 type 1 padding - RFC 2313, section 8.1. + */ + + memset(&cbb, 0, sizeof(cbb)); + + if (flen < 0 || tlen < 0) + goto err; + + if (flen > tlen - RSA_PKCS1_PADDING_SIZE) { RSAerror(RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); - return 0; + goto err; } - p = (unsigned char *)to; + if (!CBB_init_fixed(&cbb, to, tlen)) + goto err; - *(p++) = 0; - *(p++) = 1; /* Private Key BT (Block Type) */ + /* + * Add leading NUL, block type (0x01), padding bytes (0xff) and + * trailing NUL. + */ + if (!CBB_add_u8(&cbb, 0)) + goto err; + if (!CBB_add_u8(&cbb, 1)) + goto err; + for (i = 0; i < tlen - 3 - flen; i++) { + if (!CBB_add_u8(&cbb, 0xff)) + goto err; + } + if (!CBB_add_u8(&cbb, 0)) + goto err; - /* pad out with 0xff data */ - j = tlen - 3 - flen; - memset(p, 0xff, j); - p += j; - *(p++) = '\0'; - memcpy(p, from, flen); + /* Now add the actual data. */ + if (!CBB_add_bytes(&cbb, from, flen)) + goto err; - return 1; + if (!CBB_finish(&cbb, NULL, NULL)) + goto err; + + ret = 1; + + err: + CBB_cleanup(&cbb); + + return ret; } LCRYPTO_ALIAS(RSA_padding_add_PKCS1_type_1); @@ -146,33 +176,69 @@ int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, const unsigned char *from, int flen) { - int i, j; - unsigned char *p; + uint8_t padding[256]; + uint8_t pad; + CBB cbb; + CBS cbs; + int i; + int ret = 0; - if (flen > tlen - 11) { + /* + * Pad data block with PKCS1 type 2 padding - RFC 2313, section 8.1. + */ + + memset(&cbb, 0, sizeof(cbb)); + CBS_init(&cbs, NULL, 0); + + if (flen < 0 || tlen < 0) + goto err; + + if (flen > tlen - RSA_PKCS1_PADDING_SIZE) { RSAerror(RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); - return 0; + goto err; } - p = (unsigned char *)to; + if (!CBB_init_fixed(&cbb, to, tlen)) + goto err; - *(p++) = 0; - *(p++) = 2; /* Public Key BT (Block Type) */ + /* + * Add leading NUL, block type (0x02), padding bytes (random non-zero + * bytes) and trailing NUL. + */ + if (!CBB_add_u8(&cbb, 0)) + goto err; + if (!CBB_add_u8(&cbb, 2)) + goto err; + for (i = 0; i < tlen - 3 - flen; i++) { + do { + if (CBS_len(&cbs) == 0) { + arc4random_buf(padding, sizeof(padding)); + CBS_init(&cbs, padding, sizeof(padding)); + } + if (!CBS_get_u8(&cbs, &pad)) + goto err; + } while (pad == 0); - /* pad out with non-zero random data */ - j = tlen - 3 - flen; - - arc4random_buf(p, j); - for (i = 0; i < j; i++) { - while (*p == '\0') - arc4random_buf(p, 1); - p++; + if (!CBB_add_u8(&cbb, pad)) + goto err; } + if (!CBB_add_u8(&cbb, 0)) + goto err; - *(p++) = '\0'; + /* Now add the actual data. */ + if (!CBB_add_bytes(&cbb, from, flen)) + goto err; - memcpy(p, from, flen); - return 1; + if (!CBB_finish(&cbb, NULL, NULL)) + goto err; + + ret = 1; + + err: + CBB_cleanup(&cbb); + explicit_bzero(padding, sizeof(padding)); + + return ret; } LCRYPTO_ALIAS(RSA_padding_add_PKCS1_type_2); diff --git a/lib/libcrypto/whrlpool/whirlpool.c b/lib/libcrypto/whrlpool/whirlpool.c index 217c5a919..e1e0f7a89 100644 --- a/lib/libcrypto/whrlpool/whirlpool.c +++ b/lib/libcrypto/whrlpool/whirlpool.c @@ -1,4 +1,4 @@ -/* $OpenBSD: whirlpool.c,v 1.1 2024/03/29 02:41:49 jsing Exp $ */ +/* $OpenBSD: whirlpool.c,v 1.2 2024/03/30 03:45:47 joshua Exp $ */ /** * The Whirlpool hashing function. * @@ -650,6 +650,7 @@ WHIRLPOOL_Init(WHIRLPOOL_CTX *c) memset (c, 0, sizeof(*c)); return (1); } +LCRYPTO_ALIAS(WHIRLPOOL_Init); int WHIRLPOOL_Update(WHIRLPOOL_CTX *c, const void *_inp, size_t bytes) @@ -671,6 +672,7 @@ WHIRLPOOL_Update(WHIRLPOOL_CTX *c, const void *_inp, size_t bytes) return (1); } +LCRYPTO_ALIAS(WHIRLPOOL_Update); void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c, const void *_inp, size_t bits) @@ -796,6 +798,7 @@ reconsider: } } } +LCRYPTO_ALIAS(WHIRLPOOL_BitUpdate); int WHIRLPOOL_Final(unsigned char *md, WHIRLPOOL_CTX *c) @@ -837,6 +840,7 @@ WHIRLPOOL_Final(unsigned char *md, WHIRLPOOL_CTX *c) } return (0); } +LCRYPTO_ALIAS(WHIRLPOOL_Final); unsigned char * WHIRLPOOL(const void *inp, size_t bytes, unsigned char *md) @@ -851,3 +855,4 @@ WHIRLPOOL(const void *inp, size_t bytes, unsigned char *md) WHIRLPOOL_Final(md, &ctx); return (md); } +LCRYPTO_ALIAS(WHIRLPOOL); diff --git a/libexec/ld.so/sparc64/rtld_machine.c b/libexec/ld.so/sparc64/rtld_machine.c index 144c04794..2ccaa9687 100644 --- a/libexec/ld.so/sparc64/rtld_machine.c +++ b/libexec/ld.so/sparc64/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.69 2022/01/08 06:49:42 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.70 2024/03/30 08:44:20 miod Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -484,7 +484,6 @@ _dl_reloc_plt(Elf_Word *where1, Elf_Word *where2, Elf_Word *pltaddr, } else if (value < (1L<<42)) { /* * Target 42bits or smaller. - * We can generate this pattern: * * The resulting code in the jump slot is: * @@ -507,7 +506,6 @@ _dl_reloc_plt(Elf_Word *where1, Elf_Word *where2, Elf_Word *pltaddr, } else if (value > -(1UL<<41)) { /* * Large target >= 0xfffffe0000000000UL - * We can generate this pattern: * * The resulting code in the jump slot is: * diff --git a/regress/lib/libcrypto/dsa/Makefile b/regress/lib/libcrypto/dsa/Makefile index f87eb77e8..1215d8109 100644 --- a/regress/lib/libcrypto/dsa/Makefile +++ b/regress/lib/libcrypto/dsa/Makefile @@ -1,15 +1,9 @@ -# $OpenBSD: Makefile,v 1.5 2022/01/14 09:38:50 tb Exp $ +# $OpenBSD: Makefile,v 1.7 2024/03/30 00:34:40 jsing Exp $ -PROG= dsatest -LDADD= -lcrypto -DPADD= ${LIBCRYPTO} +PROG= dsatest +LDADD= -lcrypto +DPADD= ${LIBCRYPTO} WARNINGS= Yes CFLAGS+= -DLIBRESSL_INTERNAL -Werror -REGRESS_TARGETS=regress-dsatest - -regress-dsatest: ${PROG} - ./${PROG} - ./${PROG} -app2_1 - .include diff --git a/regress/lib/libcrypto/free/freenull.c.tail b/regress/lib/libcrypto/free/freenull.c.tail index e83e9e4aa..67bd3b74e 100644 --- a/regress/lib/libcrypto/free/freenull.c.tail +++ b/regress/lib/libcrypto/free/freenull.c.tail @@ -1,11 +1,9 @@ -/* $OpenBSD: freenull.c.tail,v 1.2 2018/07/10 20:55:57 tb Exp $ */ +/* $OpenBSD: freenull.c.tail,v 1.3 2024/03/30 09:41:25 tb Exp $ */ BIO_free_all(NULL); NCONF_free_data(NULL); _CONF_free_data(NULL); - lh_FUNCTION_free(NULL); - sk_ASN1_OBJECT_pop_free(NULL, NULL); sk_CONF_VALUE_pop_free(NULL, NULL); sk_GENERAL_NAME_pop_free(NULL, NULL); diff --git a/regress/lib/libcrypto/rsa/Makefile b/regress/lib/libcrypto/rsa/Makefile index ac8780049..494d40d86 100644 --- a/regress/lib/libcrypto/rsa/Makefile +++ b/regress/lib/libcrypto/rsa/Makefile @@ -1,15 +1,10 @@ -# $OpenBSD: Makefile,v 1.1 2017/01/25 06:44:04 beck Exp $ +# $OpenBSD: Makefile,v 1.4 2024/03/30 00:36:14 jsing Exp $ -PROG= rsa_test -LDADD= -lcrypto -DPADD= ${LIBCRYPTO} +PROGS= rsa_test \ + rsa_padding_test +LDADD= -lcrypto +DPADD= ${LIBCRYPTO} WARNINGS= Yes CFLAGS+= -DLIBRESSL_INTERNAL -Werror -REGRESS_TARGETS=regress-dsatest - -regress-dsatest: ${PROG} - ./${PROG} - ./${PROG} -app2_1 - .include diff --git a/regress/lib/libcrypto/rsa/rsa_padding_test.c b/regress/lib/libcrypto/rsa/rsa_padding_test.c new file mode 100644 index 000000000..1b3a0ba1e --- /dev/null +++ b/regress/lib/libcrypto/rsa/rsa_padding_test.c @@ -0,0 +1,335 @@ +/* $OpenBSD: rsa_padding_test.c,v 1.2 2024/03/30 02:20:39 jsing Exp $ */ +/* + * Copyright (c) 2024 Joel Sing + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +#include +#include + +#if 0 +static void +hexdump(const unsigned char *buf, size_t len) +{ + size_t i; + + for (i = 1; i <= len; i++) + fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 ? "" : "\n"); + + fprintf(stderr, "\n"); +} +#endif + +struct pkcs1_test { + uint8_t in[128]; + size_t in_len; + int want; + int want_error; +}; + +static const struct pkcs1_test pkcs1_type1_tests[] = { + { + .in = { + 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x6f, 0x6f, 0x6f, + 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, + 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, + }, + .in_len = 32, + .want = 19, + }, + { + .in = { + 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x00, + }, + .in_len = 11, + .want = 0, + }, + { + .in = { + 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x00, 0xff, + }, + .in_len = 12, + .want = 1, + }, + { + /* Insufficient padding bytes (< 8). */ + .in = { + 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x00, 0xff, 0xff, + }, + .in_len = 12, + .want = -1, + .want_error = RSA_R_BAD_PAD_BYTE_COUNT, + }, + { + /* Incorrect padding type (0x00). */ + .in = { + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x00, 0xff, + }, + .in_len = 12, + .want = -1, + .want_error = RSA_R_BLOCK_TYPE_IS_NOT_01, + }, + { + /* Incorrect padding type (0x02). */ + .in = { + 0x00, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x00, 0xff, + }, + .in_len = 12, + .want = -1, + .want_error = RSA_R_BLOCK_TYPE_IS_NOT_01, + }, + { + /* Non-padding byte before end of padding marker. */ + .in = { + 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xfe, 0x00, 0xff, + }, + .in_len = 12, + .want = -1, + .want_error = RSA_R_BAD_FIXED_HEADER_DECRYPT, + }, + { + /* No end of padding marker. */ + .in = { + 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + }, + .in_len = 32, + .want = -1, + .want_error = RSA_R_NULL_BEFORE_BLOCK_MISSING, + }, +}; + +#define N_PKCS1_TYPE1_TESTS \ + (sizeof(pkcs1_type1_tests) / sizeof(pkcs1_type1_tests[0])) + +static int +test_pkcs1_type1(void) +{ + const struct pkcs1_test *pt; + uint8_t buf[32], in[19], out[512]; + int pad_len; + long err; + size_t i; + int failed = 1; + + for (i = 0; i < 1000; i++) { + arc4random_buf(in, sizeof(in)); + + if (!RSA_padding_add_PKCS1_type_1(buf, sizeof(buf), in, + sizeof(in))) { + fprintf(stderr, "FAIL: failed to add PKCS1 type 1 " + "padding\n"); + goto failed; + } + + pad_len = RSA_padding_check_PKCS1_type_1(out, sizeof(out) - 1, + buf + 1, sizeof(buf) - 1, sizeof(buf)); + if (pad_len != sizeof(in)) { + fprintf(stderr, "FAIL: failed to check PKCS1 type 1 " + "padding\n"); + ERR_print_errors_fp(stderr); + goto failed; + } + } + + for (i = 0; i < N_PKCS1_TYPE1_TESTS; i++) { + pt = &pkcs1_type1_tests[i]; + + ERR_clear_error(); + + pad_len = RSA_padding_check_PKCS1_type_1(out, sizeof(out) - 1, + pt->in + 1, pt->in_len - 1, pt->in_len); + + if (pad_len != pt->want) { + fprintf(stderr, "FAIL: test %zu - failed to check " + "PKCS1 type 1 padding (%d != %d)\n", i, pad_len, + pt->want); + ERR_print_errors_fp(stderr); + goto failed; + } + + err = ERR_peek_error(); + if (pt->want == -1 && ERR_GET_REASON(err) != pt->want_error) { + fprintf(stderr, "FAIL: test %zu - PKCS1 type 1 padding " + "check failed with error reason %i, want %i\n", + i, ERR_GET_REASON(err), pt->want_error); + ERR_print_errors_fp(stderr); + goto failed; + } + } + + failed = 0; + + failed: + return failed; +} + +static const struct pkcs1_test pkcs1_type2_tests[] = { + { + .in = { + 0x00, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x6f, 0x6f, 0x6f, + 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, + 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, + }, + .in_len = 32, + .want = 19, + }, + { + .in = { + 0x00, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x00, + }, + .in_len = 11, + .want = 0, + }, + { + .in = { + 0x00, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x00, 0xff, + }, + .in_len = 12, + .want = 1, + }, + { + /* Insufficient padding bytes (< 8). */ + .in = { + 0x00, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x00, 0xff, 0xff, + }, + .in_len = 12, + .want = -1, + .want_error = RSA_R_BAD_PAD_BYTE_COUNT, + }, + { + /* Incorrect padding type (0x00). */ + .in = { + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x00, 0xff, + }, + .in_len = 12, + .want = -1, + .want_error = RSA_R_BLOCK_TYPE_IS_NOT_02, + }, + { + /* Incorrect padding type (0x01). */ + .in = { + 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x00, 0xff, + }, + .in_len = 12, + .want = -1, + .want_error = RSA_R_BLOCK_TYPE_IS_NOT_02, + }, + { + /* No end of padding marker. */ + .in = { + 0x00, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0x6f, 0x6f, + 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, + 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, + }, + .in_len = 32, + .want = -1, + .want_error = RSA_R_NULL_BEFORE_BLOCK_MISSING, + }, +}; + +#define N_PKCS1_TYPE2_TESTS \ + (sizeof(pkcs1_type2_tests) / sizeof(pkcs1_type2_tests[0])) + +static int +test_pkcs1_type2(void) +{ + const struct pkcs1_test *pt; + uint8_t buf[32], in[19], out[512]; + int pad_len; + long err; + size_t i; + int failed = 1; + + for (i = 0; i < 1000; i++) { + arc4random_buf(in, sizeof(in)); + + if (!RSA_padding_add_PKCS1_type_2(buf, sizeof(buf), in, + sizeof(in))) { + fprintf(stderr, "FAIL: failed to add PKCS1 type 2 " + "padding\n"); + goto failed; + } + + pad_len = RSA_padding_check_PKCS1_type_2(out, sizeof(out) - 1, + buf + 1, sizeof(buf) - 1, sizeof(buf)); + if (pad_len != sizeof(in)) { + fprintf(stderr, "FAIL: failed to check PKCS1 type 2 " + "padding\n"); + ERR_print_errors_fp(stderr); + goto failed; + } + } + + for (i = 0; i < N_PKCS1_TYPE2_TESTS; i++) { + pt = &pkcs1_type2_tests[i]; + + ERR_clear_error(); + + pad_len = RSA_padding_check_PKCS1_type_2(out, sizeof(out) - 1, + pt->in + 1, pt->in_len - 1, pt->in_len); + + if (pad_len != pt->want) { + fprintf(stderr, "FAIL: test %zu - failed to check " + "PKCS1 type 2 padding (%d != %d)\n", i, pad_len, + pt->want); + ERR_print_errors_fp(stderr); + goto failed; + } + + err = ERR_peek_error(); + if (pt->want == -1 && ERR_GET_REASON(err) != pt->want_error) { + fprintf(stderr, "FAIL: test %zu - PKCS1 type 2 padding " + "check failed with error reason %i, want %i\n", + i, ERR_GET_REASON(err), pt->want_error); + ERR_print_errors_fp(stderr); + goto failed; + } + } + + failed = 0; + + failed: + return failed; +} + +int +main(int argc, char **argv) +{ + int failed = 0; + + failed |= test_pkcs1_type1(); + failed |= test_pkcs1_type2(); + + return failed; +} diff --git a/regress/usr.sbin/btrace/if.bt b/regress/usr.sbin/btrace/if.bt index 053801cac..41f30815b 100644 --- a/regress/usr.sbin/btrace/if.bt +++ b/regress/usr.sbin/btrace/if.bt @@ -9,6 +9,20 @@ BEGIN { if (1) { printf("printed!\n"); } + + if (0) + printf("simple if\n"); + else + printf("simple else\n"); + + if (0) { + printf("disabled if\n"); + } else if (1) { + printf("multiple statements in "); + printf("else-if branch\n"); + } else { + printf("no else\n"); + } } END { @@ -18,4 +32,19 @@ END { printf("(%d) ", @var); printf("statements\n"); } + + if (0) printf("single-line if\n"); else printf("single-line else\n"); + + if (0) { + printf("not printed\n"); + } else { + if (0) { + printf("nested not printed\n"); + } else { + printf("nested printed\n"); + exit(); + printf("nested not printed\n"); + } + printf("also not printed\n"); + } } diff --git a/regress/usr.sbin/btrace/if.ok b/regress/usr.sbin/btrace/if.ok index c2d5a91bc..cfac256da 100644 --- a/regress/usr.sbin/btrace/if.ok +++ b/regress/usr.sbin/btrace/if.ok @@ -1,2 +1,6 @@ printed! +simple else +multiple statements in else-if branch multiple (4) statements +single-line else +nested printed diff --git a/sys/dev/fdt/dwiic_fdt.c b/sys/dev/fdt/dwiic_fdt.c index 5f4de8d44..c934b5ad0 100644 --- a/sys/dev/fdt/dwiic_fdt.c +++ b/sys/dev/fdt/dwiic_fdt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dwiic_fdt.c,v 1.1 2023/08/29 12:09:40 kettenis Exp $ */ +/* $OpenBSD: dwiic_fdt.c,v 1.2 2024/03/29 22:08:09 kettenis Exp $ */ /* * Copyright (c) 2023 Patrick Wildt * @@ -48,6 +48,7 @@ const struct cfattach dwiic_fdt_ca = { sizeof(struct dwiic_fdt_softc), dwiic_fdt_match, dwiic_fdt_attach }; +void dwiic_fdt_calc_timings(struct dwiic_fdt_softc *); void dwiic_fdt_bus_scan(struct device *, struct i2cbus_attach_args *, void *); @@ -66,8 +67,6 @@ dwiic_fdt_attach(struct device *parent, struct device *self, void *aux) struct dwiic_softc *sc = &fsc->sc_sc; struct fdt_attach_args *faa = aux; struct i2cbus_attach_args iba; - uint32_t sda_hold, sda_fall, scl_fall; - uint64_t freq; if (faa->fa_nreg < 1) return; @@ -84,19 +83,7 @@ dwiic_fdt_attach(struct device *parent, struct device *self, void *aux) reset_deassert_all(faa->fa_node); clock_enable(faa->fa_node, NULL); - freq = clock_get_frequency(faa->fa_node, NULL); - sda_hold = OF_getpropint(faa->fa_node, "i2c-sda-hold-time-ns", 300); - sda_fall = OF_getpropint(faa->fa_node, "i2c-sda-falling-time-ns", 300); - scl_fall = OF_getpropint(faa->fa_node, "i2c-scl-falling-time-ns", 300); - - sc->sda_hold_time = round_closest(freq * sda_hold, 1000000000); - - /* Standard-mode: tHIGH = 4.0 us; tLOW = 4.7 us */ - sc->ss_hcnt = round_closest(freq * (4000 + sda_fall), 1000000000) - 3; - sc->ss_lcnt = round_closest(freq * (4700 + scl_fall), 1000000000) - 1; - /* Fast-mode: tHIGH = 0.6 us; tLOW = 1.3 us */ - sc->fs_hcnt = round_closest(freq * (600 + sda_fall), 1000000000) - 3; - sc->fs_lcnt = round_closest(freq * (1300 + scl_fall), 1000000000) - 1; + dwiic_fdt_calc_timings(fsc); if (dwiic_init(sc)) { printf(": can't initialize\n"); @@ -129,6 +116,31 @@ dwiic_fdt_attach(struct device *parent, struct device *self, void *aux) config_found(&sc->sc_dev, &iba, iicbus_print); } +void +dwiic_fdt_calc_timings(struct dwiic_fdt_softc *fsc) +{ + struct dwiic_softc *sc = &fsc->sc_sc; + uint32_t sda_hold, sda_fall, scl_fall; + uint64_t freq; + + freq = clock_get_frequency(fsc->sc_node, NULL); + if (freq == 0) + return; + + sda_hold = OF_getpropint(fsc->sc_node, "i2c-sda-hold-time-ns", 300); + sda_fall = OF_getpropint(fsc->sc_node, "i2c-sda-falling-time-ns", 300); + scl_fall = OF_getpropint(fsc->sc_node, "i2c-scl-falling-time-ns", 300); + + sc->sda_hold_time = round_closest(freq * sda_hold, 1000000000); + + /* Standard-mode: tHIGH = 4.0 us; tLOW = 4.7 us */ + sc->ss_hcnt = round_closest(freq * (4000 + sda_fall), 1000000000) - 3; + sc->ss_lcnt = round_closest(freq * (4700 + scl_fall), 1000000000) - 1; + /* Fast-mode: tHIGH = 0.6 us; tLOW = 1.3 us */ + sc->fs_hcnt = round_closest(freq * (600 + sda_fall), 1000000000) - 3; + sc->fs_lcnt = round_closest(freq * (1300 + scl_fall), 1000000000) - 1; +} + void dwiic_fdt_bus_scan(struct device *self, struct i2cbus_attach_args *iba, void *aux) diff --git a/usr.bin/ssh/PROTOCOL.key b/usr.bin/ssh/PROTOCOL.key index cbf7a7027..feda2529b 100644 --- a/usr.bin/ssh/PROTOCOL.key +++ b/usr.bin/ssh/PROTOCOL.key @@ -40,7 +40,7 @@ of the cipher block size. byte[] privatekey2 string comment2 ... - string privatekeyN + byte[] privatekeyN string commentN byte 1 byte 2 @@ -68,4 +68,4 @@ For unencrypted keys the cipher "none" and the KDF "none" are used with empty passphrases. The options if the KDF "none" are the empty string. -$OpenBSD: PROTOCOL.key,v 1.3 2022/07/01 04:45:50 djm Exp $ +$OpenBSD: PROTOCOL.key,v 1.4 2024/03/30 05:56:22 djm Exp $ diff --git a/usr.bin/ssh/readpass.c b/usr.bin/ssh/readpass.c index d94a21b82..420736e26 100644 --- a/usr.bin/ssh/readpass.c +++ b/usr.bin/ssh/readpass.c @@ -1,4 +1,4 @@ -/* $OpenBSD: readpass.c,v 1.70 2022/05/27 04:27:49 dtucker Exp $ */ +/* $OpenBSD: readpass.c,v 1.71 2024/03/30 04:27:44 djm Exp $ */ /* * Copyright (c) 2001 Markus Friedl. All rights reserved. * @@ -124,8 +124,9 @@ read_passphrase(const char *prompt, int flags) const char *askpass_hint = NULL; const char *s; - if ((s = getenv("DISPLAY")) != NULL) - allow_askpass = *s != '\0'; + if (((s = getenv("DISPLAY")) != NULL && *s != '\0') || + ((s = getenv("WAYLAND_DISPLAY")) != NULL && *s != '\0')) + allow_askpass = 1; if ((s = getenv(SSH_ASKPASS_REQUIRE_ENV)) != NULL) { if (strcasecmp(s, "force") == 0) { use_askpass = 1; @@ -258,7 +259,7 @@ notify_start(int force_askpass, const char *fmt, ...) debug3_f("cannot notify: no askpass"); goto out; } - if (getenv("DISPLAY") == NULL && + if (getenv("DISPLAY") == NULL && getenv("WAYLAND_DISPLAY") == NULL && ((s = getenv(SSH_ASKPASS_REQUIRE_ENV)) == NULL || strcmp(s, "force") != 0)) { debug3_f("cannot notify: no display"); diff --git a/usr.sbin/btrace/bt_parse.y b/usr.sbin/btrace/bt_parse.y index 075eaa5b7..2497ae4ea 100644 --- a/usr.sbin/btrace/bt_parse.y +++ b/usr.sbin/btrace/bt_parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: bt_parse.y,v 1.59 2024/02/12 15:11:06 mpi Exp $ */ +/* $OpenBSD: bt_parse.y,v 1.60 2024/03/30 07:41:45 mpi Exp $ */ /* * Copyright (c) 2019-2023 Martin Pieuchot @@ -119,7 +119,7 @@ static int beflag = 0; /* BEGIN/END parsing context flag */ %token ERROR ENDFILT %token OP_EQ OP_NE OP_LE OP_LT OP_GE OP_GT OP_LAND OP_LOR /* Builtins */ -%token BUILTIN BEGIN END HZ IF STR +%token BUILTIN BEGIN ELSE END HZ IF STR /* Functions and Map operators */ %token F_DELETE F_PRINT %token MFUNC FUNC0 FUNC1 FUNCN OP1 OP2 OP4 MOP0 MOP1 @@ -248,7 +248,9 @@ stmt : ';' NL { $$ = NULL; } | GVAR '=' OP4 '(' expr ',' vargs ')' { $$ = bh_inc($1, $5, $7); } ; -stmtblck: IF '(' expr ')' block { $$ = bt_new($3, $5); } +stmtblck: IF '(' expr ')' block { $$ = bt_new($3, $5, NULL); } + | IF '(' expr ')' block ELSE block { $$ = bt_new($3, $5, $7); } + | IF '(' expr ')' block ELSE stmtblck { $$ = bt_new($3, $5, $7); } ; stmtlist: stmtlist stmtblck { $$ = bs_append($1, $2); } @@ -340,15 +342,22 @@ bc_new(struct bt_arg *term, enum bt_argtype op, struct bt_arg *ba) /* Create a new if/else test */ struct bt_stmt * -bt_new(struct bt_arg *ba, struct bt_stmt *condbs) +bt_new(struct bt_arg *ba, struct bt_stmt *condbs, struct bt_stmt *elsebs) { struct bt_arg *bop; + struct bt_cond *bc; bop = ba_op(B_AT_OP_NE, NULL, ba); - return bs_new(B_AC_TEST, bop, (struct bt_var *)condbs); + bc = calloc(1, sizeof(*bc)); + if (bc == NULL) + err(1, "bt_cond: calloc"); + bc->bc_condbs = condbs; + bc->bc_elsebs = elsebs; + return bs_new(B_AC_TEST, bop, (struct bt_var *)bc); } + /* Create a new probe */ struct bt_probe * bp_new(const char *prov, const char *func, const char *name, int32_t rate) @@ -714,6 +723,7 @@ lookup(char *s) { "count", MOP0, B_AT_MF_COUNT }, { "cpu", BUILTIN, B_AT_BI_CPU }, { "delete", F_DELETE, B_AC_DELETE }, + { "else", ELSE, 0 }, { "exit", FUNC0, B_AC_EXIT }, { "hist", OP1, 0 }, { "hz", HZ, 0 }, diff --git a/usr.sbin/btrace/bt_parser.h b/usr.sbin/btrace/bt_parser.h index 051bd7281..081c0045c 100644 --- a/usr.sbin/btrace/bt_parser.h +++ b/usr.sbin/btrace/bt_parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bt_parser.h,v 1.25 2023/10/12 15:16:44 cheloha Exp $ */ +/* $OpenBSD: bt_parser.h,v 1.26 2024/03/30 07:41:45 mpi Exp $ */ /* * Copyright (c) 2019-2021 Martin Pieuchot @@ -180,6 +180,14 @@ struct bt_arg { #define BA_INITIALIZER(v, t) { { NULL }, (void *)(v), NULL, (t) } +/* + * Represents branches of an if-else statement. + */ +struct bt_cond { + struct bt_stmt *bc_condbs; + struct bt_stmt *bc_elsebs; +}; + /* * Each action associated with a given probe is made of at least one * statement. diff --git a/usr.sbin/btrace/btrace.c b/usr.sbin/btrace/btrace.c index ce32989be..b817d9c92 100644 --- a/usr.sbin/btrace/btrace.c +++ b/usr.sbin/btrace/btrace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: btrace.c,v 1.89 2024/02/27 12:38:12 mpi Exp $ */ +/* $OpenBSD: btrace.c,v 1.90 2024/03/30 07:41:45 mpi Exp $ */ /* * Copyright (c) 2019 - 2023 Martin Pieuchot @@ -460,6 +460,7 @@ static uint64_t rules_action_scan(struct bt_stmt *bs) { struct bt_arg *ba; + struct bt_cond *bc; uint64_t evtflags = 0; while (bs != NULL) { @@ -474,8 +475,9 @@ rules_action_scan(struct bt_stmt *bs) evtflags |= ba2dtflags(ba); break; case B_AC_TEST: - evtflags |= rules_action_scan( - (struct bt_stmt *)bs->bs_var); + bc = (struct bt_cond *)bs->bs_var; + evtflags |= rules_action_scan(bc->bc_condbs); + evtflags |= rules_action_scan(bc->bc_elsebs); break; default: break; @@ -669,18 +671,6 @@ rule_eval(struct bt_rule *r, struct dt_evt *dtev) } SLIST_FOREACH(bs, &r->br_action, bs_next) { - if ((bs->bs_act == B_AC_TEST) && stmt_test(bs, dtev) == true) { - struct bt_stmt *bbs = (struct bt_stmt *)bs->bs_var; - - while (bbs != NULL) { - if (stmt_eval(bbs, dtev)) - return 1; - bbs = SLIST_NEXT(bbs, bs_next); - } - - continue; - } - if (stmt_eval(bs, dtev)) return 1; } @@ -830,6 +820,8 @@ builtin_arg(struct dt_evt *dtev, enum bt_argtype dat) int stmt_eval(struct bt_stmt *bs, struct dt_evt *dtev) { + struct bt_stmt *bbs; + struct bt_cond *bc; int halt = 0; switch (bs->bs_act) { @@ -858,7 +850,17 @@ stmt_eval(struct bt_stmt *bs, struct dt_evt *dtev) stmt_store(bs, dtev); break; case B_AC_TEST: - /* done before */ + bc = (struct bt_cond *)bs->bs_var; + if (stmt_test(bs, dtev) == true) + bbs = bc->bc_condbs; + else + bbs = bc->bc_elsebs; + + while (bbs != NULL) { + if (stmt_eval(bbs, dtev)) + return 1; + bbs = SLIST_NEXT(bbs, bs_next); + } break; case B_AC_TIME: stmt_time(bs, dtev);