[git commit] libbb/yescrypt: code shrink

Denys Vlasenko vda.linux at googlemail.com
Fri Jul 11 06:58:07 UTC 2025


commit: https://git.busybox.net/busybox/commit/?id=e62bfbcaed051146b83a096e778b5822069c160b
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
salsa20                                              684     650     -34
blockmix_salsa8                                      198     144     -54
blockmix                                             762     565    -197
blockmix_xor                                        1322    1028    -294
blockmix_xor_save                                   1499    1103    -396
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-975)           Total: -975 bytes

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 libbb/yescrypt/alg-yescrypt-kdf.c | 9 +++------
 libbb/yescrypt/alg-yescrypt.h     | 8 ++++----
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/libbb/yescrypt/alg-yescrypt-kdf.c b/libbb/yescrypt/alg-yescrypt-kdf.c
index 29d9efc07..1c254e2e2 100644
--- a/libbb/yescrypt/alg-yescrypt-kdf.c
+++ b/libbb/yescrypt/alg-yescrypt-kdf.c
@@ -106,8 +106,7 @@ do { \
 #else
 #define COPY(out, in) \
 do { \
-	for (int copyi=0; copyi<8; copyi++) \
-		(out).d[copyi] = (in).d[copyi]; \
+	memcpy((out).d, (in).d, sizeof((in).d)); \
 } while (0)
 #endif
 
@@ -161,11 +160,9 @@ static void salsa20(salsa20_blk_t *restrict B,
 	{
 		uint32_t i;
 		salsa20_simd_shuffle(&X, Bout);
-		for (i = 0; i < 16; i += 4) {
+		for (i = 0; i < 16; i++) {
+			// bbox: note: was unrolled x4
 			B->w[i] = Bout->w[i] += B->w[i];
-			B->w[i + 1] = Bout->w[i + 1] += B->w[i + 1];
-			B->w[i + 2] = Bout->w[i + 2] += B->w[i + 2];
-			B->w[i + 3] = Bout->w[i + 3] += B->w[i + 3];
 		}
 	}
 #if 0
diff --git a/libbb/yescrypt/alg-yescrypt.h b/libbb/yescrypt/alg-yescrypt.h
index 2a9434809..0b93945af 100644
--- a/libbb/yescrypt/alg-yescrypt.h
+++ b/libbb/yescrypt/alg-yescrypt.h
@@ -107,14 +107,14 @@
 #define YCTX_param_NROM  0
 #endif
 
-// "Faster, or smaller code" knobs:
-// Not a size win if disabled, so keeping it 1:
-#define KDF_UNROLL_COPY 1
+// "Faster/smaller code" knobs:
+// -941 bytes:
+#define KDF_UNROLL_COPY 0
 // -5324 bytes if 0:
 #define KDF_UNROLL_PWXFORM_ROUND 0
 // -4864 bytes if 0:
 #define KDF_UNROLL_PWXFORM 0
-// both 0: -7666 bytes
+// if both this ^^^^^^^^^^ and PWXFORM_ROUND set to 0: -7666 bytes
 
 /**
  * Type and possible values for the flags argument of yescrypt_kdf(),


More information about the busybox-cvs mailing list