libmbedtls: fix no CRT issue
In NO_CRT mode, Q and P may be invalid. But Q and P will be re-filled
again if PRNG function is valid. So add judgement process if it is
in NO_CRT mode.
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
Signed-off-by: Summer Qin <summer.qin@arm.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
[jf: rebase onto mbedtls-2.27.0]
Signed-off-by: Jerome Forissier <jerome@forissier.org>
[jw: rebase onto mbedtls-3.4.0]
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
[tve: rebased onto mbedtls-3.6.0]
Signed-off-by: Tom Van Eyck <tom.vaneyck@kuleuven.be>
[sby: rebased onto mbedtls-3.6.2]
Signed-off-by: Sungbae Yoo <sungbaey@nvidia.com>
diff --git a/lib/libmbedtls/mbedtls/library/rsa.c b/lib/libmbedtls/mbedtls/library/rsa.c
index 557faaf..8f1363f 100644
--- a/lib/libmbedtls/mbedtls/library/rsa.c
+++ b/lib/libmbedtls/mbedtls/library/rsa.c
@@ -1956,7 +1956,10 @@
/*
* RSA operation
*/
- ret = mbedtls_rsa_private(ctx, f_rng, p_rng, input, buf);
+ if( ctx->P.n == 0 )
+ ret = mbedtls_rsa_private( ctx, NULL, NULL, input, buf );
+ else
+ ret = mbedtls_rsa_private(ctx, f_rng, p_rng, input, buf);
if (ret != 0) {
goto cleanup;
@@ -2217,6 +2220,9 @@
p += hlen;
*p++ = 0xBC;
+ if (ctx->P.n == 0)
+ return mbedtls_rsa_private(ctx, NULL, NULL, sig, sig);
+
return mbedtls_rsa_private(ctx, f_rng, p_rng, sig, sig);
}