tpm2: Check return code of BN_div()

Check the return code of BN_div() when calculating Q and Qr of
a private key.

Resolves: https://github.com/stefanberger/libtpms/issues/304
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2022-03-30 10:14:51 -04:00 committed by Stefan Berger
parent 7a64b3e41e
commit 8590849b65

View File

@ -521,8 +521,7 @@ InitOpenSSLRSAPrivateKey(OBJECT *rsaKey, // IN
ERROR_RETURN(TPM_RC_FAILURE);
/* Q = N/P; no remainder */
BN_set_flags(P, BN_FLG_CONSTTIME); // P is secret
BN_div(Q, Qr, N, P, ctx);
if(!BN_is_zero(Qr))
if (!BN_div(Q, Qr, N, P, ctx) || !BN_is_zero(Qr))
ERROR_RETURN(TPM_RC_BINDING);
BN_set_flags(Q, BN_FLG_CONSTTIME); // Q is secret