This commit is contained in:
2025-10-09 10:45:04 -04:00
parent 9d91ec912a
commit 33b34bf5a5
27 changed files with 1552 additions and 106 deletions

View File

@@ -457,20 +457,17 @@ int derive_chacha20_params(const unsigned char* entropy_data, size_t entropy_siz
return 0; // Success
}
// Collect entropy from binary file
int collect_file_entropy(unsigned char* entropy_buffer, size_t target_bytes,
size_t* collected_bytes, int display_progress) {
// Get file path and size information for entropy collection
int get_file_entropy_info(char* file_path, size_t max_path_len, size_t* file_size, int display_progress) {
if (display_progress) {
print_centered_header("File Entropy Collection", 0);
printf("Load entropy from binary file (.bin format)\n");
printf("Target: %zu bytes\n", target_bytes);
}
printf("Enter path to binary entropy file: ");
fflush(stdout);
char file_path[512];
if (!fgets(file_path, sizeof(file_path), stdin)) {
if (!fgets(file_path, max_path_len, stdin)) {
printf("Error: Failed to read input\n");
return 1;
}
@@ -490,12 +487,31 @@ int collect_file_entropy(unsigned char* entropy_buffer, size_t target_bytes,
return 1;
}
size_t file_size = file_stat.st_size;
if (file_size == 0) {
*file_size = file_stat.st_size;
if (*file_size == 0) {
printf("Error: File is empty\n");
return 1;
}
if (display_progress) {
printf("✓ File found: %s\n", file_path);
printf(" Size: %zu bytes\n", *file_size);
}
return 0; // Success
}
// Collect entropy from binary file (legacy function for backward compatibility)
int collect_file_entropy(unsigned char* entropy_buffer, size_t target_bytes,
size_t* collected_bytes, int display_progress) {
char file_path[512];
size_t file_size;
// Get file path and size first
if (get_file_entropy_info(file_path, sizeof(file_path), &file_size, display_progress) != 0) {
return 1;
}
if (file_size < target_bytes) {
printf("Warning: File size (%zu bytes) is smaller than target (%zu bytes)\n",
file_size, target_bytes);