Skip to content

Commit 5013754

Browse files
committed
Fix for policy_sign issue when r or s is less than key size (needs zero padding).
1 parent 1853127 commit 5013754

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

examples/pcr/policy_sign.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,16 @@ static int PolicySign(TPM_ALG_ID alg, const char* keyFile, const char* password,
185185
rc = wc_ecc_sign_hash_ex(hash, hashSz, &rng, &key.ecc, &r, &s);
186186
}
187187
if (rc == 0) {
188-
word32 keySz = key.ecc.dp->size;
189-
mp_to_unsigned_bin(&r, sig);
190-
mp_to_unsigned_bin(&s, sig + keySz);
188+
word32 keySz = key.ecc.dp->size, rSz, sSz;
189+
*sigSz = keySz * 2;
190+
XMEMSET(sig, 0, *sigSz);
191+
/* export sign r/s - zero pad to key size */
192+
rSz = mp_unsigned_bin_size(&r);
193+
mp_to_unsigned_bin(&r, &sig[keySz - rSz]);
194+
sSz = mp_unsigned_bin_size(&s);
195+
mp_to_unsigned_bin(&s, &sig[keySz + (keySz - sSz)]);
191196
mp_clear(&r);
192197
mp_clear(&s);
193-
*sigSz = keySz * 2;
194198
}
195199
}
196200
wc_ecc_free(&key.ecc);

0 commit comments

Comments
 (0)