[git commit] libbb/yescrypt: remove unused yescrypt_shared_t

Denys Vlasenko vda.linux at googlemail.com
Sat Jul 5 23:03:49 UTC 2025


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

function                                             old     new   delta
static.smix                                            -     755    +755
static.smix1                                           -     631    +631
static.smix2                                           -     452    +452
yescrypt_free_local                                    9      49     +40
yes_crypt                                             90      87      -3
yescrypt_r                                           890     879     -11
yescrypt_kdf                                         479     449     -30
free_region                                           47       -     -47
yescrypt_kdf_body                                   1724    1467    -257
smix2                                                659       -    -659
smix                                                 790       -    -790
smix1                                                960       -    -960
------------------------------------------------------------------------------
(add/remove: 3/4 grow/shrink: 1/4 up/down: 1878/-2757)       Total: -879 bytes

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

diff --git a/libbb/yescrypt/alg-yescrypt-common.c b/libbb/yescrypt/alg-yescrypt-common.c
index 7c519b01d..9d7231f09 100644
--- a/libbb/yescrypt/alg-yescrypt-common.c
+++ b/libbb/yescrypt/alg-yescrypt-common.c
@@ -185,7 +185,6 @@ fail:
 }
 
 uint8_t *yescrypt_r(
-		const yescrypt_shared_t *shared,
 		yescrypt_local_t *local,
 		const uint8_t *passwd, size_t passwdlen,
 		const uint8_t *setting,
@@ -309,7 +308,7 @@ uint8_t *yescrypt_r(
 	if (need > buflen || need < saltstrlen)
 		goto fail;
 
-	if (yescrypt_kdf(shared, local, passwd, passwdlen, salt, saltlen,
+	if (yescrypt_kdf(local, passwd, passwdlen, salt, saltlen,
 	    &params, hashbin, sizeof(hashbin)))
 		goto fail;
 
@@ -333,11 +332,6 @@ fail:
 	return NULL;
 }
 
-int yescrypt_free_shared(yescrypt_shared_t *shared)
-{
-	return free_region(shared);
-}
-
 int yescrypt_init_local(yescrypt_local_t *local)
 {
 	init_region(local);
diff --git a/libbb/yescrypt/alg-yescrypt-kdf.c b/libbb/yescrypt/alg-yescrypt-kdf.c
index 3e98ffb0a..da23c1b59 100644
--- a/libbb/yescrypt/alg-yescrypt-kdf.c
+++ b/libbb/yescrypt/alg-yescrypt-kdf.c
@@ -800,7 +800,7 @@ static void smix(uint8_t *B, size_t r, uint32_t N, uint32_t p, uint32_t t,
  * This optimized implementation currently limits N to the range from 4 to
  * 2^31, but other implementations might not.
  */
-static int yescrypt_kdf_body(const yescrypt_shared_t *shared,
+static int yescrypt_kdf_body(
     yescrypt_local_t *local,
     const uint8_t *passwd, size_t passwdlen,
     const uint8_t *salt, size_t saltlen,
@@ -865,23 +865,8 @@ static int yescrypt_kdf_body(const yescrypt_shared_t *shared,
 	}
 
 	VROM = NULL;
-	if (shared) {
-		uint64_t expected_size = (size_t)128 * r * NROM;
-		if ((NROM & (NROM - 1)) != 0 ||
-		    NROM <= 1 || NROM > UINT32_MAX ||
-		    shared->aligned_size < expected_size)
-			goto out_EINVAL;
-		if (!(flags & YESCRYPT_INIT_SHARED)) {
-			uint64_t *tag = (uint64_t *)
-			    ((uint8_t *)shared->aligned + expected_size - 48);
-			if (tag[0] != YESCRYPT_ROM_TAG1 || tag[1] != YESCRYPT_ROM_TAG2)
-				goto out_EINVAL;
-		}
-		VROM = shared->aligned;
-	} else {
-		if (NROM)
-			goto out_EINVAL;
-	}
+	if (NROM)
+		goto out_EINVAL;
 
 	/* Allocate memory */
 	V = NULL;
@@ -1013,7 +998,7 @@ out_EINVAL:
  * to this function are the same as those for yescrypt_kdf_body() above, with
  * the addition of g, which controls hash upgrades (0 for no upgrades so far).
  */
-int yescrypt_kdf(const yescrypt_shared_t *shared,
+int yescrypt_kdf(
 		yescrypt_local_t *local,
 		const uint8_t *passwd, size_t passwdlen,
 		const uint8_t *salt, size_t saltlen,
@@ -1041,7 +1026,7 @@ int yescrypt_kdf(const yescrypt_shared_t *shared,
 	 && N / p >= 0x100
 	 && N / p * r >= 0x20000
 	) {
-		if (yescrypt_kdf_body(shared, local,
+		if (yescrypt_kdf_body(local,
 		    passwd, passwdlen, salt, saltlen,
 		    flags | YESCRYPT_ALLOC_ONLY, N, r, p, t, NROM,
 		    buf, buflen) != -3
@@ -1049,7 +1034,7 @@ int yescrypt_kdf(const yescrypt_shared_t *shared,
 			errno = EINVAL;
 			return -1;
 		}
-		retval = yescrypt_kdf_body(shared, local,
+		retval = yescrypt_kdf_body(local,
 				passwd, passwdlen, salt, saltlen,
 				flags | YESCRYPT_PREHASH, N >> 6, r, p, 0, NROM,
 				dk, sizeof(dk));
@@ -1059,7 +1044,7 @@ int yescrypt_kdf(const yescrypt_shared_t *shared,
 		passwdlen = sizeof(dk);
 	}
 
-	retval = yescrypt_kdf_body(shared, local,
+	retval = yescrypt_kdf_body(local,
 			passwd, passwdlen, salt, saltlen,
 			flags, N, r, p, t, NROM, buf, buflen);
 #ifndef SKIP_MEMZERO
diff --git a/libbb/yescrypt/alg-yescrypt.h b/libbb/yescrypt/alg-yescrypt.h
index 9755ac420..09638e3e1 100644
--- a/libbb/yescrypt/alg-yescrypt.h
+++ b/libbb/yescrypt/alg-yescrypt.h
@@ -41,7 +41,6 @@ typedef struct {
 /**
  * Types for shared (ROM) and thread-local (RAM) data structures.
  */
-typedef yescrypt_region_t yescrypt_shared_t;
 typedef yescrypt_region_t yescrypt_local_t;
 
 /**
@@ -80,8 +79,6 @@ typedef uint32_t yescrypt_flags_t;
 #define YESCRYPT_SBOX_192K		0x280
 #define YESCRYPT_SBOX_384K		0x300
 #define YESCRYPT_SBOX_768K		0x380
-/* Only valid for yescrypt_init_shared() */
-#define YESCRYPT_SHARED_PREALLOCATED	0x10000
 #ifdef YESCRYPT_INTERNAL
 /* Private */
 #define YESCRYPT_MODE_MASK		0x003
@@ -101,7 +98,6 @@ typedef uint32_t yescrypt_flags_t;
 #ifdef YESCRYPT_INTERNAL
 #define YESCRYPT_KNOWN_FLAGS \
 	(YESCRYPT_MODE_MASK | YESCRYPT_RW_FLAVOR_MASK | \
-	YESCRYPT_SHARED_PREALLOCATED | \
 	YESCRYPT_INIT_SHARED | YESCRYPT_ALLOC_ONLY | YESCRYPT_PREHASH)
 #endif
 
@@ -139,47 +135,6 @@ typedef union {
 #define HASH_SIZE sizeof(yescrypt_binary_t) /* bytes */
 #define HASH_LEN  BYTES2CHARS(HASH_SIZE)
 
-
-/**
- * yescrypt_init_shared(shared, seed, seedlen, params):
- * Optionally allocate memory for and initialize the shared (ROM) data
- * structure.  The parameters flags, NROM, r, p, and t specify how the ROM is
- * to be initialized, and seed and seedlen specify the initial seed affecting
- * the data with which the ROM is filled.
- *
- * Return 0 on success; or -1 on error.
- *
- * If bit YESCRYPT_SHARED_PREALLOCATED in flags is set, then memory for the
- * ROM is assumed to have been preallocated by the caller, with shared->aligned
- * being the start address of the ROM and shared->aligned_size being its size
- * (which must be sufficient for NROM, r, p).  This may be used e.g. when the
- * ROM is to be placed in a SysV shared memory segment allocated by the caller.
- *
- * MT-safe as long as shared is local to the thread.
- */
-extern int yescrypt_init_shared(yescrypt_shared_t *shared,
-    const uint8_t *seed, size_t seedlen, const yescrypt_params_t *params);
-
-/**
- * yescrypt_digest_shared(shared):
- * Extract the previously stored message digest of the provided yescrypt ROM.
- *
- * Return pointer to the message digest on success; or NULL on error.
- *
- * MT-unsafe.
- */
-extern yescrypt_binary_t *yescrypt_digest_shared(yescrypt_shared_t *shared);
-
-/**
- * yescrypt_free_shared(shared):
- * Free memory that had been allocated with yescrypt_init_shared().
- *
- * Return 0 on success; or -1 on error.
- *
- * MT-safe as long as shared is local to the thread.
- */
-extern int yescrypt_free_shared(yescrypt_shared_t *shared);
-
 /**
  * yescrypt_init_local(local):
  * Initialize the thread-local (RAM) data structure.  Actual memory allocation
@@ -239,7 +194,7 @@ extern int yescrypt_free_local(yescrypt_local_t *local);
  *
  * MT-safe as long as local and buf are local to the thread.
  */
-extern int yescrypt_kdf(const yescrypt_shared_t *shared,
+extern int yescrypt_kdf(
     yescrypt_local_t *local,
     const uint8_t *passwd, size_t passwdlen,
     const uint8_t *salt, size_t saltlen,
@@ -261,11 +216,10 @@ extern int yescrypt_kdf(const yescrypt_shared_t *shared,
  *
  * MT-safe as long as local and buf are local to the thread.
  */
-extern uint8_t *yescrypt_r(const yescrypt_shared_t *shared,
+extern uint8_t *yescrypt_r(
     yescrypt_local_t *local,
     const uint8_t *passwd, size_t passwdlen,
     const uint8_t *setting,
-    //KEY: const yescrypt_binary_t *key,
     uint8_t *buf, size_t buflen);
 
 extern const uint8_t *decode64(uint8_t *dst, size_t *dstlen,


More information about the busybox-cvs mailing list