+ ckmc_key_free(ppKey);
+}
+
+RUNNER_TEST(TKW_EXPORT_UNEXPORTABLE_WRAPPED_FORM){
+ ParamListPtr params = getDefaultParams(AES_CTR_ALGO);
+ ckmc_key_s *ppKey = nullptr;
+
+ assert_positive(ckmc_create_key_aes, 128, "UNEXPORTABLE_AES", UNEXPORTABLE);
+
+ assert_positive(ckmc_export_wrapped_key,
+ params.get(),
+ AES_KEY_128_ALIAS.c_str(),
+ nullptr,
+ "UNEXPORTABLE_AES",
+ nullptr,
+ &ppKey);
+ ckmc_key_free(ppKey);
+ ckmc_remove_alias("UNEXPORTABLE_AES");
+}
+
+RUNNER_TEST(TKW_IMPORT_EXPORT_WITH_DIF_KEYS_AND_ALGORITHMS){
+ testDiffKeysAndAlgorithms(AES_GCM_ALGO, AES_KEY_128_ALIAS, nullptr, AES_CTR_ALGO, AES_KEY_128_ALIAS, nullptr);
+ testDiffKeysAndAlgorithms(AES_GCM_ALGO, AES_KEY_128_ALIAS, nullptr, AES_GCM_ALGO, AES_KEY_256_ALIAS, nullptr);
+ testDiffKeysAndAlgorithms(AES_GCM_ALGO, AES_KEY_128_ALIAS, nullptr, RSA_OAEP_ALGO, RSA_KEY_1024_PRV_ALIAS, nullptr);
+}
+
+RUNNER_TEST(TKW_AES_GCM_WITH_ADD_IV_PARAM){
+ testImportExportCustomParameters(AES_GCM_ALGO, AES_KEY_128_ALIAS, nullptr, DEFAULT_IV, CKMC_PARAM_ED_AAD, AAD64);
+ testImportExportCustomParameters(AES_GCM_ALGO, AES_KEY_192_ALIAS, nullptr, DEFAULT_IV, CKMC_PARAM_ED_AAD, AAD64);
+ testImportExportCustomParameters(AES_GCM_ALGO, AES_KEY_256_ALIAS, nullptr, DEFAULT_IV, CKMC_PARAM_ED_AAD, AAD64);
+
+ testImportExportCustomParameters(AES_GCM_ALGO, AES_KEY_128_ALIAS, nullptr, DEFAULT_IV, CKMC_PARAM_ED_AAD, AAD32);
+ testImportExportCustomParameters(AES_GCM_ALGO, AES_KEY_192_ALIAS, nullptr, DEFAULT_IV, CKMC_PARAM_ED_AAD, AAD32);
+ testImportExportCustomParameters(AES_GCM_ALGO, AES_KEY_256_ALIAS, nullptr, DEFAULT_IV, CKMC_PARAM_ED_AAD, AAD32);
+
+ testImportExportCustomParameters(AES_GCM_ALGO, AES_KEY_128_ALIAS, nullptr, IV128, CKMC_PARAM_ED_AAD, AAD64);
+ testImportExportCustomParameters(AES_GCM_ALGO, AES_KEY_128_ALIAS, nullptr, IV12, CKMC_PARAM_ED_AAD, AAD64);
+ testImportExportCustomParameters(AES_GCM_ALGO, AES_KEY_128_ALIAS, nullptr, IV15, CKMC_PARAM_ED_AAD, AAD64);
+ testImportExportCustomParameters(AES_GCM_ALGO, AES_KEY_128_ALIAS, nullptr, IV17, CKMC_PARAM_ED_AAD, AAD64);
+}
+
+RUNNER_TEST(TKW_AES_GCM_WITH_TAG_LEN){
+ testImportExportCustomParameters(AES_GCM_ALGO, AES_KEY_128_ALIAS, nullptr, DEFAULT_IV, CKMC_PARAM_ED_TAG_LEN, 96);
+ testImportExportCustomParameters(AES_GCM_ALGO, AES_KEY_192_ALIAS, nullptr, DEFAULT_IV, CKMC_PARAM_ED_TAG_LEN, 104 );
+ testImportExportCustomParameters(AES_GCM_ALGO, AES_KEY_256_ALIAS, nullptr, DEFAULT_IV, CKMC_PARAM_ED_TAG_LEN, 128);
+}
+
+RUNNER_TEST(TKW_IMPORT_EXPORT_RSA_LABEL){
+ RUNNER_IGNORED_MSG("RSA-OAEP labels are not supported in openssl");
+ testImportExportCustomParameters(RSA_OAEP_ALGO, RSA_KEY_1024_PRV_ALIAS, nullptr, DEFAULT_IV, CKMC_PARAM_ED_LABEL, AAD64);
+ testImportExportCustomParameters(RSA_OAEP_ALGO, RSA_KEY_2048_PRV_ALIAS, nullptr, DEFAULT_IV, CKMC_PARAM_ED_LABEL, AAD64);
+ testImportExportCustomParameters(RSA_OAEP_ALGO, RSA_KEY_4096_PRV_ALIAS, nullptr, DEFAULT_IV, CKMC_PARAM_ED_LABEL, AAD64);
+}
+
+RUNNER_TEST(TKW_RSA_WRAPPED_KEY){
+ ckmc_raw_buffer_s *encrypted = nullptr;
+ ckmc_raw_buffer_s *rsaKeyData = nullptr;
+ ckmc_raw_buffer_s *decrypted = nullptr;
+ ckmc_raw_buffer_s *finalData = nullptr;
+
+ ckmc_key_s *ppKey = nullptr;
+ ckmc_key_s *rsaKey = nullptr;
+ ckmc_key_s *wrappedRsaKey = nullptr;
+
+ ParamListPtr params = getDefaultParams(AES_CTR_ALGO);
+
+ assert_positive(ckmc_create_key_pair_rsa, 1024, "RPV", "RPB", EXPORTABLE, EXPORTABLE);
+ assert_positive(ckmc_get_key, "RPV", nullptr, &rsaKey);
+ assert_positive(ckmc_buffer_new, rsaKey->raw_key, rsaKey->key_size, &rsaKeyData);
+
+ assert_positive(ckmc_encrypt_data,
+ params.get(),
+ AES_KEY_256_ALIAS.c_str(),
+ nullptr,
+ *rsaKeyData,
+ &encrypted);
+
+ assert_positive(ckmc_key_new,
+ encrypted->data,
+ encrypted->size,
+ CKMC_KEY_RSA_PRIVATE,
+ nullptr,
+ &wrappedRsaKey);
+
+ assert_positive(ckmc_import_wrapped_key,
+ params.get(),
+ AES_KEY_256_ALIAS.c_str(),
+ nullptr,
+ IMPORTED_ALIAS.c_str(),
+ wrappedRsaKey,
+ EXPORTABLE);
+
+ assert_positive(ckmc_export_wrapped_key,
+ params.get(),
+ AES_KEY_256_ALIAS.c_str(),
+ nullptr,
+ IMPORTED_ALIAS.c_str(),
+ nullptr,
+ &ppKey);
+
+ assert_positive(ckmc_buffer_new,
+ ppKey->raw_key,
+ ppKey->key_size,
+ &finalData);
+
+ assert_positive(ckmc_decrypt_data,
+ params.get(),
+ AES_KEY_256_ALIAS.c_str(),
+ nullptr,
+ *finalData,
+ &decrypted);
+
+ assert_buffers_equal(rsaKeyData, decrypted);
+
+ ckmc_buffer_free(rsaKeyData);
+ ckmc_buffer_free(finalData);
+ ckmc_buffer_free(decrypted);
+ ckmc_buffer_free(encrypted);
+ ckmc_key_free(wrappedRsaKey);
+ ckmc_key_free(rsaKey);
+ ckmc_key_free(ppKey);
+ ckmc_remove_key(IMPORTED_ALIAS.c_str());
+ ckmc_remove_key("RPB");
+ ckmc_remove_key("RPV");