Skip to content

Commit

Permalink
Merge pull request #7167 from SparkiDev/rsa_dec_check_d
Browse files Browse the repository at this point in the history
RSA Decryption: check private value after decryption
  • Loading branch information
dgarske committed Jan 29, 2024
2 parents a6326bd + 999f845 commit de4a6f9
Showing 1 changed file with 11 additions and 0 deletions.
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
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

0 comments on commit de4a6f9

Please sign in to comment.