← Commit list

5e17e3c6f

Denys Vlasenko
Denys Vlasenko
2025-07-06
SOURCE BUG Duration: 72s

Subject

libbb: shuffle ascii64 code around, shrink i2a64()

SOURCE BUG

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)

→ Bu hatanin tam hikayesini ve duzeltme diffini gor

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

libbb/pw_encrypt.c+1 -73
@@ -13,68 +13,7 @@
#endif
#include "libbb.h"
-/* 0..63 ->
- * "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- */
-int FAST_FUNC i2a64(int i)
-{
- i &= 0x3f;
- if (i == 0)
- return '.';
- if (i == 1)
- return '/';
- if (i < 12)
- return ('0' - 2 + i);
- if (i < 38)
- return ('A' - 12 + i);
- return ('a' - 38 + i);
-}
-
-/* Returns >=64 for invalid chars */
-int FAST_FUNC a2i64(char c)
-{
- unsigned char ch = c;
- if (ch >= 'a')
- /* "a..z" to 38..63 */
- /* anything after "z": positive int >= 64 */
- return (ch - 'a' + 38);
-
- if (ch > 'Z')
- /* after "Z" but before "a": positive byte >= 64 */
- return ch;
-
- if (ch >= 'A')
- /* "A..Z" to 12..37 */
- return (ch - 'A' + 12);
-
- if (ch > '9')
- return 64;
-
- /* "./0123456789" to 0,1,2..11 */
- /* anything before "." becomes positive byte >= 64 */
- return (unsigned char)(ch - '.');
-}
-
-int FAST_FUNC crypt_make_rand64encoded(char *p, int cnt /*, int x */)
-{
- /* was: x += ... */
- unsigned x = getpid() + monotonic_us();
- do {
- /* x = (x*1664525 + 1013904223) % 2^32 generator is lame
- * (low-order bit is not "random", etc...),
- * but for our purposes it is good enough */
- x = x*1664525 + 1013904223;
- /* BTW, Park and Miller's "minimal standard generator" is
- * x = x*16807 % ((2^31)-1)
- * It has no problem with visibly alternating lowest bit
- * but is also weak in cryptographic sense + needs div,
- * which needs more code (and slower) on many CPUs */
- *p++ = i2a64(x >> 16);
- *p++ = i2a64(x >> 22);
- } while (--cnt);
- *p = '\0';
- return x;
-}
+#include "pw_ascii64.c"
char* FAST_FUNC crypt_make_pw_salt(char salt[MAX_PW_SALT_LEN], const char *algo)
{
@@ -139,17 +78,6 @@ char* FAST_FUNC crypt_make_pw_salt(char salt[MAX_PW_SALT_LEN], const char *algo)
}
#if ENABLE_USE_BB_CRYPT
-
-static char*
-to64(char *s, unsigned v, int n)
-{
- while (--n >= 0) {
- *s++ = i2a64(v);
- v >>= 6;
- }
- return s;
-}
-
/*
* DES and MD5 crypt implementations are taken from uclibc.
* They were modified to not use static buffers.
libbb/pw_encrypt_des.c+3 -12
@@ -671,15 +671,6 @@ do_des(struct des_ctx *ctx, /*uint32_t l_in, uint32_t r_in,*/ uint32_t *l_out, u
#define DES_OUT_BUFSIZE 21
-static void
-to64_msb_first(char *s, unsigned v)
-{
- *s++ = i2a64(v >> 18); /* bits 23..18 */
- *s++ = i2a64(v >> 12); /* bits 17..12 */
- *s++ = i2a64(v >> 6); /* bits 11..6 */
- *s = i2a64(v); /* bits 5..0 */
-}
-
static char *
NOINLINE
des_crypt(struct des_ctx *ctx, char output[DES_OUT_BUFSIZE],
@@ -726,11 +717,11 @@ des_crypt(struct des_ctx *ctx, char output[DES_OUT_BUFSIZE],
/* Now encode the result. */
/* Each call takes low-order 24 bits and stores 4 chars */
/* bits 31..8 of r0 */
- to64_msb_first(output + 2, (r0 >> 8));
+ num2str64_4chars_msb_first(output + 2, (r0 >> 8));
/* bits 7..0 of r0 and 31..16 of r1 */
- to64_msb_first(output + 6, (r0 << 16) | (r1 >> 16));
+ num2str64_4chars_msb_first(output + 6, (r0 << 16) | (r1 >> 16));
/* bits 15..0 of r1 and two zero bits (plus extra zero byte) */
- to64_msb_first(output + 10, (r1 << 8));
+ num2str64_4chars_msb_first(output + 10, (r1 << 8));
/* extra zero byte is encoded as '.', fixing it */
output[13] = '\0';
libbb/pw_encrypt_md5.c+2 -2
@@ -149,9 +149,9 @@ md5_crypt(char result[MD5_OUT_BUFSIZE], const unsigned char *pw, const unsigned
final[16] = final[5];
for (i = 0; i < 5; i++) {
unsigned l = (final[i] << 16) | (final[i+6] << 8) | final[i+12];
- p = to64(p, l, 4);
+ p = num2str64_lsb_first(p, l, 4);
}
- p = to64(p, final[11], 2);
+ p = num2str64_lsb_first(p, final[11], 2);
*p = '\0';
/* Don't leave anything around in vm they could use. */
libbb/pw_encrypt_sha.c+1 -1
@@ -198,7 +198,7 @@ sha_crypt(/*const*/ char *key_data, /*const*/ char *salt_data)
#define b64_from_24bit(B2, B1, B0, N) \
do { \
unsigned w = ((B2) << 16) | ((B1) << 8) | (B0); \
- resptr = to64(resptr, w, N); \
+ resptr = num2str64_lsb_first(resptr, w, N); \
} while (0)
if (_32or64 == 32) { /* sha256 */
unsigned i = 0;