Version v0.3.9 - fix truerng

This commit is contained in:
2025-09-22 13:04:06 -04:00
parent 5e1de92454
commit a0ce6f3253
3 changed files with 68 additions and 47 deletions

BIN
otp-arm64 Executable file

Binary file not shown.

BIN
otp-x86_64 Executable file

Binary file not shown.

115
otp.c
View File

@@ -331,7 +331,7 @@ int interactive_mode(void) {
void show_main_menu(void) { void show_main_menu(void) {
printf("\n=========================== Main Menu - OTP v0.3.7 ===========================\n\n"); printf("\n=========================== Main Menu - OTP v0.3.8 ===========================\n\n");
printf(" \033[4mT\033[0mext encrypt\n"); //TEXT ENCRYPT printf(" \033[4mT\033[0mext encrypt\n"); //TEXT ENCRYPT
printf(" \033[4mF\033[0mile encrypt\n"); //FILE ENCRYPT printf(" \033[4mF\033[0mile encrypt\n"); //FILE ENCRYPT
@@ -3243,7 +3243,7 @@ int generate_ascii_armor(const char* chksum, uint64_t offset, const unsigned cha
strcpy(*ascii_output, "-----BEGIN OTP MESSAGE-----\n"); strcpy(*ascii_output, "-----BEGIN OTP MESSAGE-----\n");
char temp_line[256]; char temp_line[256];
snprintf(temp_line, sizeof(temp_line), "Version: v0.3.7\n"); snprintf(temp_line, sizeof(temp_line), "Version: v0.3.8\n");
strcat(*ascii_output, temp_line); strcat(*ascii_output, temp_line);
snprintf(temp_line, sizeof(temp_line), "Pad-ChkSum: %s\n", chksum); snprintf(temp_line, sizeof(temp_line), "Pad-ChkSum: %s\n", chksum);
@@ -4729,51 +4729,72 @@ int handle_add_entropy_to_pad(const char* pad_chksum) {
return 1; return 1;
} }
// Get entropy amount size_t target_bytes;
printf("\nEntropy collection options:\n");
printf(" 1. Recommended (2048 bytes) - Optimal security\n");
printf(" 2. Minimum (1024 bytes) - Good security\n");
printf(" 3. Maximum (4096 bytes) - Maximum security\n");
printf(" 4. Custom amount\n");
printf("Enter choice (1-4): ");
char amount_input[10]; // For TrueRNG, automatically use the full pad size
if (!fgets(amount_input, sizeof(amount_input), stdin)) { if (entropy_source == ENTROPY_SOURCE_TRUERNG) {
printf("Error: Failed to read input\n"); // Get the pad file size
return 1; char pad_path[1024];
} char state_path[1024];
get_pad_path(pad_chksum, pad_path, state_path);
size_t target_bytes = 2048; // Default
int amount_choice = atoi(amount_input); struct stat pad_stat;
if (stat(pad_path, &pad_stat) != 0) {
switch (amount_choice) { printf("Error: Cannot get pad file size\n");
case 1: return 1;
target_bytes = 2048; }
break;
case 2: target_bytes = (size_t)pad_stat.st_size;
target_bytes = 1024; printf("\nTrueRNG selected - will enhance entire pad with hardware entropy\n");
break; printf("Pad size: %.2f GB (%zu bytes)\n",
case 3: (double)target_bytes / (1024.0 * 1024.0 * 1024.0), target_bytes);
target_bytes = 4096; } else {
break; // For other entropy sources, show the selection menu
case 4: printf("\nEntropy collection options:\n");
printf("Enter custom amount (512-8192 bytes): "); printf(" 1. Recommended (2048 bytes) - Optimal security\n");
char custom_input[32]; printf(" 2. Minimum (1024 bytes) - Good security\n");
if (!fgets(custom_input, sizeof(custom_input), stdin)) { printf(" 3. Maximum (4096 bytes) - Maximum security\n");
printf("Error: Failed to read input\n"); printf(" 4. Custom amount\n");
return 1; printf("Enter choice (1-4): ");
}
char amount_input[10];
size_t custom_amount = (size_t)atoi(custom_input); if (!fgets(amount_input, sizeof(amount_input), stdin)) {
if (custom_amount < 512 || custom_amount > 8192) { printf("Error: Failed to read input\n");
printf("Error: Invalid amount. Must be between 512 and 8192 bytes.\n"); return 1;
return 1; }
}
target_bytes = custom_amount; target_bytes = 2048; // Default
break; int amount_choice = atoi(amount_input);
default:
target_bytes = 2048; // Default to recommended switch (amount_choice) {
break; case 1:
target_bytes = 2048;
break;
case 2:
target_bytes = 1024;
break;
case 3:
target_bytes = 4096;
break;
case 4:
printf("Enter custom amount (512-8192 bytes): ");
char custom_input[32];
if (!fgets(custom_input, sizeof(custom_input), stdin)) {
printf("Error: Failed to read input\n");
return 1;
}
size_t custom_amount = (size_t)atoi(custom_input);
if (custom_amount < 512 || custom_amount > 8192) {
printf("Error: Invalid amount. Must be between 512 and 8192 bytes.\n");
return 1;
}
target_bytes = custom_amount;
break;
default:
target_bytes = 2048; // Default to recommended
break;
}
} }
printf("\nCollecting %zu bytes of entropy from selected source...\n", target_bytes); printf("\nCollecting %zu bytes of entropy from selected source...\n", target_bytes);
@@ -4824,7 +4845,7 @@ int handle_add_entropy_to_pad(const char* pad_chksum) {
void print_usage(const char* program_name) { void print_usage(const char* program_name) {
printf("OTP Cipher - One Time Pad Implementation v0.3.7\n"); printf("OTP Cipher - One Time Pad Implementation v0.3.8\n");
printf("Built for testing entropy system\n"); printf("Built for testing entropy system\n");
printf("Usage:\n"); printf("Usage:\n");
printf(" %s - Interactive mode\n", program_name); printf(" %s - Interactive mode\n", program_name);