You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.2 KiB
58 lines
2.2 KiB
#include <tinycrypt/aes.h> |
|
#include <tinycrypt/ccm_mode.h> |
|
#include <tinycrypt/constants.h> |
|
#include <string.h> |
|
#include <stdio.h> |
|
|
|
int main() { |
|
printf("=== Detailed Debug Test ===\n"); |
|
|
|
// Test AES key setup |
|
struct tc_aes_key_sched_struct sched; |
|
uint8_t test_key[16] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
|
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10}; |
|
|
|
printf("Testing AES key setup...\n"); |
|
int aes_result = tc_aes128_set_encrypt_key(&sched, test_key); |
|
printf("tc_aes128_set_encrypt_key returned: %d\n", aes_result); |
|
printf("TC_CRYPTO_SUCCESS = %d\n", TC_CRYPTO_SUCCESS); |
|
|
|
if (aes_result == TC_CRYPTO_SUCCESS) { |
|
printf("✓ AES key setup successful\n"); |
|
|
|
// Test CCM config |
|
struct tc_ccm_mode_struct ccm_state; |
|
uint8_t nonce[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; |
|
|
|
printf("Testing CCM config...\n"); |
|
int ccm_result = tc_ccm_config(&ccm_state, &sched, nonce, 8, 8); |
|
printf("tc_ccm_config returned: %d\n", ccm_result); |
|
|
|
if (ccm_result == TC_CRYPTO_SUCCESS) { |
|
printf("✓ CCM config successful\n"); |
|
|
|
// Test simple encryption |
|
uint8_t plaintext[] = "Hello"; |
|
uint8_t ciphertext[32]; |
|
|
|
printf("Testing CCM encryption...\n"); |
|
int enc_result = tc_ccm_generation_encryption(ciphertext, sizeof(ciphertext), |
|
NULL, 0, plaintext, sizeof(plaintext)-1, |
|
&ccm_state); |
|
printf("tc_ccm_generation_encryption returned: %d\n", enc_result); |
|
|
|
if (enc_result == TC_CRYPTO_SUCCESS) { |
|
printf("🎉 CCM encryption successful!\n"); |
|
printf("Ciphertext length: %zu\n", sizeof(plaintext)-1 + 8); // data + tag |
|
} else { |
|
printf("❌ CCM encryption failed\n"); |
|
} |
|
} else { |
|
printf("❌ CCM config failed\n"); |
|
} |
|
} else { |
|
printf("❌ AES key setup failed\n"); |
|
} |
|
|
|
return 0; |
|
}
|
|
|