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.1 KiB
58 lines
2.1 KiB
#include "../src/secure_channel.h" |
|
#include <string.h> |
|
#include <stdio.h> |
|
|
|
int main() { |
|
printf("=== Debug Test ===\n"); |
|
|
|
struct SC_MYKEYS keys; |
|
for (int i = 0; i < SC_PRIVKEY_SIZE; i++) { |
|
keys.private_key[i] = i; |
|
keys.public_key[i] = i + 64; |
|
} |
|
|
|
sc_context_t ctx; |
|
int result = sc_init_ctx(&ctx, &keys); |
|
printf("sc_init_ctx returned: %d\n", result); |
|
|
|
if (result == SC_OK) { |
|
printf("Context initialized successfully\n"); |
|
printf("initialized: %d, peer_key_set: %d, session_ready: %d\n", |
|
ctx.initialized, ctx.peer_key_set, ctx.session_ready); |
|
|
|
// Manually set peer key and session ready |
|
memcpy(ctx.peer_public_key, keys.public_key, SC_PUBKEY_SIZE); |
|
ctx.peer_key_set = 1; |
|
ctx.session_ready = 1; // This is the key! |
|
printf("Manually set peer key and session ready\n"); |
|
printf("initialized: %d, peer_key_set: %d, session_ready: %d\n", |
|
ctx.initialized, ctx.peer_key_set, ctx.session_ready); |
|
|
|
// Try to encrypt |
|
uint8_t plaintext[] = "Hello"; |
|
uint8_t ciphertext[256]; |
|
size_t ciphertext_len; |
|
|
|
printf("Trying to encrypt...\n"); |
|
int enc_result = sc_encrypt(&ctx, plaintext, 5, 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); |
|
|
|
// Try to decrypt |
|
uint8_t decrypted[256]; |
|
size_t decrypted_len; |
|
printf("Trying to decrypt...\n"); |
|
int dec_result = sc_decrypt(&ctx, ciphertext, ciphertext_len, decrypted, &decrypted_len); |
|
printf("sc_decrypt returned: %d\n", dec_result); |
|
|
|
if (dec_result == SC_OK) { |
|
printf("Decryption successful! Decrypted length: %zu\n", decrypted_len); |
|
printf("Original: '%.*s', Decrypted: '%.*s'\n", 5, plaintext, (int)decrypted_len, decrypted); |
|
} |
|
} |
|
} |
|
|
|
return 0; |
|
}
|
|
|