Skip to content

Commit

Permalink
Fix for policy_sign issue when r or s is less than key size (needs ze…
Browse files Browse the repository at this point in the history
…ro padding).
  • Loading branch information
dgarske committed Nov 29, 2023
1 parent 1853127 commit 5013754
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions examples/pcr/policy_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,16 @@ static int PolicySign(TPM_ALG_ID alg, const char* keyFile, const char* password,
rc = wc_ecc_sign_hash_ex(hash, hashSz, &rng, &key.ecc, &r, &s);
}
if (rc == 0) {
word32 keySz = key.ecc.dp->size;
mp_to_unsigned_bin(&r, sig);
mp_to_unsigned_bin(&s, sig + keySz);
word32 keySz = key.ecc.dp->size, rSz, sSz;
*sigSz = keySz * 2;
XMEMSET(sig, 0, *sigSz);
/* export sign r/s - zero pad to key size */
rSz = mp_unsigned_bin_size(&r);
mp_to_unsigned_bin(&r, &sig[keySz - rSz]);
sSz = mp_unsigned_bin_size(&s);
mp_to_unsigned_bin(&s, &sig[keySz + (keySz - sSz)]);
mp_clear(&r);
mp_clear(&s);
*sigSz = keySz * 2;
}
}
wc_ecc_free(&key.ecc);
Expand Down

0 comments on commit 5013754

Please sign in to comment.