[git commit] libbb/yescrypt: remove one NOINLINE, add copyright headers, merge two source files
Denys Vlasenko
vda.linux at googlemail.com
Sun Jul 6 18:59:00 UTC 2025
commit: https://git.busybox.net/busybox/commit/?id=f3a1b7be72a2f2699ba25ecdb2c93b90e109f725
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
function old new delta
pw_encrypt 945 974 +29
yes_crypt 50 - -50
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 29/-50) Total: -21 bytes
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
libbb/yescrypt/alg-yescrypt-common.c | 2 +-
libbb/yescrypt/alg-yescrypt-kdf.c | 27 ++++++++++++++++++
libbb/yescrypt/alg-yescrypt-platform.c | 45 ------------------------------
libbb/yescrypt/alg-yescrypt.h | 51 ++++------------------------------
libbb/yescrypt/y.c | 10 +++++--
5 files changed, 41 insertions(+), 94 deletions(-)
diff --git a/libbb/yescrypt/alg-yescrypt-common.c b/libbb/yescrypt/alg-yescrypt-common.c
index b9a5c51ac..435eaecca 100644
--- a/libbb/yescrypt/alg-yescrypt-common.c
+++ b/libbb/yescrypt/alg-yescrypt-common.c
@@ -258,7 +258,7 @@ uint8_t *yescrypt_r(
if (saltend != saltstr + saltstrlen)
goto fail; /* salt[] is too small, or bad char during decode */
- need = prefixlen + 1 + HASH_LEN + 1;
+ need = prefixlen + 1 + YESCRYPT_HASH_LEN + 1;
if (need > buflen || need < prefixlen)
goto fail;
diff --git a/libbb/yescrypt/alg-yescrypt-kdf.c b/libbb/yescrypt/alg-yescrypt-kdf.c
index 781e1f0bb..27ef2caa4 100644
--- a/libbb/yescrypt/alg-yescrypt-kdf.c
+++ b/libbb/yescrypt/alg-yescrypt-kdf.c
@@ -759,6 +759,33 @@ static void smix(uint8_t *B, size_t r, uint32_t N, uint32_t p, uint32_t t,
}
}
+/* Allocator code */
+
+static void alloc_region(yescrypt_region_t *region, size_t size)
+{
+ int flags =
+# ifdef MAP_NOCORE /* huh? */
+ MAP_NOCORE |
+# endif
+ MAP_ANON | MAP_PRIVATE;
+ uint8_t *base = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0);
+ if (base == MAP_FAILED)
+ bb_die_memory_exhausted();
+ //region->base = base;
+ //region->base_size = size;
+ region->aligned = base;
+ region->aligned_size = size;
+}
+
+static void free_region(yescrypt_region_t *region)
+{
+ if (region->aligned)
+ munmap(region->aligned, region->aligned_size);
+ //region->base = NULL;
+ //region->base_size = 0;
+ region->aligned = NULL;
+ region->aligned_size = 0;
+}
/**
* yescrypt_kdf_body(shared, local, passwd, passwdlen, salt, saltlen,
* flags, N, r, p, t, NROM, buf, buflen):
diff --git a/libbb/yescrypt/alg-yescrypt-platform.c b/libbb/yescrypt/alg-yescrypt-platform.c
deleted file mode 100644
index 8dd5feb55..000000000
--- a/libbb/yescrypt/alg-yescrypt-platform.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*-
- * Copyright 2013-2018,2022 Alexander Peslyak
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS 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 AUTHOR OR 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.
- */
-
-static void alloc_region(yescrypt_region_t *region, size_t size)
-{
- int flags =
-# ifdef MAP_NOCORE /* huh? */
- MAP_NOCORE |
-# endif
- MAP_ANON | MAP_PRIVATE;
- uint8_t *base = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0);
- if (base == MAP_FAILED)
- bb_die_memory_exhausted();
- //region->base = base;
- //region->base_size = size;
- region->aligned = base;
- region->aligned_size = size;
-}
-
-static void free_region(yescrypt_region_t *region)
-{
- if (region->aligned)
- munmap(region->aligned, region->aligned_size);
- //region->base = NULL;
- //region->base_size = 0;
- region->aligned = NULL;
- region->aligned_size = 0;
-}
diff --git a/libbb/yescrypt/alg-yescrypt.h b/libbb/yescrypt/alg-yescrypt.h
index edabbc222..5b442c2c9 100644
--- a/libbb/yescrypt/alg-yescrypt.h
+++ b/libbb/yescrypt/alg-yescrypt.h
@@ -64,6 +64,7 @@ typedef uint32_t yescrypt_flags_t;
#define YESCRYPT_SBOX_192K 0x280
#define YESCRYPT_SBOX_384K 0x300
#define YESCRYPT_SBOX_768K 0x380
+
#ifdef YESCRYPT_INTERNAL
/* Private */
#define YESCRYPT_MODE_MASK 0x003
@@ -123,59 +124,17 @@ typedef struct {
} yescrypt_ctx_t;
/* How many chars base-64 encoded bytes require? */
-#define BYTES2CHARS(bytes) ((((bytes) * 8) + 5) / 6)
+#define YESCRYPT_BYTES2CHARS(bytes) ((((bytes) * 8) + 5) / 6)
/* The /etc/passwd-style hash is "<prefix>$<hash><NUL>" */
/*
* "$y$", up to 8 params of up to 6 chars each, '$', salt
* Alternatively, but that's smaller:
* "$7$", 3 params encoded as 1+5+5 chars, salt
*/
-#define PREFIX_LEN (3 + 8 * 6 + 1 + BYTES2CHARS(32))
-
-#define HASH_SIZE 32
-#define HASH_LEN BYTES2CHARS(HASH_SIZE)
+#define YESCRYPT_PREFIX_LEN (3 + 8 * 6 + 1 + YESCRYPT_BYTES2CHARS(32))
-/**
- * yescrypt_kdf(shared, local, passwd, passwdlen, salt, saltlen, params,
- * buf, buflen):
- * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r,
- * p, buflen), or a revision of scrypt as requested by flags and shared, and
- * write the result into buf. The parameters N, r, p, and buflen must satisfy
- * the same conditions as with crypto_scrypt(). t controls computation time
- * while not affecting peak memory usage (t = 0 is optimal unless higher N*r
- * is not affordable while higher t is). g controls hash upgrades (g = 0 for
- * no upgrades so far). shared and flags may request special modes. local is
- * the thread-local data structure, allowing to preserve and reuse a memory
- * allocation across calls, thereby reducing processing overhead.
- *
- * Return 0 on success; or -1 on error.
- *
- * Classic scrypt is available by setting shared = NULL, flags = 0, and t = 0.
- *
- * Setting YESCRYPT_WORM enables only minimal deviations from classic scrypt:
- * support for the t parameter, and pre- and post-hashing.
- *
- * Setting YESCRYPT_RW fully enables yescrypt. As a side effect of differences
- * between the algorithms, it also prevents p > 1 from growing the threads'
- * combined processing time and memory allocation (like it did with classic
- * scrypt and YESCRYPT_WORM), treating p as a divider rather than a multiplier.
- *
- * Passing a shared structure, with ROM contents previously computed by
- * yescrypt_init_shared(), enables the use of ROM and requires YESCRYPT_RW.
- *
- * In order to allow for initialization of the ROM to be split into a separate
- * program (or separate invocation of the same program), the shared->aligned
- * and shared->aligned_size fields may optionally be set by the caller directly
- * (e.g., to a mapped SysV shm segment), without using yescrypt_init_shared().
- *
- * MT-safe as long as local and buf are local to the thread.
- */
-#ifdef YESCRYPT_INTERNAL
-static int yescrypt_kdf32(
- yescrypt_ctx_t *yctx,
- const uint8_t *passwd, size_t passwdlen,
- uint8_t *buf32);
-#endif
+#define YESCRYPT_HASH_SIZE 32
+#define YESCRYPT_HASH_LEN YESCRYPT_BYTES2CHARS(YESCRYPT_HASH_SIZE)
/**
* yescrypt_r(shared, local, passwd, passwdlen, setting, key, buf, buflen):
diff --git a/libbb/yescrypt/y.c b/libbb/yescrypt/y.c
index 92c6eb7a8..e7d447531 100644
--- a/libbb/yescrypt/y.c
+++ b/libbb/yescrypt/y.c
@@ -1,11 +1,17 @@
+/*
+ * The compilation unit for yescrypt-related code.
+ *
+ * Copyright (C) 2025 by Denys Vlasenko <vda.linux at googlemail.com>
+ *
+ * Licensed under GPLv2, see file LICENSE in this source tree.
+ */
//kbuild:lib-$(CONFIG_USE_BB_CRYPT_YES) += y.o
-#include <libbb.h>
+#include "libbb.h"
#define YESCRYPT_INTERNAL
#include "alg-sha256.h"
#include "alg-yescrypt.h"
#include "alg-sha256.c"
-#include "alg-yescrypt-platform.c"
#include "alg-yescrypt-kdf.c"
#include "alg-yescrypt-common.c"
More information about the busybox-cvs
mailing list