size_t count() const { return m_params.size(); }
};
-ckmc_param_list_s** EMPTY_PLIST = NULL;
-ckmc_param_list_s* EMPTY_LIST = NULL;
+ckmc_param_list_h* EMPTY_PLIST = NULL;
+ckmc_param_list_h EMPTY_LIST = NULL;
const size_t DEFAULT_IV_LEN = 16;
const size_t DEFAULT_IV_LEN_BITS = 8*DEFAULT_IV_LEN;
RawBufferPtr IV(createRandomBufferCAPI(DEFAULT_IV_LEN), ckmc_buffer_free);
-void assert_list_empty(const ckmc_param_list_s* list)
+void assert_list_empty(ckmc_param_list_h list)
{
const CryptoAlgorithmWrapper* caw = reinterpret_cast<const CryptoAlgorithmWrapper*>(list);
RUNNER_ASSERT_MSG(caw->empty(), "Parameter list is not empty");
}
-void check_int_param(const ckmc_param_list_s* list,
+void check_int_param(ckmc_param_list_h list,
ckmc_param_name_e name,
uint64_t expected)
{
"Param " << name << " expected value: " << expected << " got: " << got);
}
-void check_buffer_param(const ckmc_param_list_s* list,
+void check_buffer_param(ckmc_param_list_h list,
ckmc_param_name_e name,
const ckmc_raw_buffer_s& expected)
{
assert_buffers_equal(expected, *got);
}
-void assert_param_count(const ckmc_param_list_s* list, size_t expected)
+void assert_param_count(ckmc_param_list_h list, size_t expected)
{
RUNNER_ASSERT_MSG(list, "List is NULL");
const CryptoAlgorithmWrapper* caw = reinterpret_cast<const CryptoAlgorithmWrapper*>(list);
RUNNER_TEST(TAP_0040_add_integer_invalid_param)
{
- assert_invalid_param(ckmc_param_list_add_integer,
+ assert_invalid_param(ckmc_param_list_set_integer,
EMPTY_LIST,
CKMC_PARAM_ALGO_TYPE,
CKMC_ALGO_AES_CTR);
ParamListPtr list = createParamListPtr();
- assert_invalid_param(ckmc_param_list_add_integer,
+ assert_invalid_param(ckmc_param_list_set_integer,
list.get(),
static_cast<ckmc_param_name_e>(-1),
CKMC_ALGO_AES_CTR);
RUNNER_TEST(TAP_0050_add_buffer_invalid_param)
{
- assert_invalid_param(ckmc_param_list_add_buffer,
+ assert_invalid_param(ckmc_param_list_set_buffer,
EMPTY_LIST,
CKMC_PARAM_ED_IV,
IV.get());
ParamListPtr list = createParamListPtr();
- assert_invalid_param(ckmc_param_list_add_buffer,
+ assert_invalid_param(ckmc_param_list_set_buffer,
list.get(),
CKMC_PARAM_ED_IV,
nullptr);
ckmc_raw_buffer_s buffer;
buffer.data = nullptr;
buffer.size = 0;
- assert_invalid_param(ckmc_param_list_add_buffer,
+ assert_invalid_param(ckmc_param_list_set_buffer,
list.get(),
CKMC_PARAM_ED_IV,
&buffer);
assert_list_empty(list.get());
- assert_invalid_param(ckmc_param_list_add_buffer,
+ assert_invalid_param(ckmc_param_list_set_buffer,
list.get(),
static_cast<ckmc_param_name_e>(-1),
IV.get());
RUNNER_TEST(TAP_0060_add_param)
{
ParamListPtr list = createParamListPtr();
- assert_positive(ckmc_param_list_add_integer,
+ assert_positive(ckmc_param_list_set_integer,
list.get(),
CKMC_PARAM_ALGO_TYPE,
CKMC_ALGO_AES_GCM);
assert_param_count(list.get(),1);
RawBufferPtr buffer(createRandomBufferCAPI(DEFAULT_IV_LEN), ckmc_buffer_free);
- assert_positive(ckmc_param_list_add_buffer,
+ assert_positive(ckmc_param_list_set_buffer,
list.get(),
CKMC_PARAM_ED_IV,
buffer.get());
RUNNER_TEST(TAP_0070_generate_invalid_param)
{
- assert_invalid_param(ckmc_generate_params, static_cast<ckmc_algo_type_e>(-1), EMPTY_LIST);
+ assert_invalid_param(ckmc_generate_new_params, static_cast<ckmc_algo_type_e>(-1), EMPTY_PLIST);
}
RUNNER_TEST(TAP_0080_generate)
{
- ParamListPtr list = createParamListPtr();
- assert_positive(ckmc_generate_params, CKMC_ALGO_AES_CTR, list.get());
+ ckmc_param_list_h handle = NULL;
+ assert_positive(ckmc_generate_new_params, CKMC_ALGO_AES_CTR, &handle);
+ ParamListPtr list = ParamListPtr(handle, ckmc_param_list_free);
check_int_param(list.get(), CKMC_PARAM_ALGO_TYPE, CKMC_ALGO_AES_CTR);
check_int_param(list.get(), CKMC_PARAM_ED_CTR_LEN, DEFAULT_IV_LEN_BITS);
EncryptionApi* g_api = &g_syncApi;
-EncryptionError apiEncrypt(const ckmc_param_list_s *params,
+EncryptionError apiEncrypt(ckmc_param_list_h params,
const char *key_alias,
const char *password,
const ckmc_raw_buffer_s decrypted,
return g_api->encrypt(params, key_alias, password, decrypted, ppencrypted);
}
-EncryptionError apiDecrypt(const ckmc_param_list_s *params,
+EncryptionError apiDecrypt(ckmc_param_list_h params,
const char *key_alias,
const char *password,
const ckmc_raw_buffer_s encrypted,
void setParam(ParamListPtr& params, ckmc_param_name_e name, ckmc_raw_buffer_s* buffer)
{
- int ret = ckmc_param_list_add_buffer(params.get(), name, buffer);
+ int ret = ckmc_param_list_set_buffer(params.get(), name, buffer);
RUNNER_ASSERT_MSG(ret == CKMC_ERROR_NONE,
"Failed to set param " << name << " error: " << CKMCErrorToString(ret));
}
void setParam(ParamListPtr& params, ckmc_param_name_e name, int integer)
{
- int ret = ckmc_param_list_add_integer(params.get(), name, integer);
+ int ret = ckmc_param_list_set_integer(params.get(), name, integer);
RUNNER_ASSERT_MSG(ret == CKMC_ERROR_NONE,
"Failed to set param " << name << " error: " << CKMCErrorToString(ret));
}
ckmc_raw_buffer_s* encrypted = nullptr;
KeyAliasPair aliases = algo->keyGen(pass);
- ret.params = createParamListPtr();
- assert_positive(ckmc_generate_params, algo->m_type, ret.params.get());
+ ckmc_param_list_h handle = NULL;
+ assert_positive(ckmc_generate_new_params, algo->m_type, &handle);
+ ret.params = ParamListPtr(handle, ckmc_param_list_free);
setParam(ret.params, CKMC_PARAM_ED_IV, createRandomBufferCAPI(DEFAULT_IV_LEN));
assert_crypto_positive(apiEncrypt,
KeyAliasPair aliases = algo->keyGen();
// setup params
- ParamListPtr params = createParamListPtr();
- assert_positive(ckmc_generate_params, algo->m_type, params.get());
+ ckmc_param_list_h handle = NULL;
+ assert_positive(ckmc_generate_new_params, algo->m_type, &handle);
+ ParamListPtr params = ParamListPtr(handle, ckmc_param_list_free);
// invalid encryption
auto test = [&](){
KeyAliasPair aliases = algo->keyGen();
// setup params
- ParamListPtr params = createParamListPtr();
- assert_positive(ckmc_generate_params, algo->m_type, params.get());
+ ckmc_param_list_h handle = NULL;
+ assert_positive(ckmc_generate_new_params, algo->m_type, &handle);
+ ParamListPtr params = ParamListPtr(handle, ckmc_param_list_free);
+
setParam(params, CKMC_PARAM_ED_IV, createRandomBufferCAPI(DEFAULT_IV_LEN));
// set AAD
ckmc_raw_buffer_s* decryptedTmp = nullptr;
// setup params
- ParamListPtr params = createParamListPtr();
- assert_positive(ckmc_generate_params, CKMC_ALGO_AES_GCM, params.get());
+ ckmc_param_list_h handle = NULL;
+ assert_positive(ckmc_generate_new_params, CKMC_ALGO_AES_GCM, &handle);
+ ParamListPtr params = ParamListPtr(handle, ckmc_param_list_free);
setParam(params, CKMC_PARAM_ED_IV, createRandomBufferCAPI(DEFAULT_IV_LEN));
setParam(params, CKMC_PARAM_ED_IV, createRandomBufferCAPI(size));
KeyAliasPair aliases = algo->keyGen();
// setup params
- ParamListPtr params = createParamListPtr();
- assert_positive(ckmc_generate_params, algo->m_type, params.get());
+ ckmc_param_list_h handle = NULL;
+ assert_positive(ckmc_generate_new_params, algo->m_type, &handle);
+ ParamListPtr params = ParamListPtr(handle, ckmc_param_list_free);
setParam(params, CKMC_PARAM_ED_IV, createRandomBufferCAPI(DEFAULT_IV_LEN));
// encryption
KeyAliasPair aliases = algo->keyGen();
// setup params
- ParamListPtr params = createParamListPtr();
- assert_positive(ckmc_generate_params, algo->m_type, params.get());
+ ckmc_param_list_h handle = NULL;
+ assert_positive(ckmc_generate_new_params, algo->m_type, &handle);
+ ParamListPtr params = ParamListPtr(handle, ckmc_param_list_free);
setParam(params, CKMC_PARAM_ED_IV, createRandomBufferCAPI(DEFAULT_IV_LEN));
// encryption
KeyAliasPair aliases = algo->keyGen();
// setup params
- ParamListPtr params = createParamListPtr();
- assert_positive(ckmc_generate_params, algo->m_type, params.get());
+ ckmc_param_list_h handle = NULL;
+ assert_positive(ckmc_generate_new_params, algo->m_type, &handle);
+ ParamListPtr params = ParamListPtr(handle, ckmc_param_list_free);
setParam(params, CKMC_PARAM_ED_IV, createRandomBufferCAPI(DEFAULT_IV_LEN));
std::vector<TagTest> testData = {
// add AES GCM key
KeyAliasPair aliases = algo->keyGen();
- testGcmIvSize(11, aliases, EncryptionError::SERVER_ERROR); // 12B is the smallest
+ testGcmIvSize(11, aliases, EncryptionError::SERVER_ERROR); // 12B is the smallest
testGcmIvSize(12, aliases);
testGcmIvSize(17, aliases);
testGcmIvSize(128, aliases);
ckmc_raw_buffer_s* encrypted = nullptr;
KeyAliasPair aliases = algo->keyGen();
- ret.params = createParamListPtr();
- assert_positive(ckmc_generate_params, algo->m_type, ret.params.get());
+ ckmc_param_list_h handle = NULL;
+ assert_positive(ckmc_generate_new_params, algo->m_type, &handle);
+ ret.params = ParamListPtr(handle, ckmc_param_list_free);
assert_crypto_result(EncryptionError::SERVER_ERROR,
apiEncrypt,
ret.params.get(),
ckmc_raw_buffer_s* encrypted = nullptr;
// setup params
- ParamListPtr params = createParamListPtr();
- assert_positive(ckmc_generate_params, algo->m_type, params.get());
+ ckmc_param_list_h handle = NULL;
+ assert_positive(ckmc_generate_new_params, algo->m_type, &handle);
+ ParamListPtr params = ParamListPtr(handle, ckmc_param_list_free);
setParam(params, CKMC_PARAM_ED_IV, createRandomBufferCAPI(DEFAULT_IV_LEN));
assert_crypto_result(EncryptionError::ALIAS_UNKNOWN,
KeyAliasPair aliases = algo->keyGen();
// setup params
- ParamListPtr params = createParamListPtr();
- assert_positive(ckmc_generate_params, algo->m_type, params.get());
+ ckmc_param_list_h handle = NULL;
+ assert_positive(ckmc_generate_new_params, algo->m_type, &handle);
+ ParamListPtr params = ParamListPtr(handle, ckmc_param_list_free);
setParam(params, CKMC_PARAM_ED_IV, createRandomBufferCAPI(DEFAULT_IV_LEN));
assert_crypto_invalid_param(apiEncrypt,
KeyAliasPair aliases = algo->keyGen();
// setup params
- ParamListPtr params = createParamListPtr();
- assert_positive(ckmc_generate_params, algo->m_type, params.get());
+ ckmc_param_list_h handle = NULL;
+ assert_positive(ckmc_generate_new_params, algo->m_type, &handle);
+ ParamListPtr params = ParamListPtr(handle, ckmc_param_list_free);
setParam(params, CKMC_PARAM_ED_IV, createRandomBufferCAPI(DEFAULT_IV_LEN));
assert_crypto_invalid_param(apiEncrypt,
KeyAliasPair aliases = algo->keyGen();
// setup params
- ParamListPtr params = createParamListPtr();
- assert_positive(ckmc_generate_params, algo->m_type, params.get());
+ ckmc_param_list_h handle = NULL;
+ assert_positive(ckmc_generate_new_params, algo->m_type, &handle);
+ ParamListPtr params = ParamListPtr(handle, ckmc_param_list_free);
setParam(params, CKMC_PARAM_ED_IV, createRandomBufferCAPI(DEFAULT_IV_LEN));
assert_crypto_invalid_param(apiDecrypt,
testEncryptDecryptDifferentKeys(RSA_OAEP_4096, false);
}
-RUNNER_TEST_MULTIPLE(TED_0210_encrypt_decrypt_different_params, SyncEnv, AsyncEnv)
-{
- testAllAlgorithms([](const AlgoBasePtr& algo){
- // prepare buffers
- RawBufferPtr plain = create_raw_buffer(createRandomBufferCAPI(BUF_LEN));
- ckmc_raw_buffer_s* decrypted = nullptr;
-
- // encrypt
- auto ret = encrypt(algo, plain);
-
- // setup different params
- ParamListPtr params = createParamListPtr();
- assert_positive(ckmc_generate_params, CKMC_ALGO_RSA_GEN, params.get());
- setParam(params, CKMC_PARAM_ED_IV, createRandomBufferCAPI(DEFAULT_IV_LEN));
-
- assert_crypto_invalid_param(apiDecrypt,
- params.get(),
- ret.prvKey.c_str(),
- nullptr,
- *ret.encrypted.get(),
- &decrypted);
- });
-}
-
RUNNER_TEST_MULTIPLE(TED_0300_encrypt_decrypt, SyncEnv, AsyncEnv)
{
testAllAlgorithms([](const AlgoBasePtr& algo){
KeyAliasPair aliases = algo->keyGen(nullptr);
// params
- ParamListPtr params = createParamListPtr();
- assert_positive(ckmc_generate_params, algo->m_type, params.get());
+ ckmc_param_list_h handle = NULL;
+ assert_positive(ckmc_generate_new_params, algo->m_type, &handle);
+ ParamListPtr params = ParamListPtr(handle, ckmc_param_list_free);
setParam(params, CKMC_PARAM_ED_IV, createRandomBufferCAPI(DEFAULT_IV_LEN));
// encrypt