Version v0.3.43 - -m Remove unnecessary calculate_checksum() calls during encryption - use filename checksum directly

This commit is contained in:
2025-12-27 11:56:28 -05:00
parent 81eded2995
commit 3bef639cc3
3 changed files with 11 additions and 21 deletions

View File

@@ -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);