From bb17b0a7bec794416d07af50a8e21266b22f257b Mon Sep 17 00:00:00 2001 From: Laan Tungir Date: Sun, 10 Aug 2025 09:06:53 -0400 Subject: [PATCH] Version v0.2.7 - Automatic version increment --- otp.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/otp.c b/otp.c index 56f6e49..81a66df 100644 --- a/otp.c +++ b/otp.c @@ -764,11 +764,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"); } - // 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"); if (state_file) { - uint64_t zero = 0; - fwrite(&zero, sizeof(uint64_t), 1, state_file); + uint64_t reserved_bytes = 32; + fwrite(&reserved_bytes, sizeof(uint64_t), 1, state_file); fclose(state_file); } else { printf("Error: Failed to create state file\n"); @@ -816,6 +816,15 @@ int encrypt_text(const char* pad_identifier) { 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 if (calculate_checksum(pad_path, hash_hex) != 0) { printf("Error: Cannot calculate pad checksum\n");