<< encrypt2str(algo) << " is different than expected");
}
}
+
+RUNNER_TEST(T7120_yaca_simple_encrypt_invalid_param, YacaTest)
+{
+ Buffer plaintext = random_buffer(1024);
+ char* ciphertext;
+ size_t ciphertext_len;
+
+ yaca_encrypt_algorithm_e algo = YACA_ENCRYPT_AES;
+ yaca_block_cipher_mode_e bcm = YACA_BCM_CBC;
+
+ auto sym_key = generate_key(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_LENGTH_192BIT);
+ auto iv = generate_key(YACA_KEY_TYPE_IV, YACA_KEY_LENGTH_IV_128BIT);
+
+ auto rsa_priv = generate_key(YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_LENGTH_1024BIT);
+ auto rsa_pub = extract_public_key(rsa_priv);
+ auto des_key = generate_key(YACA_KEY_TYPE_DES, YACA_KEY_LENGTH_192BIT);
+ auto dh_params = generate_key(YACA_KEY_TYPE_DH_PARAMS, YACA_KEY_LENGTH_DH_RFC_1024_160);
+ auto dh_priv = generate_key_from_parameters(dh_params);
+ auto bad_iv = generate_key(YACA_KEY_TYPE_IV, YACA_KEY_LENGTH_UNSAFE_8BIT);
+
+ YACA_INVALID_PARAM(yaca_simple_encrypt(static_cast<yaca_encrypt_algorithm_e>(-1), bcm,
+ sym_key.get(), iv.get(), plaintext.data(), plaintext.size(),
+ &ciphertext, &ciphertext_len));
+
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, static_cast<yaca_block_cipher_mode_e>(-1),
+ sym_key.get(), iv.get(), plaintext.data(), plaintext.size(),
+ &ciphertext, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, YACA_BCM_GCM, sym_key.get(), iv.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, YACA_BCM_CCM, sym_key.get(), iv.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, YACA_KEY_NULL, iv.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, iv.get(), iv.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, rsa_priv.get(), iv.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, rsa_pub.get(), iv.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, dh_params.get(), iv.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, dh_priv.get(), iv.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, sym_key.get(), YACA_KEY_NULL,
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, sym_key.get(), bad_iv.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, sym_key.get(), sym_key.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, sym_key.get(), rsa_priv.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, sym_key.get(), rsa_pub.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, sym_key.get(), dh_params.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, sym_key.get(), dh_priv.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, sym_key.get(), des_key.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, &ciphertext_len));
+
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, sym_key.get(), iv.get(),
+ nullptr, plaintext.size(), &ciphertext, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, sym_key.get(), iv.get(),
+ plaintext.data(), 0, &ciphertext, &ciphertext_len));
+
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, sym_key.get(), iv.get(),
+ plaintext.data(), plaintext.size(), nullptr, &ciphertext_len));
+ YACA_INVALID_PARAM(yaca_simple_encrypt(algo, bcm, sym_key.get(), iv.get(),
+ plaintext.data(), plaintext.size(), &ciphertext, nullptr));
+}
+
+RUNNER_TEST(T7130_yaca_simple_decrypt_invalid_param, YacaTest)
+{
+ Buffer ciphertext = random_buffer(1024);
+ char* plaintext;
+ size_t plaintext_len;
+
+ yaca_encrypt_algorithm_e algo = YACA_ENCRYPT_AES;
+ yaca_block_cipher_mode_e bcm = YACA_BCM_CBC;
+
+ auto sym_key = generate_key(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_LENGTH_192BIT);
+ auto iv = generate_key(YACA_KEY_TYPE_IV, YACA_KEY_LENGTH_IV_128BIT);
+
+ auto rsa_priv = generate_key(YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_LENGTH_1024BIT);
+ auto rsa_pub = extract_public_key(rsa_priv);
+ auto des_key = generate_key(YACA_KEY_TYPE_DES, YACA_KEY_LENGTH_192BIT);
+ auto dh_params = generate_key(YACA_KEY_TYPE_DH_PARAMS, YACA_KEY_LENGTH_DH_RFC_1024_160);
+ auto dh_priv = generate_key_from_parameters(dh_params);
+ auto bad_iv = generate_key(YACA_KEY_TYPE_IV, YACA_KEY_LENGTH_UNSAFE_8BIT);
+
+ YACA_INVALID_PARAM(yaca_simple_decrypt(static_cast<yaca_encrypt_algorithm_e>(-1), bcm,
+ sym_key.get(), iv.get(), ciphertext.data(), ciphertext.size(),
+ &plaintext, &plaintext_len));
+
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, static_cast<yaca_block_cipher_mode_e>(-1),
+ sym_key.get(), iv.get(), ciphertext.data(), ciphertext.size(),
+ &plaintext, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, YACA_BCM_GCM, sym_key.get(), iv.get(),
+ ciphertext.data(), ciphertext.size(), &plaintext, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, YACA_BCM_CCM, sym_key.get(), iv.get(),
+ ciphertext.data(), ciphertext.size(), &plaintext, &plaintext_len));
+
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, YACA_KEY_NULL, iv.get(),
+ ciphertext.data(), ciphertext.size(), &plaintext, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, iv.get(), iv.get(),
+ ciphertext.data(), ciphertext.size(), &plaintext, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, rsa_priv.get(), iv.get(),
+ ciphertext.data(), ciphertext.size(), &plaintext, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, rsa_pub.get(), iv.get(),
+ ciphertext.data(), ciphertext.size(), &plaintext, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, dh_params.get(), iv.get(),
+ ciphertext.data(), ciphertext.size(), &plaintext, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, dh_priv.get(), iv.get(),
+ ciphertext.data(), ciphertext.size(), &plaintext, &plaintext_len));
+
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, sym_key.get(), YACA_KEY_NULL,
+ ciphertext.data(), ciphertext.size(), &plaintext, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, sym_key.get(), bad_iv.get(),
+ ciphertext.data(), ciphertext.size(), &plaintext, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, sym_key.get(), sym_key.get(),
+ ciphertext.data(), ciphertext.size(), &plaintext, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, sym_key.get(), rsa_priv.get(),
+ ciphertext.data(), ciphertext.size(), &plaintext, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, sym_key.get(), rsa_pub.get(),
+ ciphertext.data(), ciphertext.size(), &plaintext, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, sym_key.get(), dh_params.get(),
+ ciphertext.data(), ciphertext.size(), &plaintext, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, sym_key.get(), dh_priv.get(),
+ ciphertext.data(), ciphertext.size(),&plaintext, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, sym_key.get(), des_key.get(),
+ ciphertext.data(), ciphertext.size(), &plaintext, &plaintext_len));
+
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, sym_key.get(), iv.get(),
+ nullptr, ciphertext.size(), &plaintext, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, sym_key.get(), iv.get(),
+ ciphertext.data(), 0, &plaintext, &plaintext_len));
+
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, sym_key.get(), iv.get(),
+ ciphertext.data(), ciphertext.size(), nullptr, &plaintext_len));
+ YACA_INVALID_PARAM(yaca_simple_decrypt(algo, bcm, sym_key.get(), iv.get(),
+ ciphertext.data(), ciphertext.size(), &plaintext, nullptr));
+}