void Tests::runTests()
{
- if (this->rsaStandard())
- cout << "RSA standard OK" << endl;
- else
- cout << "RSA standard failed!" << endl;
+ cout << "Tests::runTests() ..." << endl;
- if (this->rsaCrt())
- cout << "RSA CRT OK" << endl;
- else
- cout << "RSA CRT failed!" << endl;
+ cout << "RSA standard: " << (this->rsaStandard() ? "OK" : "failed!") << endl;
+ cout << "RSA CRT: " << (this->rsaCrt() ? "OK" : "failed!") << endl;
}
void Tests::runTestsWithShamirsTrick()
{
- if (this->rsaCrtWithShamirsTrick())
- cout << "RSA CRT with shamir's trick OK" << endl;
- else
- cout << "RSA CRT with shamir's trick failed!" << endl;
+ cout << "Tests::runTestsWithShamirsTrick() ..." << endl;
+
+ cout << "RSA CRT with Shamir's trick: " << (this->rsaCrtWithShamirsTrick() ? "OK" : "failed!") << endl;
}
void Tests::runTimeMeasures()
{
+ cout << "Tests::runTimeMeasures() ..." << endl;
+
const int N = 1000;
const int nbKeys = 20; // Number of different generated key.
cout << N * nbKeys << " x RSA CRT: " << timeRsaCRT << " ms" << endl;
cout << N * nbKeys << " x RSA CRT Shamir's trick: " << timeRsaCRTShamirsTrick << " ms" << endl;
cout << "Speedup for CRT: " << (double(timeRsaStd) / double(timeRsaCRT)) << endl;
- cout << "Speedup for CRT with Shamir's trick: " << (double(timeRsaStd) / double(timeRsaCRT)) << endl;
+ cout << "Speedup for CRT with Shamir's trick: " << (double(timeRsaStd) / double(timeRsaCRTShamirsTrick)) << endl;
}
void Tests::doAttack()
{
+ cout << "Tests::doAttack() ..." << endl;
+
const auto& keys = RsaCrt::generateRSAKeys(RSA_PUBLIC_EXPONENT, KEY_SIZE_BITS);
const auto& kPub = keys.first;
const auto& kPriv = keys.second;
attackSuccessful = attackSuccessful && kPriv.p == p && kPriv.q == q; // With p and q we can recreate the original private key.
}
- // Try the attack with a correct signature.
+ // Try the attack with a correct signature (p and q shouldn't be found).
{
mpz_class correctSignaturePowerE;
mpz_pow_ui(correctSignaturePowerE.get_mpz_t(), correctSignature.get_mpz_t(), RSA_PUBLIC_EXPONENT);
void Tests::doAttackFixed()
{
- const auto& keys = RsaCrt::generateRSAKeys(RSA_PUBLIC_EXPONENT, KEY_SIZE_BITS);
- const auto& kPub = keys.first;
+ cout << "Tests::doAttackFixed() ..." << endl;
+
+ const auto& keys = RsaCrtShamirsTrick::generateRSAKeys(RSA_PUBLIC_EXPONENT, KEY_SIZE_BITS);
const auto& kPriv = keys.second;
+
+ mpz_class message = Rand::randSize(128);
+
+ try
+ {
+ RsaCrtShamirsTrick::signWithFaultySp(message, kPriv);
+ cout << "Attack successful -> incorrect" << endl;
+ }
+ catch (const RsaCrtShamirsTrick::UnableToSignWithShamirsTrick& e)
+ {
+ cout << "Attack failed -> correct" << endl;
+ }
}
bool Tests::rsaStandard()