Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bb17b0a7be |
15
otp.c
15
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");
|
||||
|
||||
Reference in New Issue
Block a user