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.
76 lines
3.1 KiB
76 lines
3.1 KiB
#include <tinycrypt/aes.h> |
|
#include <tinycrypt/ccm_mode.h> |
|
#include <tinycrypt/constants.h> |
|
#include <string.h> |
|
#include <stdio.h> |
|
|
|
#define SC_NONCE_SIZE 8 |
|
#define SC_TAG_SIZE 8 |
|
|
|
int main() { |
|
printf("=== Fixed 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); |
|
|
|
if (aes_result == TC_CRYPTO_SUCCESS) { |
|
printf("✓ AES key setup successful\n"); |
|
|
|
// Test CCM config with correct parameters |
|
struct tc_ccm_mode_struct ccm_state; |
|
uint8_t nonce[SC_NONCE_SIZE] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; |
|
|
|
printf("Testing CCM config...\n"); |
|
printf("Nonce size: %d, Tag size: %d\n", SC_NONCE_SIZE, SC_TAG_SIZE); |
|
int ccm_result = tc_ccm_config(&ccm_state, &sched, nonce, SC_NONCE_SIZE, SC_TAG_SIZE); |
|
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 (data + tag)\n", sizeof(plaintext)-1 + SC_TAG_SIZE); |
|
|
|
// Test decryption |
|
uint8_t decrypted[32]; |
|
printf("Testing CCM decryption...\n"); |
|
int dec_result = tc_ccm_decryption_verification(decrypted, sizeof(plaintext)-1, |
|
NULL, 0, ciphertext, sizeof(plaintext)-1 + SC_TAG_SIZE, |
|
&ccm_state); |
|
printf("tc_ccm_decryption_verification returned: %d\n", dec_result); |
|
|
|
if (dec_result == TC_CRYPTO_SUCCESS) { |
|
printf("🎉 CCM decryption successful!\n"); |
|
printf("Decrypted: '%.*s'\n", (int)(sizeof(plaintext)-1), decrypted); |
|
} else { |
|
printf("❌ CCM decryption failed\n"); |
|
} |
|
} else { |
|
printf("❌ CCM encryption failed\n"); |
|
} |
|
} else { |
|
printf("❌ CCM config failed\n"); |
|
} |
|
} else { |
|
printf("❌ AES key setup failed\n"); |
|
} |
|
|
|
return 0; |
|
}
|
|
|