#include #include #include #include #include #define SC_TAG_SIZE 8 #define SC_SESSION_KEY_SIZE 16 int main() { printf("=== Basic Crypto Test ===\n"); struct tc_aes_key_sched_struct sched; uint8_t test_key[SC_SESSION_KEY_SIZE] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10}; if (tc_aes128_set_encrypt_key(&sched, test_key) != TC_CRYPTO_SUCCESS) { printf("❌ AES key setup failed\n"); return 1; } printf("✅ AES key setup successful\n"); struct tc_ccm_mode_struct ccm_state; TCCcmMode_t c = &ccm_state; uint8_t nonce[13] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD}; if (tc_ccm_config(c, &sched, nonce, 13, SC_TAG_SIZE) != TC_CRYPTO_SUCCESS) { printf("❌ CCM config failed\n"); return 1; } printf("✅ CCM config successful\n"); uint8_t plaintext[] = "Hello, World!"; uint8_t ciphertext[64]; size_t plaintext_len = sizeof(plaintext) - 1; size_t ciphertext_len = plaintext_len + SC_TAG_SIZE; if (tc_ccm_generation_encryption(ciphertext, ciphertext_len, NULL, 0, plaintext, plaintext_len, c) != TC_CRYPTO_SUCCESS) { printf("❌ Encryption failed\n"); return 1; } printf("✅ Encryption successful\n"); uint8_t decrypted[64]; if (tc_ccm_decryption_verification(decrypted, plaintext_len, NULL, 0, ciphertext, ciphertext_len, c) != TC_CRYPTO_SUCCESS) { printf("❌ Decryption failed\n"); return 1; } printf("✅ Decryption successful\n"); if (memcmp(plaintext, decrypted, plaintext_len) == 0) { printf("✅ Crypto test PASSED\n"); return 0; } else { printf("❌ Data mismatch\n"); return 1; } }