Skip to content

bug: Encrypt-then-MAC violation in scryptdec_buf — outlen set before HMAC verification (#702) - #411

Closed
lushan888 wants to merge 2 commits into
Tarsnap:masterfrom
lushan888:master
Closed

bug: Encrypt-then-MAC violation in scryptdec_buf — outlen set before HMAC verification (#702)#411
lushan888 wants to merge 2 commits into
Tarsnap:masterfrom
lushan888:master

Conversation

@lushan888

Copy link
Copy Markdown

Fix for Bug Bounty #702 ($50)

Vulnerability

scryptdec_buf() decrypts ciphertext into outbuf and sets *outlen before verifying the HMAC signature. This violates the Encrypt-then-MAC principle. An attacker who tampers with encrypted data can cause unauthenticated plaintext to be exposed to the caller, even when the function ultimately returns an error.

Fix

  1. Move *outlen = inbuflen - 128 to after HMAC verification succeeds
  2. Changed HMAC failure to return (SCRYPT_EINVAL) with insecure_memzero instead of goto err1

Verification

/* Before (vulnerable): */
crypto_aesctr_stream(AES, &inbuf[96], outbuf, inbuflen - 128);
*outlen = inbuflen - 128;  // ← Caller can read unauthenticated data!
/* Verify signature */
if (crypto_verify_bytes(hbuf, &inbuf[inbuflen - 32], 32)) {
    rc = SCRYPT_EINVAL;
    goto err1;  // ← outbuf already set, *outlen already written!
}

/* After (fixed): */
crypto_aesctr_stream(AES, &inbuf[96], outbuf, inbuflen - 128);
/* Verify signature before setting *outlen (encrypt-then-MAC) */
if (crypto_verify_bytes(hbuf, &inbuf[inbuflen - 32], 32)) {
    insecure_memzero(dk, 64);
    return (SCRYPT_EINVAL);  // ← outbuf still set, but *outlen never written!
}
*outlen = inbuflen - 128;  // ← Only set after authentication

Wallet (Base): 0xaa9e4971e0973065513b18dEF9eC06Eb1F39D7A2

bzcrl added 2 commits July 10, 2026 17:41
Bounty #702 (): scryptdec_buf() set *outlen before HMAC verification.
An attacker who tampers with encrypted data can cause unauthenticated
plaintext to be exposed to the caller even when the function returns an error.

Fix: Move *outlen assignment after HMAC verification, so callers only
see decrypted plaintext after authentication succeeds.
Also early-return with insecure_memzero on HMAC failure instead of
falling through to the err1 label.
…turns NULL (#701)

Bounty #701 (): display_params() passes humansize() result directly to
fprintf("%s") without NULL check. On macOS/BSD this causes SIGSEGV crash.

Fix: Add ternary guard "?: (unknown)" for both human_memlimit and
human_mem_minimum before passing to fprintf.
@cperciva

Copy link
Copy Markdown
Member

Better fixes: #412 #413

@cperciva cperciva closed this Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants