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;
+ size_t hKeyBitLen = YACA_KEY_LENGTH_256BIT;
+ size_t iv_bit_len = YACA_KEY_LENGTH_IV_128BIT;
+
yaca_context_h hContext = YACA_CONTEXT_NULL;
yaca_key_h hKey = YACA_KEY_NULL;
- yaca_padding_e padding = YACA_PADDING_PKCS1_PSS;
- yaca_key_type_e type = YACA_KEY_TYPE_RSA_PRIV;
- yaca_padding_e *eReturnedPadding = NULL;
- size_t nReturnedSize = 0;
+ yaca_key_h iv = YACA_KEY_NULL;
+
+ char *enc = NULL;
+ char *dec = NULL;
+ size_t enc_len;
+ size_t dec_len;
+
+ char *aad = NULL;
+ char *tag = NULL;
+ size_t aad_len = 16;
+ size_t tag_len = 16;
- int nRet = yaca_key_generate(type, YACA_KEY_LENGTH_1024BIT, &hKey);
+ size_t block_len;
+ size_t output_len;
+ size_t written_len;
+ size_t rem;
+
+ int nRet = YACA_ERROR_NONE;
+
+ // 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");
-
- nRet = yaca_sign_initialize(&hContext, YACA_DIGEST_SHA512, hKey);
- PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_sign_initialize", YacaGetError(nRet), yaca_key_destroy(hKey));
- CHECK_HANDLE(hContext, "yaca_sign_initialize");
+ 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");
- //Target API
- nRet = yaca_context_set_property(hContext, YACA_PROPERTY_PADDING, (void*)(&padding), sizeof(padding));
- PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_context_set_property", YacaGetError(nRet), yaca_key_destroy(hKey));
+ 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));
- //Target API
- nRet = yaca_context_get_property(hContext, YACA_PROPERTY_PADDING, (void**)&eReturnedPadding, &nReturnedSize);
- PRINT_RESULT_CLEANUP(YACA_ERROR_NONE, nRet, "yaca_context_set_property", YacaGetError(nRet), yaca_key_destroy(hKey));
+ 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));
+
+ 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));
+
+ 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));
+ yaca_free(enc);
+ yaca_free(dec);
+ yaca_free(tag);
+ yaca_free(aad);
+ yaca_context_destroy(hContext);
+ yaca_key_destroy(iv);
yaca_key_destroy(hKey);
- yaca_context_destroy(hContext);
return 0;
}
/** @} */
-/** @} */
\ No newline at end of file
+/** @} */