From ca5eb817689340c9e11f21f75b2eede73622ad2e Mon Sep 17 00:00:00 2001 From: jsing <> Date: Mon, 27 Jan 2025 14:02:32 +0000 Subject: Mop up RC4_INDEX. The RC4_INDEX define switches between base pointer indexing and per-byte pointer increment. This supposedly made a huge difference to performance on x86 at some point, however compilers have improved somewhat since then. There is no change (or effectively no change) in generated assembly on a the majority of LLVM platforms and even when there is some change (e.g. aarch64), there is no noticable performance difference. Simplify the (still messy) macros/code and mop up RC4_INDEX. ok tb@ --- src/lib/libcrypto/arch/aarch64/opensslconf.h | 7 ---- src/lib/libcrypto/arch/alpha/opensslconf.h | 7 ---- src/lib/libcrypto/arch/amd64/opensslconf.h | 7 ---- src/lib/libcrypto/arch/arm/opensslconf.h | 7 ---- src/lib/libcrypto/arch/hppa/opensslconf.h | 7 ---- src/lib/libcrypto/arch/i386/opensslconf.h | 7 ---- src/lib/libcrypto/arch/m88k/opensslconf.h | 7 ---- src/lib/libcrypto/arch/mips64/opensslconf.h | 7 ---- src/lib/libcrypto/arch/powerpc/opensslconf.h | 7 ---- src/lib/libcrypto/arch/powerpc64/opensslconf.h | 7 ---- src/lib/libcrypto/arch/riscv64/opensslconf.h | 7 ---- src/lib/libcrypto/arch/sh/opensslconf.h | 7 ---- src/lib/libcrypto/arch/sparc64/opensslconf.h | 7 ---- src/lib/libcrypto/rc4/rc4.c | 44 +++++++++++--------------- 14 files changed, 19 insertions(+), 116 deletions(-) diff --git a/src/lib/libcrypto/arch/aarch64/opensslconf.h b/src/lib/libcrypto/arch/aarch64/opensslconf.h index fed209a008..e6e294a962 100644 --- a/src/lib/libcrypto/arch/aarch64/opensslconf.h +++ b/src/lib/libcrypto/arch/aarch64/opensslconf.h @@ -65,13 +65,6 @@ #undef EIGHT_BIT #endif -#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) -#define CONFIG_HEADER_RC4_LOCL_H -/* if this is defined data[i] is used instead of *data, this is a %20 - * speedup on x86 */ -#undef RC4_INDEX -#endif - #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) #define CONFIG_HEADER_BF_LOCL_H #undef BF_PTR diff --git a/src/lib/libcrypto/arch/alpha/opensslconf.h b/src/lib/libcrypto/arch/alpha/opensslconf.h index 1dbd8f22fa..1c033369ea 100644 --- a/src/lib/libcrypto/arch/alpha/opensslconf.h +++ b/src/lib/libcrypto/arch/alpha/opensslconf.h @@ -63,13 +63,6 @@ #undef THIRTY_TWO_BIT #endif -#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) -#define CONFIG_HEADER_RC4_LOCL_H -/* if this is defined data[i] is used instead of *data, this is a %20 - * speedup on x86 */ -#undef RC4_INDEX -#endif - #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) #define CONFIG_HEADER_BF_LOCL_H #define BF_PTR diff --git a/src/lib/libcrypto/arch/amd64/opensslconf.h b/src/lib/libcrypto/arch/amd64/opensslconf.h index 7615744a6b..4187a44c86 100644 --- a/src/lib/libcrypto/arch/amd64/opensslconf.h +++ b/src/lib/libcrypto/arch/amd64/opensslconf.h @@ -60,13 +60,6 @@ #undef THIRTY_TWO_BIT #endif -#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) -#define CONFIG_HEADER_RC4_LOCL_H -/* if this is defined data[i] is used instead of *data, this is a %20 - * speedup on x86 */ -#undef RC4_INDEX -#endif - #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) #define CONFIG_HEADER_BF_LOCL_H #undef BF_PTR diff --git a/src/lib/libcrypto/arch/arm/opensslconf.h b/src/lib/libcrypto/arch/arm/opensslconf.h index 3413abb672..98dcfee3a1 100644 --- a/src/lib/libcrypto/arch/arm/opensslconf.h +++ b/src/lib/libcrypto/arch/arm/opensslconf.h @@ -65,13 +65,6 @@ #undef EIGHT_BIT #endif -#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) -#define CONFIG_HEADER_RC4_LOCL_H -/* if this is defined data[i] is used instead of *data, this is a %20 - * speedup on x86 */ -#define RC4_INDEX -#endif - #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) #define CONFIG_HEADER_BF_LOCL_H #undef BF_PTR diff --git a/src/lib/libcrypto/arch/hppa/opensslconf.h b/src/lib/libcrypto/arch/hppa/opensslconf.h index 3413abb672..98dcfee3a1 100644 --- a/src/lib/libcrypto/arch/hppa/opensslconf.h +++ b/src/lib/libcrypto/arch/hppa/opensslconf.h @@ -65,13 +65,6 @@ #undef EIGHT_BIT #endif -#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) -#define CONFIG_HEADER_RC4_LOCL_H -/* if this is defined data[i] is used instead of *data, this is a %20 - * speedup on x86 */ -#define RC4_INDEX -#endif - #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) #define CONFIG_HEADER_BF_LOCL_H #undef BF_PTR diff --git a/src/lib/libcrypto/arch/i386/opensslconf.h b/src/lib/libcrypto/arch/i386/opensslconf.h index ac1ea99cc9..1ea367102b 100644 --- a/src/lib/libcrypto/arch/i386/opensslconf.h +++ b/src/lib/libcrypto/arch/i386/opensslconf.h @@ -65,13 +65,6 @@ #undef EIGHT_BIT #endif -#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) -#define CONFIG_HEADER_RC4_LOCL_H -/* if this is defined data[i] is used instead of *data, this is a %20 - * speedup on x86 */ -#define RC4_INDEX -#endif - #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) #define CONFIG_HEADER_BF_LOCL_H #undef BF_PTR diff --git a/src/lib/libcrypto/arch/m88k/opensslconf.h b/src/lib/libcrypto/arch/m88k/opensslconf.h index 3413abb672..98dcfee3a1 100644 --- a/src/lib/libcrypto/arch/m88k/opensslconf.h +++ b/src/lib/libcrypto/arch/m88k/opensslconf.h @@ -65,13 +65,6 @@ #undef EIGHT_BIT #endif -#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) -#define CONFIG_HEADER_RC4_LOCL_H -/* if this is defined data[i] is used instead of *data, this is a %20 - * speedup on x86 */ -#define RC4_INDEX -#endif - #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) #define CONFIG_HEADER_BF_LOCL_H #undef BF_PTR diff --git a/src/lib/libcrypto/arch/mips64/opensslconf.h b/src/lib/libcrypto/arch/mips64/opensslconf.h index e5b1b51ec5..ec35dc9946 100644 --- a/src/lib/libcrypto/arch/mips64/opensslconf.h +++ b/src/lib/libcrypto/arch/mips64/opensslconf.h @@ -65,13 +65,6 @@ #undef EIGHT_BIT #endif -#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) -#define CONFIG_HEADER_RC4_LOCL_H -/* if this is defined data[i] is used instead of *data, this is a %20 - * speedup on x86 */ -#undef RC4_INDEX -#endif - #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) #define CONFIG_HEADER_BF_LOCL_H #define BF_PTR diff --git a/src/lib/libcrypto/arch/powerpc/opensslconf.h b/src/lib/libcrypto/arch/powerpc/opensslconf.h index 3413abb672..98dcfee3a1 100644 --- a/src/lib/libcrypto/arch/powerpc/opensslconf.h +++ b/src/lib/libcrypto/arch/powerpc/opensslconf.h @@ -65,13 +65,6 @@ #undef EIGHT_BIT #endif -#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) -#define CONFIG_HEADER_RC4_LOCL_H -/* if this is defined data[i] is used instead of *data, this is a %20 - * speedup on x86 */ -#define RC4_INDEX -#endif - #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) #define CONFIG_HEADER_BF_LOCL_H #undef BF_PTR diff --git a/src/lib/libcrypto/arch/powerpc64/opensslconf.h b/src/lib/libcrypto/arch/powerpc64/opensslconf.h index 7615744a6b..4187a44c86 100644 --- a/src/lib/libcrypto/arch/powerpc64/opensslconf.h +++ b/src/lib/libcrypto/arch/powerpc64/opensslconf.h @@ -60,13 +60,6 @@ #undef THIRTY_TWO_BIT #endif -#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) -#define CONFIG_HEADER_RC4_LOCL_H -/* if this is defined data[i] is used instead of *data, this is a %20 - * speedup on x86 */ -#undef RC4_INDEX -#endif - #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) #define CONFIG_HEADER_BF_LOCL_H #undef BF_PTR diff --git a/src/lib/libcrypto/arch/riscv64/opensslconf.h b/src/lib/libcrypto/arch/riscv64/opensslconf.h index fed209a008..e6e294a962 100644 --- a/src/lib/libcrypto/arch/riscv64/opensslconf.h +++ b/src/lib/libcrypto/arch/riscv64/opensslconf.h @@ -65,13 +65,6 @@ #undef EIGHT_BIT #endif -#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) -#define CONFIG_HEADER_RC4_LOCL_H -/* if this is defined data[i] is used instead of *data, this is a %20 - * speedup on x86 */ -#undef RC4_INDEX -#endif - #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) #define CONFIG_HEADER_BF_LOCL_H #undef BF_PTR diff --git a/src/lib/libcrypto/arch/sh/opensslconf.h b/src/lib/libcrypto/arch/sh/opensslconf.h index 3413abb672..98dcfee3a1 100644 --- a/src/lib/libcrypto/arch/sh/opensslconf.h +++ b/src/lib/libcrypto/arch/sh/opensslconf.h @@ -65,13 +65,6 @@ #undef EIGHT_BIT #endif -#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) -#define CONFIG_HEADER_RC4_LOCL_H -/* if this is defined data[i] is used instead of *data, this is a %20 - * speedup on x86 */ -#define RC4_INDEX -#endif - #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) #define CONFIG_HEADER_BF_LOCL_H #undef BF_PTR diff --git a/src/lib/libcrypto/arch/sparc64/opensslconf.h b/src/lib/libcrypto/arch/sparc64/opensslconf.h index e5b1b51ec5..ec35dc9946 100644 --- a/src/lib/libcrypto/arch/sparc64/opensslconf.h +++ b/src/lib/libcrypto/arch/sparc64/opensslconf.h @@ -65,13 +65,6 @@ #undef EIGHT_BIT #endif -#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) -#define CONFIG_HEADER_RC4_LOCL_H -/* if this is defined data[i] is used instead of *data, this is a %20 - * speedup on x86 */ -#undef RC4_INDEX -#endif - #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) #define CONFIG_HEADER_BF_LOCL_H #define BF_PTR diff --git a/src/lib/libcrypto/rc4/rc4.c b/src/lib/libcrypto/rc4/rc4.c index 930d0d9bb3..56ed43cba7 100644 --- a/src/lib/libcrypto/rc4/rc4.c +++ b/src/lib/libcrypto/rc4/rc4.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rc4.c,v 1.12 2024/08/11 13:02:39 jsing Exp $ */ +/* $OpenBSD: rc4.c,v 1.13 2025/01/27 14:02:32 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -196,7 +196,7 @@ rc4_internal(RC4_KEY *key, size_t len, const unsigned char *indata, #endif } #endif -#define LOOP(in,out) \ +#define RC4_LOOP(in,out) \ x=((x+1)&0xff); \ tx=d[x]; \ y=(tx+y)&0xff; \ @@ -204,27 +204,21 @@ rc4_internal(RC4_KEY *key, size_t len, const unsigned char *indata, d[y]=tx; \ (out) = d[(tx+ty)&0xff]^ (in); -#ifndef RC4_INDEX -#define RC4_LOOP(a,b,i) LOOP(*((a)++),*((b)++)) -#else -#define RC4_LOOP(a,b,i) LOOP(a[i],b[i]) -#endif - i = len >> 3; if (i) { for (;;) { - RC4_LOOP(indata, outdata, 0); - RC4_LOOP(indata, outdata, 1); - RC4_LOOP(indata, outdata, 2); - RC4_LOOP(indata, outdata, 3); - RC4_LOOP(indata, outdata, 4); - RC4_LOOP(indata, outdata, 5); - RC4_LOOP(indata, outdata, 6); - RC4_LOOP(indata, outdata, 7); -#ifdef RC4_INDEX + RC4_LOOP(indata[0], outdata[0]); + RC4_LOOP(indata[1], outdata[1]); + RC4_LOOP(indata[2], outdata[2]); + RC4_LOOP(indata[3], outdata[3]); + RC4_LOOP(indata[4], outdata[4]); + RC4_LOOP(indata[5], outdata[5]); + RC4_LOOP(indata[6], outdata[6]); + RC4_LOOP(indata[7], outdata[7]); + indata += 8; outdata += 8; -#endif + if (--i == 0) break; } @@ -232,25 +226,25 @@ rc4_internal(RC4_KEY *key, size_t len, const unsigned char *indata, i = len&0x07; if (i) { for (;;) { - RC4_LOOP(indata, outdata, 0); + RC4_LOOP(indata[0], outdata[0]); if (--i == 0) break; - RC4_LOOP(indata, outdata, 1); + RC4_LOOP(indata[1], outdata[1]); if (--i == 0) break; - RC4_LOOP(indata, outdata, 2); + RC4_LOOP(indata[2], outdata[2]); if (--i == 0) break; - RC4_LOOP(indata, outdata, 3); + RC4_LOOP(indata[3], outdata[3]); if (--i == 0) break; - RC4_LOOP(indata, outdata, 4); + RC4_LOOP(indata[4], outdata[4]); if (--i == 0) break; - RC4_LOOP(indata, outdata, 5); + RC4_LOOP(indata[5], outdata[5]); if (--i == 0) break; - RC4_LOOP(indata, outdata, 6); + RC4_LOOP(indata[6], outdata[6]); if (--i == 0) break; } -- cgit v1.2.3-55-g6feb