int ITc_yaca_decrypt_update_finalize_p(void)
{
START_TEST;
-
+
yaca_encrypt_algorithm_e eEncryptAlgorithm = YACA_ENCRYPT_AES;
yaca_block_cipher_mode_e eBlockCipherMode = YACA_BCM_GCM;
yaca_key_type_e key_type = YACA_KEY_TYPE_SYMMETRIC;
// Key generation
nRet = yaca_key_generate(key_type, hKeyBitLen, &hKey);
PRINT_RESULT(YACA_ERROR_NONE, nRet, "yaca_key_generate", YacaGetError(nRet));
- CHECK_HANDLE(hKey, "yaca_key_generate");
+ CHECK_HANDLE(hKey, "yaca_key_generate");
// IV generation
nRet = yaca_key_generate(YACA_KEY_TYPE_IV, iv_bit_len, &iv);
PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_key_generate", YacaGetError(nRet), yaca_key_destroy(hKey));
CHECK_HANDLE(iv, "yaca_key_generate");
-
+
nRet = yaca_zalloc(aad_len, (void**)&aad);
PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_zalloc", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_key_destroy(iv));
nRet = yaca_randomize_bytes(aad, aad_len);
PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_randomize_bytes", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(aad);yaca_key_destroy(iv));
-
- nRet = yaca_zalloc(tag_len, (void**)&tag);
- PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_zalloc", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(aad);yaca_key_destroy(iv));
// Encryption
nRet = yaca_encrypt_initialize(&hContext, eEncryptAlgorithm, eBlockCipherMode, hKey, iv);
- PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_encrypt_initialize", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(aad);yaca_free(tag);yaca_key_destroy(iv));
+ PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_encrypt_initialize", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(aad);yaca_key_destroy(iv));
nRet = yaca_context_set_property(hContext, YACA_PROPERTY_GCM_AAD, aad, aad_len);
- PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_context_set_property", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(tag);yaca_free(aad);yaca_context_destroy(hContext);yaca_key_destroy(iv));
+ PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_context_set_property", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(aad);yaca_context_destroy(hContext);yaca_key_destroy(iv));
nRet = yaca_context_get_output_length(hContext, LOREM4096_SIZE, &output_len);
- PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_context_get_output_length", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(tag);yaca_free(aad);yaca_context_destroy(hContext);yaca_key_destroy(iv));
+ PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_context_get_output_length", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(aad);yaca_context_destroy(hContext);yaca_key_destroy(iv));
nRet = yaca_context_get_output_length(hContext, 0, &block_len);
- PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_context_get_output_length", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(tag);yaca_free(aad);yaca_context_destroy(hContext);yaca_key_destroy(iv));
+ PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_context_get_output_length", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(aad);yaca_context_destroy(hContext);yaca_key_destroy(iv));
enc_len = output_len + block_len;
nRet = yaca_malloc(enc_len, (void**)&enc);
- PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_malloc", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(tag);yaca_free(aad);yaca_context_destroy(hContext);yaca_key_destroy(iv));
+ PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_malloc", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(aad);yaca_context_destroy(hContext);yaca_key_destroy(iv));
written_len = enc_len;
nRet = yaca_encrypt_update(hContext, lorem4096, LOREM4096_SIZE, enc, &written_len);
- PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_encrypt_update", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(tag);yaca_free(aad);yaca_free(enc);yaca_context_destroy(hContext);yaca_key_destroy(iv));
-
+ PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_encrypt_update", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(aad);yaca_free(enc);yaca_context_destroy(hContext);yaca_key_destroy(iv));
+
rem = enc_len - written_len;
nRet = yaca_encrypt_finalize(hContext, enc + written_len, &rem);
- PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_encrypt_finalize", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(tag);yaca_free(aad);yaca_free(enc);yaca_context_destroy(hContext);yaca_key_destroy(iv));
+ PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_encrypt_finalize", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(aad);yaca_free(enc);yaca_context_destroy(hContext);yaca_key_destroy(iv));
enc_len = rem + written_len;
// Set the tag length and get the tag after final encryption
nRet = yaca_context_set_property(hContext, YACA_PROPERTY_GCM_TAG_LEN, (void*)&tag_len, sizeof(tag_len));
- PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_context_set_property", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(tag);yaca_free(aad);yaca_free(enc);yaca_context_destroy(hContext);yaca_key_destroy(iv));
+ PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_context_set_property", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(aad);yaca_free(enc);yaca_context_destroy(hContext);yaca_key_destroy(iv));
- nRet = yaca_context_get_property(hContext, YACA_PROPERTY_GCM_TAG, (void**)tag, &tag_len);
- PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_context_get_property", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(tag);yaca_free(aad);yaca_free(enc);yaca_context_destroy(hContext);yaca_key_destroy(iv));
+ nRet = yaca_context_get_property(hContext, YACA_PROPERTY_GCM_TAG, (void**)&tag, &tag_len);
+ PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_context_get_property", YacaGetError(nRet), yaca_key_destroy(hKey);yaca_free(aad);yaca_free(enc);yaca_context_destroy(hContext);yaca_key_destroy(iv));
yaca_context_destroy(hContext);
hContext = YACA_CONTEXT_NULL;
//Target API
nRet = yaca_decrypt_finalize(hContext, dec + written_len, &rem);
PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_decrypt_finalize", YacaGetError(nRet), yaca_context_destroy(hContext);yaca_key_destroy(iv);yaca_free(tag);yaca_free(aad);yaca_free(enc);yaca_free(dec);yaca_key_destroy(hKey));
-
+
dec_len = rem + written_len;
yaca_free(enc);
yaca_context_destroy(hContext);
yaca_key_destroy(iv);
yaca_key_destroy(hKey);
-
+
return 0;
}
/** @} */
-/** @} */
\ No newline at end of file
+/** @} */
ret = yaca_randomize_bytes(aad, aad_len);
assert_eq(ret, YACA_ERROR_NONE);
- ret = yaca_zalloc(tag_len, (void**)&tag);
- assert_eq(ret, YACA_ERROR_NONE);
-
// Encryption
ret = yaca_encrypt_initialize(&ctx, algo, bcm, key, iv);
assert_eq(ret, YACA_ERROR_NONE);
ret = yaca_context_set_property(ctx, YACA_PROPERTY_GCM_TAG_LEN, (void*)&tag_len, sizeof(tag_len));
assert_eq(ret, YACA_ERROR_NONE);
- ret = yaca_context_get_property(ctx, YACA_PROPERTY_GCM_TAG, (void**)tag, &tag_len);
+ ret = yaca_context_get_property(ctx, YACA_PROPERTY_GCM_TAG, (void**)&tag, &tag_len);
assert_eq(ret, YACA_ERROR_NONE);
yaca_context_destroy(ctx);
assert_eq(yaca_randomize_bytes(aad, aad_len), YACA_ERROR_NONE);
- assert_eq(yaca_zalloc(tag_len, (void**)&tag), YACA_ERROR_NONE);
-
/* Encryption */
{
assert_eq(yaca_encrypt_initialize(&ctx, algo, bcm, key, iv), YACA_ERROR_NONE);
enc_len += written_len;
/* Get the tag after final encryption */
- assert_eq(yaca_context_get_property(ctx, YACA_PROPERTY_CCM_TAG, (void**)tag, &tag_len), YACA_ERROR_NONE);
+ assert_eq(yaca_context_get_property(ctx, YACA_PROPERTY_CCM_TAG, (void**)&tag, &tag_len), YACA_ERROR_NONE);
yaca_context_destroy(ctx);
ctx = YACA_CONTEXT_NULL;