Commit f32cfba
verifier: fix Hygon TPM SM2 quote signature verification
The previous verify path built an SM2 PKey and ran the signature through
OpenSSL's EVP_DigestVerify (effectively `Verifier::new(SM3, pkey)`).
That path either applies the GB/T 32918 ZA pre-processing
(SM3(ENTL || ID || a || b || xG || yG || xA || yA) prepended to the
message) or, on a plain EC PKey, silently dispatches to ECDSA verify.
Neither matches what TPM2 produces: per the TPM 2.0 spec the SM2 quote
signs SM3(attestBody) directly, with no ZA mixing and no DER wrapping.
End-to-end attestation against a real Hygon TPM therefore failed with
"Verify Hygon TPM quote signature failed" even when the AK, evidence
body, and signature were all correct.
Drop the OpenSSL high-level verifier and implement the SM2 verify
equation from GB/T 32918.2-2016 §7.1 directly using BigNum/EcPoint:
e = SM3(attestBody)
t = (r + s) mod n with t != 0
P = s * G + t * Q
ok iff (e + P.x) mod n == r
Range-check r and s against [1, n-1] up front and reject t == 0 to
match the spec. Reuse the existing extracted (r, s) from the marshalled
TPM signature; create_sm2_pkey is left in place because it is still
used to compare AK pubkeys against the keylime registrar.
Signed-off-by: Jiale Zhang <xinjian.zjl@alibaba-inc.com>1 parent 312088a commit f32cfba
1 file changed
Lines changed: 46 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | 13 | | |
16 | 14 | | |
17 | | - | |
18 | 15 | | |
19 | 16 | | |
20 | 17 | | |
| |||
94 | 91 | | |
95 | 92 | | |
96 | 93 | | |
97 | | - | |
| 94 | + | |
98 | 95 | | |
99 | 96 | | |
100 | 97 | | |
| |||
103 | 100 | | |
104 | 101 | | |
105 | 102 | | |
106 | | - | |
107 | | - | |
| 103 | + | |
108 | 104 | | |
109 | 105 | | |
110 | 106 | | |
| |||
420 | 416 | | |
421 | 417 | | |
422 | 418 | | |
423 | | - | |
424 | | - | |
| 419 | + | |
425 | 420 | | |
426 | 421 | | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
| 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 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
434 | 465 | | |
435 | 466 | | |
436 | 467 | | |
| |||
0 commit comments