Skip to content

Commit de4a6f9

Browse files
authored
Merge pull request #7167 from SparkiDev/rsa_dec_check_d
RSA Decryption: check private value after decryption
2 parents a6326bd + 999f845 commit de4a6f9

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

wolfcrypt/src/rsa.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2723,6 +2723,17 @@ static int RsaFunctionSync(const byte* in, word32 inLen, byte* out,
27232723
if (mp_to_unsigned_bin_len_ct(tmp, out, (int)*outLen) != MP_OKAY)
27242724
ret = MP_TO_E;
27252725
}
2726+
#ifdef WOLFSSL_RSA_CHECK_D_ON_DECRYPT
2727+
if ((ret == 0) && (type == RSA_PRIVATE_DECRYPT)) {
2728+
mp_sub(&key->n, &key->p, tmp);
2729+
mp_sub(tmp, &key->q, tmp);
2730+
mp_add_d(tmp, 1, tmp);
2731+
mp_mulmod(&key->d, &key->e, tmp, tmp);
2732+
if (!mp_isone(tmp)) {
2733+
ret = MP_EXPTMOD_E;
2734+
}
2735+
}
2736+
#endif
27262737
#else
27272738
(void)type;
27282739
(void)key;

0 commit comments

Comments
 (0)