testAKey("prvpass", "pubpass");
ca.setParam(ParamName::GEN_KEY_LEN, 2048);
testAKey();
+ ca.setParam(ParamName::GEN_KEY_LEN, 3072);
+ testAKey();
ca.setParam(ParamName::GEN_KEY_LEN, 4096);
testAKey();
ca->setParam(ParamName::ALGO_TYPE, AlgoType::RSA_GEN);
invalidGen();
- for (int keyLen : { 0, 512, 1023, 1025, 3072, 4097, 8192 }) {
+ for (int keyLen : { 0, 512, 1023, 1025, 3073, 4097, 8192 }) {
ca->setParam(ParamName::GEN_KEY_LEN, keyLen);
invalidGen();
}
POSITIVE_TEST_CASE(asymmetricEncryptDecrypt)
{
- constexpr int KEY_BIT_LEN = 2048;
- auto& rsaKeys = generateObjUPtrPair(AlgoType::RSA_GEN, KEY_BIT_LEN);
+ for (int KEY_BIT_LEN : {1024, 2048, 3072, 4096})
+ {
+ auto& rsaKeys = generateObjUPtrPair(AlgoType::RSA_GEN, KEY_BIT_LEN);
- CryptoAlgorithm enc;
- enc.setParam(ParamName::ALGO_TYPE, AlgoType::RSA_OAEP);
+ CryptoAlgorithm enc;
+ enc.setParam(ParamName::ALGO_TYPE, AlgoType::RSA_OAEP);
- RawBuffer encrypted;
- RawBuffer decrypted;
+ RawBuffer encrypted;
+ RawBuffer decrypted;
- auto encryptDecrypt = [&](const RawBuffer& input)
- {
- BOOST_REQUIRE_NO_THROW(encrypted = rsaKeys.pub->encrypt(enc, input));
- BOOST_REQUIRE(encrypted.size() == KEY_BIT_LEN / 8);
+ auto encryptDecrypt = [&](const RawBuffer& input)
+ {
+ BOOST_REQUIRE_NO_THROW(encrypted = rsaKeys.pub->encrypt(enc, input));
+ BOOST_REQUIRE(encrypted.size() == static_cast<unsigned int>(KEY_BIT_LEN / 8));
- BOOST_REQUIRE_NO_THROW(decrypted = rsaKeys.prv->decrypt(enc, encrypted));
- BOOST_REQUIRE(decrypted == input);
- };
+ BOOST_REQUIRE_NO_THROW(decrypted = rsaKeys.prv->decrypt(enc, encrypted));
+ BOOST_REQUIRE(decrypted == input);
+ };
- encryptDecrypt(createRandom(oaepMaxSize(KEY_BIT_LEN, HashAlgorithm::SHA1)));
- encryptDecrypt(createRandom(oaepMaxSize(KEY_BIT_LEN, HashAlgorithm::SHA1) - 1));
- encryptDecrypt(RawBuffer());
+ encryptDecrypt(createRandom(oaepMaxSize(KEY_BIT_LEN, HashAlgorithm::SHA1)));
+ encryptDecrypt(createRandom(oaepMaxSize(KEY_BIT_LEN, HashAlgorithm::SHA1) - 1));
+ encryptDecrypt(RawBuffer());
- enc.setParam(ParamName::ED_OAEP_HASH, HashAlgorithm::SHA1);
- encryptDecrypt(createRandom(oaepMaxSize(KEY_BIT_LEN, HashAlgorithm::SHA1)));
- enc.setParam(ParamName::ED_OAEP_HASH, HashAlgorithm::SHA256);
- encryptDecrypt(createRandom(oaepMaxSize(KEY_BIT_LEN, HashAlgorithm::SHA256)));
+ enc.setParam(ParamName::ED_OAEP_HASH, HashAlgorithm::SHA1);
+ encryptDecrypt(createRandom(oaepMaxSize(KEY_BIT_LEN, HashAlgorithm::SHA1)));
+ enc.setParam(ParamName::ED_OAEP_HASH, HashAlgorithm::SHA256);
+ encryptDecrypt(createRandom(oaepMaxSize(KEY_BIT_LEN, HashAlgorithm::SHA256)));
+ }
}
NEGATIVE_TEST_CASE(asymmetricEncryptDecrypt)
signVerify(AlgoType::RSA_GEN, 1024, HashAlgorithm::SHA384, RSAPaddingAlgorithm::PKCS1);
signVerify(AlgoType::RSA_GEN, 1024, HashAlgorithm::SHA512, RSAPaddingAlgorithm::PKCS1);
signVerify(AlgoType::RSA_GEN, 2048, HashAlgorithm::SHA1, RSAPaddingAlgorithm::PKCS1);
+ signVerify(AlgoType::RSA_GEN, 3072, HashAlgorithm::SHA1, RSAPaddingAlgorithm::PKCS1);
signVerify(AlgoType::RSA_GEN, 4096, HashAlgorithm::SHA1, RSAPaddingAlgorithm::PKCS1);
signVerify(AlgoType::DSA_GEN, 1024, HashAlgorithm::SHA1);
message[0] = 0; // make sure it's smaller than the modulus
message.resize(4096/8);
signVerify(AlgoType::RSA_GEN, 4096, HashAlgorithm::NONE);
+ message.resize(3072/8);
+ signVerify(AlgoType::RSA_GEN, 3072, HashAlgorithm::NONE);
message.resize(2048/8);
signVerify(AlgoType::RSA_GEN, 2048, HashAlgorithm::NONE);
message.resize(1024/8);
// no hash + padding
message.resize(512/8);
signVerify(AlgoType::RSA_GEN, 4096, HashAlgorithm::NONE, RSAPaddingAlgorithm::PKCS1);
+ signVerify(AlgoType::RSA_GEN, 3072, HashAlgorithm::NONE, RSAPaddingAlgorithm::PKCS1);
signVerify(AlgoType::RSA_GEN, 2048, HashAlgorithm::NONE, RSAPaddingAlgorithm::PKCS1);
signVerify(AlgoType::RSA_GEN, 1024, HashAlgorithm::NONE, RSAPaddingAlgorithm::PKCS1);
}