summaryrefslogtreecommitdiff
path: root/libbb/yescrypt
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2025-08-01 02:21:38 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2025-08-01 02:21:38 +0200
commite95086b2fadcddd77723a8fea77f8319eb5dbf69 (patch)
treed2aa765e428039321195e9678be1c3179f838e6c /libbb/yescrypt
parent4f3a56dc12a2126bdacff73f1cfe586d06e800c0 (diff)
libbb/yescrypt: code shrink
function old new delta static.PBKDF2_SHA256 219 165 -54 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/yescrypt')
-rw-r--r--libbb/yescrypt/alg-sha256.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/libbb/yescrypt/alg-sha256.c b/libbb/yescrypt/alg-sha256.c
index 20e8d1ee4..dc748c968 100644
--- a/libbb/yescrypt/alg-sha256.c
+++ b/libbb/yescrypt/alg-sha256.c
@@ -47,9 +47,12 @@ PBKDF2_SHA256(const uint8_t *passwd, size_t passwdlen,
/* Iterate through the blocks. */
for (i = 0; dkLen != 0; ) {
- uint64_t U[32 / 8];
- uint64_t T[32 / 8];
- uint64_t j;
+ long U[32 / sizeof(long)];
+ long T[32 / sizeof(long)];
+// Do not make these ^^ uint64_t[]. Keep them long[].
+// Even though the XORing loop below is optimized out,
+// gcc is not smart enough to realize that 64-bit alignment of the stack
+// is no longer useful, and generates ~50 more bytes of code on i386...
uint32_t ivec;
size_t clen;
int k;
@@ -64,13 +67,15 @@ PBKDF2_SHA256(const uint8_t *passwd, size_t passwdlen,
//does libbb need a non-vararg version with just one (buf,len)?
if (c > 1) {
+//in yescrypt, c is always 1, so this if() branch is optimized out
+ uint64_t j;
/* T_i = U_1 ... */
memcpy(U, T, 32);
for (j = 2; j <= c; j++) {
/* Compute U_j. */
hmac_peek_hash(&Phctx, (void*)U, U, 32, NULL);
/* ... xor U_j ... */
- for (k = 0; k < 32 / 8; k++)
+ for (k = 0; k < 32 / sizeof(long); k++)
T[k] ^= U[k];
//TODO: xorbuf32_aligned_long(T, U);
}