From 3bef639cc343615fc0ef78c12e3a9ce99f0b60c2 Mon Sep 17 00:00:00 2001 From: Laan Tungir Date: Sat, 27 Dec 2025 11:56:28 -0500 Subject: [PATCH] Version v0.3.43 - -m Remove unnecessary calculate_checksum() calls during encryption - use filename checksum directly --- README.md | 6 +++--- src/crypto.c | 24 +++++++----------------- src/main.h | 2 +- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 8859058..47457b2 100644 --- a/README.md +++ b/README.md @@ -58,14 +58,14 @@ One-time pads can be trivially encrypted and decrypted using pencil and paper, m ### Download Pre-Built Binaries -**[Download Current Linux x86](https://git.laantungir.net/laantungir/otp/releases/download/v0.3.41/otp-v0.3.41-linux-x86_64)** +**[Download Current Linux x86](https://git.laantungir.net/laantungir/otp/releases/download/v0.3.42/otp-v0.3.42-linux-x86_64)** -**[Download Current Raspberry Pi 64](https://git.laantungir.net/laantungir/otp/releases/download/v0.3.41/otp-v0.3.41-linux-arm64)** +**[Download Current Raspberry Pi 64](https://git.laantungir.net/laantungir/otp/releases/download/v0.3.42/otp-v0.3.42-linux-arm64)** After downloading: ```bash # Rename for convenience, then make executable -mv otp-v0.3.41-linux-x86_64 otp +mv otp-v0.3.42-linux-x86_64 otp chmod +x otp # Run it diff --git a/src/crypto.c b/src/crypto.c index ac671c5..c6887d5 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -297,7 +297,6 @@ int encrypt_text(const char* pad_identifier, const char* input_text) { } char text_buffer[MAX_INPUT_SIZE]; - char chksum_hex[MAX_HASH_LENGTH]; uint64_t current_offset; char pad_path[MAX_HASH_LENGTH + 20]; @@ -327,12 +326,8 @@ int encrypt_text(const char* pad_identifier, const char* input_text) { } } - // Calculate XOR checksum of pad file - if (calculate_checksum(pad_path, chksum_hex) != 0) { - printf("Error: Cannot calculate pad checksum\n"); - free(pad_chksum); - return 1; - } + // Use pad_chksum directly - it's already the checksum from the filename + // No need to recalculate by reading the entire pad file // Get input text - either from parameter or user input if (input_text != NULL) { @@ -464,7 +459,7 @@ int encrypt_text(const char* pad_identifier, const char* input_text) { // Use universal ASCII armor generator char* ascii_output; - if (generate_ascii_armor(chksum_hex, current_offset, ciphertext, input_len, &ascii_output) != 0) { + if (generate_ascii_armor(pad_chksum, current_offset, ciphertext, input_len, &ascii_output) != 0) { printf("Error: Failed to generate ASCII armor\n"); free(pad_data); free(ciphertext); @@ -746,7 +741,6 @@ int encrypt_file(const char* pad_identifier, const char* input_file, const char* return 1; } - char chksum_hex[MAX_HASH_LENGTH]; uint64_t current_offset; char pad_path[MAX_HASH_LENGTH + 20]; @@ -791,12 +785,8 @@ int encrypt_file(const char* pad_identifier, const char* input_file, const char* } } - // Calculate XOR checksum of pad file - if (calculate_checksum(pad_path, chksum_hex) != 0) { - printf("Error: Cannot calculate pad checksum\n"); - free(pad_chksum); - return 1; - } + // Use pad_chksum directly - it's already the checksum from the filename + // No need to recalculate by reading the entire pad file // Check if we have enough pad space struct stat pad_stat; @@ -927,7 +917,7 @@ int encrypt_file(const char* pad_identifier, const char* input_file, const char* // Use universal ASCII armor generator char* ascii_output; - if (generate_ascii_armor(chksum_hex, current_offset, encrypted_data, file_size, &ascii_output) != 0) { + if (generate_ascii_armor(pad_chksum, current_offset, encrypted_data, file_size, &ascii_output) != 0) { printf("Error: Failed to generate ASCII armor\n"); fclose(output_fp); free(encrypted_data); @@ -961,7 +951,7 @@ int encrypt_file(const char* pad_identifier, const char* input_file, const char* // Pad checksum: 32 bytes (binary) unsigned char pad_chksum_bin[32]; for (int i = 0; i < 32; i++) { - sscanf(chksum_hex + i*2, "%2hhx", &pad_chksum_bin[i]); + sscanf(pad_chksum + i*2, "%2hhx", &pad_chksum_bin[i]); } fwrite(pad_chksum_bin, 1, 32, output_fp); diff --git a/src/main.h b/src/main.h index 731580c..7da3e97 100644 --- a/src/main.h +++ b/src/main.h @@ -23,7 +23,7 @@ #include // Version - Updated automatically by build.sh -#define OTP_VERSION "v0.3.41" +#define OTP_VERSION "v0.3.42" // Constants #define MAX_INPUT_SIZE 4096