Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 68a2a0c252 | |||
| bb17b0a7be |
92
otp.c
92
otp.c
@@ -101,37 +101,46 @@ int interactive_mode(void) {
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
show_main_menu();
|
show_main_menu();
|
||||||
int choice = get_user_choice(1, 6);
|
char input[10];
|
||||||
|
if (fgets(input, sizeof(input), stdin)) {
|
||||||
|
char choice = toupper(input[0]);
|
||||||
|
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
case 1:
|
case 'G':
|
||||||
handle_generate_menu();
|
handle_generate_menu();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 'E':
|
||||||
handle_encrypt_menu();
|
handle_encrypt_menu();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 'D':
|
||||||
handle_decrypt_menu();
|
handle_decrypt_menu();
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 'L':
|
||||||
list_available_pads();
|
list_available_pads();
|
||||||
break;
|
break;
|
||||||
case 5: {
|
case 'S': {
|
||||||
printf("Enter pad checksum (or prefix): ");
|
printf("Enter pad checksum (or prefix): ");
|
||||||
char input[MAX_HASH_LENGTH];
|
char input[MAX_HASH_LENGTH];
|
||||||
if (fgets(input, sizeof(input), stdin)) {
|
if (fgets(input, sizeof(input), stdin)) {
|
||||||
input[strcspn(input, "\n")] = 0;
|
input[strcspn(input, "\n")] = 0;
|
||||||
char* hash = find_pad_by_prefix(input);
|
char* hash = find_pad_by_prefix(input);
|
||||||
if (hash) {
|
if (hash) {
|
||||||
show_pad_info(hash);
|
show_pad_info(hash);
|
||||||
free(hash);
|
free(hash);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
case 'X':
|
||||||
|
printf("Goodbye!\n");
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
printf("Invalid option. Please select G, E, D, L, S, or X.\n");
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
case 6:
|
} else {
|
||||||
printf("Goodbye!\n");
|
printf("Error reading input. Please try again.\n");
|
||||||
return 0;
|
continue;
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
@@ -176,13 +185,13 @@ int command_line_mode(int argc, char* argv[]) {
|
|||||||
|
|
||||||
void show_main_menu(void) {
|
void show_main_menu(void) {
|
||||||
printf("=== Main Menu ===\n");
|
printf("=== Main Menu ===\n");
|
||||||
printf("1. Generate new pad\n");
|
printf("\033[4mG\033[0menerate new pad\n");
|
||||||
printf("2. Encrypt message\n");
|
printf("\033[4mE\033[0mncrypt message\n");
|
||||||
printf("3. Decrypt message\n");
|
printf("\033[4mD\033[0mecrypt message\n");
|
||||||
printf("4. List available pads\n");
|
printf("\033[4mL\033[0mist available pads\n");
|
||||||
printf("5. Show pad information\n");
|
printf("\033[4mS\033[0mhow pad information\n");
|
||||||
printf("6. Exit\n");
|
printf("E\033[4mx\033[0mit\n");
|
||||||
printf("\nSelect option (1-6): ");
|
printf("\nSelect option (G/E/D/L/S/X): ");
|
||||||
}
|
}
|
||||||
|
|
||||||
int handle_generate_menu(void) {
|
int handle_generate_menu(void) {
|
||||||
@@ -764,11 +773,11 @@ int generate_pad_with_entropy(uint64_t size_bytes, int display_progress, int use
|
|||||||
printf("Warning: Cannot set pad file to read-only\n");
|
printf("Warning: Cannot set pad file to read-only\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize state file with offset 0
|
// Initialize state file with offset 32 (first 32 bytes used for checksum encryption)
|
||||||
FILE* state_file = fopen(state_path, "wb");
|
FILE* state_file = fopen(state_path, "wb");
|
||||||
if (state_file) {
|
if (state_file) {
|
||||||
uint64_t zero = 0;
|
uint64_t reserved_bytes = 32;
|
||||||
fwrite(&zero, sizeof(uint64_t), 1, state_file);
|
fwrite(&reserved_bytes, sizeof(uint64_t), 1, state_file);
|
||||||
fclose(state_file);
|
fclose(state_file);
|
||||||
} else {
|
} else {
|
||||||
printf("Error: Failed to create state file\n");
|
printf("Error: Failed to create state file\n");
|
||||||
@@ -816,6 +825,15 @@ int encrypt_text(const char* pad_identifier) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure we never encrypt before offset 32 (reserved for checksum encryption)
|
||||||
|
if (current_offset < 32) {
|
||||||
|
printf("Warning: State offset below reserved area, adjusting to 32\n");
|
||||||
|
current_offset = 32;
|
||||||
|
if (write_state_offset(pad_hash, current_offset) != 0) {
|
||||||
|
printf("Warning: Failed to update state file\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate XOR checksum of pad file
|
// Calculate XOR checksum of pad file
|
||||||
if (calculate_checksum(pad_path, hash_hex) != 0) {
|
if (calculate_checksum(pad_path, hash_hex) != 0) {
|
||||||
printf("Error: Cannot calculate pad checksum\n");
|
printf("Error: Cannot calculate pad checksum\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user