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.
65 lines
2.3 KiB
65 lines
2.3 KiB
#include "../src/secure_channel.h" |
|
#include <string.h> |
|
#include <stdio.h> |
|
|
|
int main() { |
|
printf("=== Debug Encryption Test ===\n"); |
|
|
|
// Create test keys |
|
struct SC_MYKEYS keys; |
|
for (int i = 0; i < SC_PRIVKEY_SIZE; i++) { |
|
keys.private_key[i] = i; |
|
keys.public_key[i] = i + 64; |
|
} |
|
|
|
// Initialize context |
|
sc_context_t ctx; |
|
int result = sc_init_ctx(&ctx, &keys); |
|
printf("✓ Context initialized: %d\n", result); |
|
|
|
// Set up for encryption (manual setup to bypass ECC issues) |
|
memcpy(ctx.peer_public_key, keys.public_key, SC_PUBKEY_SIZE); |
|
ctx.peer_key_set = 1; |
|
ctx.session_ready = 1; |
|
|
|
// Set a test session key manually (16 bytes for AES-128) |
|
uint8_t test_session_key[SC_SESSION_KEY_SIZE]; |
|
for (int i = 0; i < SC_SESSION_KEY_SIZE; i++) { |
|
test_session_key[i] = i + 100; |
|
} |
|
memcpy(ctx.session_key, test_session_key, SC_SESSION_KEY_SIZE); |
|
printf("✓ Set test session key\n"); |
|
|
|
printf("Context state:\n"); |
|
printf(" initialized: %d\n", ctx.initialized); |
|
printf(" peer_key_set: %d\n", ctx.peer_key_set); |
|
printf(" session_ready: %d\n", ctx.session_ready); |
|
printf(" tx_counter: %llu\n", (unsigned long long)ctx.tx_counter); |
|
|
|
// Test encryption step by step |
|
uint8_t plaintext[] = "Hello"; |
|
uint8_t ciphertext[256]; |
|
size_t ciphertext_len; |
|
|
|
printf("\nTrying to encrypt '%.*s' (%d bytes)...\n", |
|
(int)sizeof(plaintext)-1, plaintext, (int)sizeof(plaintext)-1); |
|
|
|
int enc_result = sc_encrypt(&ctx, plaintext, sizeof(plaintext)-1, ciphertext, &ciphertext_len); |
|
printf("sc_encrypt returned: %d\n", enc_result); |
|
|
|
if (enc_result == SC_OK) { |
|
printf("🎉 Encryption successful! Ciphertext length: %zu\n", ciphertext_len); |
|
} else { |
|
printf("❌ Encryption failed with code: %d\n", enc_result); |
|
|
|
// Check what the error codes mean |
|
printf("Error code meanings:\n"); |
|
printf(" SC_ERR_INVALID_ARG: %d\n", SC_ERR_INVALID_ARG); |
|
printf(" SC_ERR_CRYPTO: %d\n", SC_ERR_CRYPTO); |
|
printf(" SC_ERR_NOT_INITIALIZED: %d\n", SC_ERR_NOT_INITIALIZED); |
|
printf(" SC_ERR_AUTH_FAILED: %d\n", SC_ERR_AUTH_FAILED); |
|
printf(" SC_ERR_CRC_FAILED: %d\n", SC_ERR_CRC_FAILED); |
|
} |
|
|
|
return 0; |
|
}
|
|
|