Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSA Decryption: check private value after decryption #7167

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions wolfcrypt/src/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -2723,6 +2723,17 @@ static int RsaFunctionSync(const byte* in, word32 inLen, byte* out,
if (mp_to_unsigned_bin_len_ct(tmp, out, (int)*outLen) != MP_OKAY)
ret = MP_TO_E;
}
#ifdef WOLFSSL_RSA_CHECK_D_ON_DECRYPT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something that should be on be default and optionally turned off rather than off be default and optionally turned on?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to enable with WOLFSSL_CHECK_SIG_FAULTS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WOLFSSL_CHECK_SIG_FAULTS is currently for signature and ECC.
This code is only for RSA decryption and not signing.
If there was a better generic 'check data after op' define, I would consider enabling it as part of that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SparkiDev should this be on by default and have a different macro name to disable it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are very limited circumstances that would require the checking of d.
It is unnecessary work that we should avoided if possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge as-is then document clearly those reasons

if ((ret == 0) && (type == RSA_PRIVATE_DECRYPT)) {
mp_sub(&key->n, &key->p, tmp);
mp_sub(tmp, &key->q, tmp);
mp_add_d(tmp, 1, tmp);
mp_mulmod(&key->d, &key->e, tmp, tmp);
if (!mp_isone(tmp)) {
ret = MP_EXPTMOD_E;
}
}
#endif
#else
(void)type;
(void)key;
Expand Down