Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f87b2dbd8f | |||
| 1582c88be5 | |||
| 2ce3e823c5 |
BIN
otp-x86_64
BIN
otp-x86_64
Binary file not shown.
46
otp.c
46
otp.c
@@ -405,7 +405,7 @@ int interactive_mode(void) {
|
|||||||
|
|
||||||
void show_main_menu(void) {
|
void show_main_menu(void) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
print_centered_header("Main Menu - OTP v0.3.11", 0);
|
print_centered_header("Main Menu - OTP v0.3.14", 0);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
printf(" \033[4mT\033[0mext encrypt\n"); //TEXT ENCRYPT
|
printf(" \033[4mT\033[0mext encrypt\n"); //TEXT ENCRYPT
|
||||||
@@ -860,13 +860,13 @@ int generate_pad(uint64_t size_bytes, int display_progress) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char temp_filename[64];
|
char temp_filename[1024];
|
||||||
char pad_path[MAX_HASH_LENGTH + 20];
|
char pad_path[MAX_HASH_LENGTH + 20];
|
||||||
char state_path[MAX_HASH_LENGTH + 20];
|
char state_path[MAX_HASH_LENGTH + 20];
|
||||||
char chksum_hex[MAX_HASH_LENGTH];
|
char chksum_hex[MAX_HASH_LENGTH];
|
||||||
|
|
||||||
// Create temporary filename
|
// Create temporary filename in the pads directory to avoid cross-filesystem issues
|
||||||
snprintf(temp_filename, sizeof(temp_filename), "temp_%ld.pad", time(NULL));
|
snprintf(temp_filename, sizeof(temp_filename), "%s/temp_%ld.pad", current_pads_dir, time(NULL));
|
||||||
|
|
||||||
FILE* urandom = fopen("/dev/urandom", "rb");
|
FILE* urandom = fopen("/dev/urandom", "rb");
|
||||||
if (!urandom) {
|
if (!urandom) {
|
||||||
@@ -936,39 +936,11 @@ int generate_pad(uint64_t size_bytes, int display_progress) {
|
|||||||
// Get final paths in pads directory
|
// Get final paths in pads directory
|
||||||
get_pad_path(chksum_hex, pad_path, state_path);
|
get_pad_path(chksum_hex, pad_path, state_path);
|
||||||
|
|
||||||
// Try rename first (works for same filesystem)
|
// Rename temporary file to final name (atomic operation within same directory)
|
||||||
if (rename(temp_filename, pad_path) != 0) {
|
if (rename(temp_filename, pad_path) != 0) {
|
||||||
// If rename fails, try copy and delete (works across filesystems)
|
printf("Error: Cannot rename temporary pad file to final name\n");
|
||||||
FILE* temp_file = fopen(temp_filename, "rb");
|
|
||||||
FILE* dest_file = fopen(pad_path, "wb");
|
|
||||||
|
|
||||||
if (!temp_file || !dest_file) {
|
|
||||||
printf("Error: Cannot copy pad file to pads directory\n");
|
|
||||||
if (temp_file) fclose(temp_file);
|
|
||||||
if (dest_file) fclose(dest_file);
|
|
||||||
unlink(temp_filename);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy file in chunks
|
|
||||||
unsigned char copy_buffer[64 * 1024];
|
|
||||||
size_t bytes_read;
|
|
||||||
while ((bytes_read = fread(copy_buffer, 1, sizeof(copy_buffer), temp_file)) > 0) {
|
|
||||||
if (fwrite(copy_buffer, 1, bytes_read, dest_file) != bytes_read) {
|
|
||||||
printf("Error: Failed to copy pad file to pads directory\n");
|
|
||||||
fclose(temp_file);
|
|
||||||
fclose(dest_file);
|
|
||||||
unlink(temp_filename);
|
|
||||||
unlink(pad_path);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(temp_file);
|
|
||||||
fclose(dest_file);
|
|
||||||
|
|
||||||
// Remove temporary file after successful copy
|
|
||||||
unlink(temp_filename);
|
unlink(temp_filename);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set pad file to read-only
|
// Set pad file to read-only
|
||||||
@@ -3825,7 +3797,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.11\n");
|
snprintf(temp_line, sizeof(temp_line), "Version: v0.3.14\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);
|
||||||
@@ -5567,7 +5539,7 @@ int handle_delete_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.11\n");
|
printf("OTP Cipher - One Time Pad Implementation v0.3.14\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);
|
||||||
|
|||||||
Reference in New Issue
Block a user