libbb/yescrypt: remove one NOINLINE, add copyright headers, merge two source files
This commit was genuinely broken at the time (not related to our build system): libbb/yescrypt eklenirken (2025-07-06 - 2025-07-07 arasi) once unutulan kaynak dosyalari (pw_encrypt_yes.c, hash_sha256_block.c, pw_ascii64.c), ardindan 64-bit'te derlenmeyen bir 'buflen' degiskeni (alg-yescrypt-kdf.c) vardi - busybox'in kendi kodundaki gercek hatalar (e5d3a8763 ile duzeltildi)
No binary (build failed)
—
(log yok)
| @@ -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; | |
| @@ -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): | |
| @@ -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; |
| - | } |
| @@ -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): | |
| @@ -1,11 +1,17 @@ | |
| + | /* |
| + | * The compilation unit for yescrypt-related code. |
| + | * |
| + | * Copyright (C) 2025 by Denys Vlasenko <[email protected]> |
| + | * |
| + | * 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" | |