← Commit list

0893bc3ba

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

Subject

libbb/yescrypt: code shrink

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 →

include/libbb.h+2 -0
@@ -2189,6 +2189,8 @@ char *decode_base64(char *dst, const char **pp_src) FAST_FUNC;
char *decode_base32(char *dst, const char **pp_src) FAST_FUNC;
void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC;
+int FAST_FUNC i2a64(int i);
+
typedef struct md5_ctx_t {
uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */
void (*process_block)(struct md5_ctx_t*) FAST_FUNC;
libbb/pw_encrypt.c+5 -7
@@ -13,11 +13,10 @@
#endif
#include "libbb.h"
-/* static const uint8_t ascii64[] ALIGN1 =
+/* 0..63 ->
* "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
*/
-
-static int i64c(int i)
+int FAST_FUNC i2a64(int i)
{
i &= 0x3f;
if (i == 0)
@@ -45,8 +44,8 @@ int FAST_FUNC crypt_make_rand64encoded(char *p, int cnt /*, int x */)
* 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++ = i64c(x >> 16);
- *p++ = i64c(x >> 22);
+ *p++ = i2a64(x >> 16);
+ *p++ = i2a64(x >> 22);
} while (--cnt);
*p = '\0';
return x;
@@ -120,8 +119,7 @@ static char*
to64(char *s, unsigned v, int n)
{
while (--n >= 0) {
- /* *s++ = ascii64[v & 0x3f]; */
- *s++ = i64c(v);
+ *s++ = i2a64(v);
v >>= 6;
}
return s;
libbb/pw_encrypt_des.c+4 -4
@@ -703,10 +703,10 @@ to64_msb_first(char *s, unsigned v)
*s++ = ascii64[(v >> 6) & 0x3f]; /* bits 11..6 */
*s = ascii64[v & 0x3f]; /* bits 5..0 */
#endif
- *s++ = i64c(v >> 18); /* bits 23..18 */
- *s++ = i64c(v >> 12); /* bits 17..12 */
- *s++ = i64c(v >> 6); /* bits 11..6 */
- *s = i64c(v); /* bits 5..0 */
+ *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 *
libbb/yescrypt/alg-sha256.c+1 -1
@@ -107,7 +107,7 @@ HMAC_SHA256_Buf(const void *K, size_t Klen, const void *in, size_t len,
* Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and
* write the output to buf. The value dkLen must be at most 32 * (2^32 - 1).
*/
-void
+static void
PBKDF2_SHA256(const uint8_t *passwd, size_t passwdlen,
const uint8_t *salt, size_t saltlen,
uint64_t c, uint8_t *buf, size_t dkLen)
libbb/yescrypt/alg-sha256.h+0 -18
@@ -24,26 +24,8 @@
* SUCH DAMAGE.
*/
-/*
- * Use #defines in order to avoid namespace collisions with anyone else's
- * SHA256 code (e.g., the code in OpenSSL).
- */
-#define HMAC_SHA256_Init libcperciva_HMAC_SHA256_Init
-#define HMAC_SHA256_Update libcperciva_HMAC_SHA256_Update
-#define HMAC_SHA256_Final libcperciva_HMAC_SHA256_Final
-#define HMAC_SHA256_Buf libcperciva_HMAC_SHA256_Buf
-#define HMAC_SHA256_CTX libcperciva_HMAC_SHA256_CTX
-
/* Context structure for HMAC-SHA256 operations. */
typedef struct {
sha256_ctx_t ictx;
sha256_ctx_t octx;
} HMAC_SHA256_CTX;
-
-/**
- * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen):
- * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and
- * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1).
- */
-extern void PBKDF2_SHA256(const uint8_t *, size_t, const uint8_t *, size_t,
- uint64_t, uint8_t *, size_t);
libbb/yescrypt/alg-yescrypt-common.c+1 -1
@@ -88,7 +88,7 @@ static uint8_t *encode64_uint32_fixed(
for (bits = 0; bits < srcbits; bits += 6) {
if (dstlen < 2)
return NULL;
- *dst++ = itoa64[src & 0x3f];
+ *dst++ = i2a64(src);
dstlen--;
src >>= 6;
}
libbb/yescrypt/y.c+0 -6
@@ -124,12 +124,6 @@ VECTOR_TO_CPU(be,32);
VECTOR_TO_CPU(be,64);
-const unsigned char ascii64[65] =
- "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-/* 0000000000111111111122222222223333333333444444444455555555556666 */
-/* 0123456789012345678901234567890123456789012345678901234567890123 */
-#define itoa64 ascii64
-
#define YESCRYPT_INTERNAL
#include "alg-sha256.h"
#include "alg-yescrypt.h"