Commit d928a18
committed
Regression test for the EVP_DigestVerifyFinal HMAC zero-length tag
forgery.
wolfSSL_EVP_DigestVerifyFinal in wolfcrypt/src/evp.c uses the
caller-supplied siglen as the comparison length for the HMAC branch
with only an upper bound check:
if (siglen > hashLen || siglen > INT_MAX)
return WOLFSSL_FAILURE;
...
if (ConstantCompare(sig, digest, (int)siglen) == 0)
return WOLFSSL_SUCCESS;
There is no lower bound, so passing siglen=0 with any non-NULL sig
pointer makes ConstantCompare return 0 (zero-length comparison is
trivially equal) and the function reports SUCCESS. An attacker who
controls a serialized MAC length field forwarded to this API obtains
a universal HMAC forgery without knowledge of the key.
The test:
1. Builds an HMAC-SHA256 EVP_PKEY with a fixed key.
2. Positive control: signs a message, verifies the genuine 32-byte
tag round-trips and a wrong full-length tag is rejected.
3. Forgery probe: calls EVP_DigestVerifyFinal with siglen=0 and a
pointer to all-zero buffer. Asserts the call does NOT return
WOLFSSL_SUCCESS. On the unfixed tree this returns
WOLFSSL_SUCCESS (forgery accepted); on a fixed tree the
implementation must require siglen >= the algorithm's native
digest size or otherwise reject zero-length tags.1 parent 7da1916 commit d928a18
2 files changed
Lines changed: 76 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
382 | 382 | | |
383 | 383 | | |
384 | 384 | | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
385 | 458 | | |
386 | 459 | | |
387 | 460 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| 74 | + | |
| 75 | + | |
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
| |||
0 commit comments