Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a0ce6f3253 | |||
| 5e1de92454 | |||
| 55cf7b1937 | |||
| 3d990091eb | |||
| 232846e7ce | |||
| 860ec08d4f | |||
| 60276f5c97 | |||
| 8616e78547 | |||
| 8327ee125b | |||
| 5dadd948e6 | |||
| 02044f1054 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,6 +1,9 @@
|
|||||||
otp
|
otp
|
||||||
pads/
|
pads/
|
||||||
|
files/
|
||||||
Gemini.md
|
Gemini.md
|
||||||
TropicOfCancer-HenryMiller.txt
|
TropicOfCancer-HenryMiller.txt
|
||||||
|
.gitea_token
|
||||||
|
true_rng/
|
||||||
|
|
||||||
# Auto-generated files (none currently)
|
# Auto-generated files (none currently)
|
||||||
|
|||||||
165
build.sh
165
build.sh
@@ -150,38 +150,151 @@ update_source_version() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Build functions
|
# Cross-platform build functions
|
||||||
build_project() {
|
check_cross_compiler() {
|
||||||
print_status "Cleaning previous build..."
|
if ! command -v aarch64-linux-gnu-gcc > /dev/null 2>&1; then
|
||||||
make clean
|
print_error "ARM64/AArch64 cross-compiler not found!"
|
||||||
increment_version
|
print_error "Install with: sudo apt install gcc-aarch64-linux-gnu"
|
||||||
print_status "Building OTP project..."
|
print_error "Or on other distros: gcc-cross-aarch64"
|
||||||
make
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
upload_release_asset() {
|
||||||
|
local api_url="$1"
|
||||||
|
local token="$2"
|
||||||
|
local version="$3"
|
||||||
|
local filename="$4"
|
||||||
|
local display_name="$5"
|
||||||
|
|
||||||
|
if [ ! -f "$filename" ]; then
|
||||||
|
print_warning "Binary $filename not found, skipping upload"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_status "Uploading $filename as '$display_name' to release..."
|
||||||
|
|
||||||
|
# Get release ID first
|
||||||
|
local release_id=$(curl -s -H "Authorization: token $token" \
|
||||||
|
"$api_url/releases/tags/$version" | \
|
||||||
|
grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
|
||||||
|
|
||||||
|
if [ -z "$release_id" ]; then
|
||||||
|
print_error "Could not get release ID for $version"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Upload the asset using multipart/form-data
|
||||||
|
curl -X POST "$api_url/releases/$release_id/assets" \
|
||||||
|
-H "Authorization: token $token" \
|
||||||
|
-F "attachment=@$filename;filename=$display_name"
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
print_success "Build completed successfully"
|
print_success "Uploaded $filename as '$display_name' successfully"
|
||||||
else
|
else
|
||||||
print_error "Build failed"
|
print_warning "Failed to upload $filename"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
build_static() {
|
create_gitea_release() {
|
||||||
|
local version="$1"
|
||||||
|
|
||||||
|
# Read token from ~/.gitea_token
|
||||||
|
if [ ! -f "$HOME/.gitea_token" ]; then
|
||||||
|
print_error "No ~/.gitea_token found. Cannot create release."
|
||||||
|
print_error "Create ~/.gitea_token with your Gitea access token"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local token=$(cat "$HOME/.gitea_token" | tr -d '\n\r')
|
||||||
|
local api_url="https://git.laantungir.net/api/v1/repos/laantungir/otp"
|
||||||
|
|
||||||
|
print_status "Creating Gitea release for $version..."
|
||||||
|
|
||||||
|
# Create release
|
||||||
|
local response=$(curl -s -X POST "$api_url/releases" \
|
||||||
|
-H "Authorization: token $token" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{\"tag_name\": \"$version\", \"name\": \"$version\", \"body\": \"Automated release for $version\"}")
|
||||||
|
|
||||||
|
if echo "$response" | grep -q '"id"'; then
|
||||||
|
print_success "Created release $version"
|
||||||
|
|
||||||
|
# Upload binaries with descriptive names
|
||||||
|
upload_release_asset "$api_url" "$token" "$version" "otp-x86_64" "otp-${version}-linux-x86_64"
|
||||||
|
upload_release_asset "$api_url" "$token" "$version" "otp-arm64" "otp-${version}-linux-arm64"
|
||||||
|
else
|
||||||
|
print_warning "Release may already exist or creation failed"
|
||||||
|
print_status "Response: $response"
|
||||||
|
|
||||||
|
# Try to upload to existing release anyway
|
||||||
|
upload_release_asset "$api_url" "$token" "$version" "otp-x86_64" "otp-${version}-linux-x86_64"
|
||||||
|
upload_release_asset "$api_url" "$token" "$version" "otp-arm64" "otp-${version}-linux-arm64"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
build_project() {
|
||||||
print_status "Cleaning previous build..."
|
print_status "Cleaning previous build..."
|
||||||
make clean
|
make clean
|
||||||
increment_version
|
increment_version
|
||||||
print_status "Building OTP project with static linking..."
|
|
||||||
make static
|
# Check for cross-compiler
|
||||||
if [ $? -eq 0 ]; then
|
if ! check_cross_compiler; then
|
||||||
print_success "Static build completed successfully"
|
print_warning "ARM64/AArch64 cross-compiler not available, building x86_64 only"
|
||||||
|
|
||||||
|
# Build x86_64 only
|
||||||
|
print_status "Building OTP project for x86_64..."
|
||||||
|
make CC=gcc
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
mv otp otp-x86_64
|
||||||
|
print_success "x86_64 build completed successfully"
|
||||||
|
else
|
||||||
|
print_error "x86_64 build failed"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
print_error "Static build failed"
|
# Build both architectures
|
||||||
return 1
|
print_status "Building OTP project for x86_64..."
|
||||||
|
make clean
|
||||||
|
make CC=gcc
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
mv otp otp-x86_64
|
||||||
|
print_success "x86_64 build completed successfully"
|
||||||
|
else
|
||||||
|
print_error "x86_64 build failed"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_status "Building OTP project for ARM64/AArch64..."
|
||||||
|
make clean
|
||||||
|
make CC=aarch64-linux-gnu-gcc
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
mv otp otp-arm64
|
||||||
|
print_success "ARM64/AArch64 build completed successfully"
|
||||||
|
else
|
||||||
|
print_error "ARM64/AArch64 build failed"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Create Gitea release with binaries
|
||||||
|
if [ -f "$HOME/.gitea_token" ]; then
|
||||||
|
create_gitea_release "$NEW_VERSION"
|
||||||
|
else
|
||||||
|
print_warning "No ~/.gitea_token found. Skipping release creation."
|
||||||
|
print_warning "Create ~/.gitea_token with your Gitea access token to enable releases."
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_success "Build completed successfully"
|
||||||
}
|
}
|
||||||
|
|
||||||
clean_project() {
|
clean_project() {
|
||||||
print_status "Cleaning build artifacts..."
|
print_status "Cleaning build artifacts..."
|
||||||
make clean
|
make clean
|
||||||
|
# Remove cross-compiled binaries
|
||||||
|
rm -f otp-x86_64 otp-arm64
|
||||||
print_success "Clean completed"
|
print_success "Clean completed"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,9 +325,6 @@ case "${1:-build}" in
|
|||||||
build)
|
build)
|
||||||
build_project
|
build_project
|
||||||
;;
|
;;
|
||||||
static)
|
|
||||||
build_static
|
|
||||||
;;
|
|
||||||
clean)
|
clean)
|
||||||
clean_project
|
clean_project
|
||||||
;;
|
;;
|
||||||
@@ -226,22 +336,29 @@ case "${1:-build}" in
|
|||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "OTP Cipher Build Script"
|
echo "OTP Cipher Build Script"
|
||||||
echo "Usage: $0 [-m \"commit message\"] {build|static|clean|install|uninstall}"
|
echo "Usage: $0 [-m \"commit message\"] {build|clean|install|uninstall}"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -m, --message \"text\" - Specify commit message (skips interactive prompt)"
|
echo " -m, --message \"text\" - Specify commit message (skips interactive prompt)"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Commands:"
|
echo "Commands:"
|
||||||
echo " build - Build project with automatic version increment (default)"
|
echo " build - Cross-compile for x86_64 and ARM64/AArch64 with automatic version increment (default)"
|
||||||
echo " static - Build with static linking and version increment"
|
echo " clean - Clean build artifacts and cross-compiled binaries"
|
||||||
echo " clean - Clean build artifacts"
|
|
||||||
echo " install - Install to system (requires build first)"
|
echo " install - Install to system (requires build first)"
|
||||||
echo " uninstall - Remove from system"
|
echo " uninstall - Remove from system"
|
||||||
echo ""
|
echo ""
|
||||||
|
echo "Build Output:"
|
||||||
|
echo " otp-x86_64 - Native x86_64 binary"
|
||||||
|
echo " otp-arm64 - ARM64/AArch64 binary for Raspberry Pi (if cross-compiler available)"
|
||||||
|
echo ""
|
||||||
|
echo "Gitea Integration:"
|
||||||
|
echo " - Automatically creates releases with binaries if ~/.gitea_token exists"
|
||||||
|
echo " - Requires: ARM64 cross-compiler (gcc-aarch64-linux-gnu)"
|
||||||
|
echo ""
|
||||||
echo "Examples:"
|
echo "Examples:"
|
||||||
echo " $0"
|
echo " $0"
|
||||||
echo " $0 -m \"Fixed checksum parsing bug\""
|
echo " $0 -m \"Fixed checksum parsing bug\""
|
||||||
echo " $0 --message \"Added new feature\" static"
|
echo " $0 --message \"Added new feature\" build"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
BIN
otp-x86_64
Executable file
BIN
otp-x86_64
Executable file
Binary file not shown.
773
otp.c
773
otp.c
@@ -7,6 +7,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/statvfs.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -330,7 +331,7 @@ int interactive_mode(void) {
|
|||||||
void show_main_menu(void) {
|
void show_main_menu(void) {
|
||||||
|
|
||||||
|
|
||||||
printf("\n=========================== Main Menu - OTP v0.2.109 ===========================\n\n");
|
printf("\n=========================== Main Menu - OTP v0.3.8 ===========================\n\n");
|
||||||
|
|
||||||
printf(" \033[4mT\033[0mext encrypt\n"); //TEXT ENCRYPT
|
printf(" \033[4mT\033[0mext encrypt\n"); //TEXT ENCRYPT
|
||||||
printf(" \033[4mF\033[0mile encrypt\n"); //FILE ENCRYPT
|
printf(" \033[4mF\033[0mile encrypt\n"); //FILE ENCRYPT
|
||||||
@@ -2185,8 +2186,36 @@ int detect_otp_thumb_drive(char* otp_drive_path, size_t path_size) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// To be removed
|
||||||
|
// Format file size for display
|
||||||
|
// void format_size_string(uint64_t bytes, char* result, size_t result_size) {
|
||||||
|
// if (bytes == 0) {
|
||||||
|
// strncpy(result, "Unknown", result_size - 1);
|
||||||
|
// result[result_size - 1] = '\0';
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (bytes < 1024) {
|
||||||
|
// snprintf(result, result_size, "%luB", bytes);
|
||||||
|
// } else if (bytes < 1024 * 1024) {
|
||||||
|
// snprintf(result, result_size, "%.1fKB", (double)bytes / 1024.0);
|
||||||
|
// } else if (bytes < 1024 * 1024 * 1024) {
|
||||||
|
// snprintf(result, result_size, "%.1fMB", (double)bytes / (1024.0 * 1024.0));
|
||||||
|
// } else if (bytes < 1024ULL * 1024 * 1024 * 1024) {
|
||||||
|
// snprintf(result, result_size, "%.2fGB", (double)bytes / (1024.0 * 1024.0 * 1024.0));
|
||||||
|
// } else {
|
||||||
|
// snprintf(result, result_size, "%.2fTB", (double)bytes / (1024.0 * 1024.0 * 1024.0 * 1024.0));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Custom base64 encode function
|
// Custom base64 encode function
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char* custom_base64_encode(const unsigned char* input, int length) {
|
char* custom_base64_encode(const unsigned char* input, int length) {
|
||||||
int output_length = 4 * ((length + 2) / 3);
|
int output_length = 4 * ((length + 2) / 3);
|
||||||
char* encoded = malloc(output_length + 1);
|
char* encoded = malloc(output_length + 1);
|
||||||
@@ -2258,6 +2287,372 @@ unsigned char* custom_base64_decode(const char* input, int* output_length) {
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// TRUERNG DEVICE DETECTION AND COMMUNICATION
|
||||||
|
// Ported from true_rng/main.c for entropy collection
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Read USB device info from sysfs (ported from TrueRNG reference)
|
||||||
|
int read_usb_device_info(const char* port_name, char* vid, char* pid) {
|
||||||
|
char path[512];
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
// Try to read idVendor first (works for both ttyUSB and ttyACM devices)
|
||||||
|
snprintf(path, sizeof(path), "/sys/class/tty/%s/device/../idVendor", port_name);
|
||||||
|
fp = fopen(path, "r");
|
||||||
|
if (fp) {
|
||||||
|
if (fgets(vid, 8, fp) != NULL) {
|
||||||
|
// Remove newline if present
|
||||||
|
int len = strlen(vid);
|
||||||
|
if (len > 0 && vid[len-1] == '\n') {
|
||||||
|
vid[len-1] = '\0';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fclose(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to read idProduct
|
||||||
|
snprintf(path, sizeof(path), "/sys/class/tty/%s/device/../idProduct", port_name);
|
||||||
|
fp = fopen(path, "r");
|
||||||
|
if (fp) {
|
||||||
|
if (fgets(pid, 8, fp) != NULL) {
|
||||||
|
// Remove newline if present
|
||||||
|
int len = strlen(pid);
|
||||||
|
if (len > 0 && pid[len-1] == '\n') {
|
||||||
|
pid[len-1] = '\0';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fclose(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find TrueRNG device port (ported and adapted from TrueRNG reference)
|
||||||
|
// Returns: 0=not found, 1=TrueRNGproV2, 2=TrueRNGpro, 3=TrueRNG
|
||||||
|
int find_truerng_port(char* port_path, size_t port_path_size, truerng_device_type_t* device_type) {
|
||||||
|
DIR *dir;
|
||||||
|
struct dirent *entry;
|
||||||
|
char vid[8], pid[8];
|
||||||
|
int device_found = 0;
|
||||||
|
|
||||||
|
dir = opendir("/dev");
|
||||||
|
if (dir == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
|
// Look for ttyUSB* or ttyACM* devices
|
||||||
|
if (strncmp(entry->d_name, "ttyUSB", 6) == 0 ||
|
||||||
|
strncmp(entry->d_name, "ttyACM", 6) == 0) {
|
||||||
|
|
||||||
|
if (read_usb_device_info(entry->d_name, vid, pid)) {
|
||||||
|
// Convert to uppercase for comparison
|
||||||
|
for (int i = 0; vid[i]; i++) vid[i] = toupper(vid[i]);
|
||||||
|
for (int i = 0; pid[i]; i++) pid[i] = toupper(pid[i]);
|
||||||
|
|
||||||
|
// Check for TrueRNGproV2
|
||||||
|
if (strcmp(vid, TRUERNGPROV2_VID) == 0 && strcmp(pid, TRUERNGPROV2_PID) == 0) {
|
||||||
|
snprintf(port_path, port_path_size, "/dev/%s", entry->d_name);
|
||||||
|
*device_type = TRUERNG_PRO_V2;
|
||||||
|
device_found = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for TrueRNGpro
|
||||||
|
if (strcmp(vid, TRUERNGPRO_VID) == 0 && strcmp(pid, TRUERNGPRO_PID) == 0) {
|
||||||
|
snprintf(port_path, port_path_size, "/dev/%s", entry->d_name);
|
||||||
|
*device_type = TRUERNG_PRO;
|
||||||
|
device_found = 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for TrueRNG
|
||||||
|
if (strcmp(vid, TRUERNG_VID) == 0 && strcmp(pid, TRUERNG_PID) == 0) {
|
||||||
|
snprintf(port_path, port_path_size, "/dev/%s", entry->d_name);
|
||||||
|
*device_type = TRUERNG_ORIGINAL;
|
||||||
|
device_found = 3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
return device_found;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup serial port for TrueRNG communication (ported from TrueRNG reference)
|
||||||
|
int setup_truerng_serial_port(const char* port_path) {
|
||||||
|
int fd;
|
||||||
|
struct termios tty;
|
||||||
|
|
||||||
|
fd = open(port_path, O_RDWR | O_NOCTTY);
|
||||||
|
if (fd < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get current port settings
|
||||||
|
if (tcgetattr(fd, &tty) != 0) {
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set baud rate (TrueRNG devices use 9600)
|
||||||
|
cfsetospeed(&tty, B9600);
|
||||||
|
cfsetispeed(&tty, B9600);
|
||||||
|
|
||||||
|
// 8N1 mode
|
||||||
|
tty.c_cflag &= ~PARENB; // No parity
|
||||||
|
tty.c_cflag &= ~CSTOPB; // 1 stop bit
|
||||||
|
tty.c_cflag &= ~CSIZE; // Clear size bits
|
||||||
|
tty.c_cflag |= CS8; // 8 data bits
|
||||||
|
tty.c_cflag &= ~CRTSCTS; // No hardware flow control
|
||||||
|
tty.c_cflag |= CREAD | CLOCAL; // Enable reading and ignore modem controls
|
||||||
|
|
||||||
|
// Raw input mode
|
||||||
|
tty.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||||
|
tty.c_iflag &= ~(IXON | IXOFF | IXANY);
|
||||||
|
tty.c_oflag &= ~OPOST;
|
||||||
|
|
||||||
|
// Set for blocking reads - wait for data indefinitely
|
||||||
|
tty.c_cc[VMIN] = 1; // Block until at least 1 character is received
|
||||||
|
tty.c_cc[VTIME] = 0; // No timeout
|
||||||
|
|
||||||
|
// Apply settings
|
||||||
|
if (tcsetattr(fd, TCSANOW, &tty) != 0) {
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flush input buffer
|
||||||
|
tcflush(fd, TCIFLUSH);
|
||||||
|
|
||||||
|
// Set DTR
|
||||||
|
int status;
|
||||||
|
ioctl(fd, TIOCMGET, &status);
|
||||||
|
status |= TIOCM_DTR;
|
||||||
|
ioctl(fd, TIOCMSET, &status);
|
||||||
|
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get friendly name for TrueRNG device type
|
||||||
|
const char* get_truerng_device_name(truerng_device_type_t device_type) {
|
||||||
|
switch (device_type) {
|
||||||
|
case TRUERNG_PRO_V2: return "TrueRNGproV2";
|
||||||
|
case TRUERNG_PRO: return "TrueRNGpro";
|
||||||
|
case TRUERNG_ORIGINAL: return "TrueRNG";
|
||||||
|
default: return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect entropy from TrueRNG device with equivalent quality to keyboard entropy
|
||||||
|
int collect_truerng_entropy(unsigned char* entropy_buffer, size_t target_bytes,
|
||||||
|
size_t* collected_bytes, int display_progress) {
|
||||||
|
char port_path[512];
|
||||||
|
truerng_device_type_t device_type;
|
||||||
|
int serial_fd = -1;
|
||||||
|
|
||||||
|
// Find TrueRNG device
|
||||||
|
if (!find_truerng_port(port_path, sizeof(port_path), &device_type)) {
|
||||||
|
if (display_progress) {
|
||||||
|
printf("No TrueRNG device found.\n");
|
||||||
|
printf("\nSupported devices:\n");
|
||||||
|
printf(" - TrueRNG (PID: %s, VID: %s)\n", TRUERNG_VID, TRUERNG_PID);
|
||||||
|
printf(" - TrueRNGpro (PID: %s, VID: %s)\n", TRUERNGPRO_VID, TRUERNGPRO_PID);
|
||||||
|
printf(" - TrueRNGproV2 (PID: %s, VID: %s)\n", TRUERNGPROV2_VID, TRUERNGPROV2_PID);
|
||||||
|
printf("\nPlease connect a TrueRNG device and try again.\n");
|
||||||
|
}
|
||||||
|
return 1; // Device not found
|
||||||
|
}
|
||||||
|
|
||||||
|
if (display_progress) {
|
||||||
|
printf("Found %s at %s\n", get_truerng_device_name(device_type), port_path);
|
||||||
|
printf("Collecting %zu bytes of entropy...\n", target_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup serial port
|
||||||
|
serial_fd = setup_truerng_serial_port(port_path);
|
||||||
|
if (serial_fd < 0) {
|
||||||
|
if (display_progress) {
|
||||||
|
printf("Error: Cannot open TrueRNG device at %s\n", port_path);
|
||||||
|
printf("Check device permissions or run as root.\n");
|
||||||
|
}
|
||||||
|
return 2; // Serial port setup failed
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect entropy data
|
||||||
|
size_t bytes_read = 0;
|
||||||
|
unsigned char buffer[1024]; // Read in 1KB chunks
|
||||||
|
time_t start_time = time(NULL);
|
||||||
|
|
||||||
|
while (bytes_read < target_bytes) {
|
||||||
|
size_t chunk_size = sizeof(buffer);
|
||||||
|
if (target_bytes - bytes_read < chunk_size) {
|
||||||
|
chunk_size = target_bytes - bytes_read;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t bytes_in_chunk = 0;
|
||||||
|
while (bytes_in_chunk < chunk_size) {
|
||||||
|
ssize_t result = read(serial_fd, buffer + bytes_in_chunk, chunk_size - bytes_in_chunk);
|
||||||
|
if (result < 0) {
|
||||||
|
if (display_progress) {
|
||||||
|
printf("Error: Failed to read from TrueRNG device\n");
|
||||||
|
}
|
||||||
|
close(serial_fd);
|
||||||
|
return 3; // Read failed
|
||||||
|
} else if (result == 0) {
|
||||||
|
if (display_progress) {
|
||||||
|
printf("Error: No data received from TrueRNG device\n");
|
||||||
|
}
|
||||||
|
close(serial_fd);
|
||||||
|
return 4; // No data
|
||||||
|
}
|
||||||
|
bytes_in_chunk += result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy to entropy buffer
|
||||||
|
memcpy(entropy_buffer + bytes_read, buffer, chunk_size);
|
||||||
|
bytes_read += chunk_size;
|
||||||
|
|
||||||
|
// Show progress for large collections
|
||||||
|
if (display_progress && bytes_read % (4 * 1024) == 0) { // Every 4KB
|
||||||
|
double percentage = (double)bytes_read / target_bytes * 100.0;
|
||||||
|
printf("Progress: %.1f%% (%zu/%zu bytes)\r", percentage, bytes_read, target_bytes);
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close(serial_fd);
|
||||||
|
|
||||||
|
if (display_progress) {
|
||||||
|
double collection_time = difftime(time(NULL), start_time);
|
||||||
|
printf("\n✓ TrueRNG entropy collection complete!\n");
|
||||||
|
printf(" Collected: %zu bytes in %.1f seconds\n", bytes_read, collection_time);
|
||||||
|
printf(" Device: %s\n", get_truerng_device_name(device_type));
|
||||||
|
if (collection_time > 0) {
|
||||||
|
printf(" Rate: %.1f KB/s\n", (double)bytes_read / collection_time / 1024.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*collected_bytes = bytes_read;
|
||||||
|
return 0; // Success
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect dice entropy with manual input validation
|
||||||
|
int collect_dice_entropy(unsigned char* entropy_buffer, size_t target_bytes,
|
||||||
|
size_t* collected_bytes, int display_progress) {
|
||||||
|
if (display_progress) {
|
||||||
|
printf("=== Dice Entropy Collection ===\n");
|
||||||
|
printf("Enter dice rolls as sequences of digits 1-6.\n");
|
||||||
|
printf("Target: %zu bytes (%zu dice rolls needed)\n", target_bytes, target_bytes * 4);
|
||||||
|
printf("Press Enter after each sequence, or 'done' when finished.\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t entropy_bits = 0;
|
||||||
|
size_t target_bits = target_bytes * 8;
|
||||||
|
unsigned char current_byte = 0;
|
||||||
|
int bits_in_byte = 0;
|
||||||
|
size_t bytes_written = 0;
|
||||||
|
|
||||||
|
char input[256];
|
||||||
|
|
||||||
|
while (entropy_bits < target_bits && bytes_written < target_bytes) {
|
||||||
|
if (display_progress) {
|
||||||
|
double percentage = (double)entropy_bits / target_bits * 100.0;
|
||||||
|
printf("Progress: %.1f%% (%zu/%zu bits) - Enter dice rolls: ",
|
||||||
|
percentage, entropy_bits, target_bits);
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fgets(input, sizeof(input), stdin)) {
|
||||||
|
if (display_progress) {
|
||||||
|
printf("Error: Failed to read input\n");
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove newline
|
||||||
|
input[strcspn(input, "\n")] = 0;
|
||||||
|
|
||||||
|
// Check for done command
|
||||||
|
if (strcmp(input, "done") == 0 && entropy_bits >= target_bits / 2) {
|
||||||
|
break; // Allow early exit if we have at least half the target
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process dice rolls
|
||||||
|
for (size_t i = 0; input[i] && entropy_bits < target_bits && bytes_written < target_bytes; i++) {
|
||||||
|
char c = input[i];
|
||||||
|
if (c >= '1' && c <= '6') {
|
||||||
|
// Convert dice roll (1-6) to 3 bits of entropy
|
||||||
|
unsigned char roll_value = c - '1'; // 0-5
|
||||||
|
|
||||||
|
// Pack 3 bits into current byte
|
||||||
|
for (int bit = 2; bit >= 0 && entropy_bits < target_bits; bit--) {
|
||||||
|
current_byte = (current_byte << 1) | ((roll_value >> bit) & 1);
|
||||||
|
bits_in_byte++;
|
||||||
|
entropy_bits++;
|
||||||
|
|
||||||
|
if (bits_in_byte == 8) {
|
||||||
|
entropy_buffer[bytes_written++] = current_byte;
|
||||||
|
current_byte = 0;
|
||||||
|
bits_in_byte = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle partial byte
|
||||||
|
if (bits_in_byte > 0 && bytes_written < target_bytes) {
|
||||||
|
// Pad remaining bits with zeros
|
||||||
|
current_byte <<= (8 - bits_in_byte);
|
||||||
|
entropy_buffer[bytes_written++] = current_byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (display_progress) {
|
||||||
|
printf("\n✓ Dice entropy collection complete!\n");
|
||||||
|
printf(" Collected: %zu bytes from dice rolls\n", bytes_written);
|
||||||
|
printf(" Entropy bits: %zu\n", entropy_bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
*collected_bytes = bytes_written;
|
||||||
|
return 0; // Success
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect entropy by source type with unified interface
|
||||||
|
int collect_entropy_by_source(entropy_source_t source, unsigned char* entropy_buffer,
|
||||||
|
size_t target_bytes, size_t* collected_bytes, int display_progress) {
|
||||||
|
switch (source) {
|
||||||
|
case ENTROPY_SOURCE_KEYBOARD:
|
||||||
|
return collect_entropy_with_feedback(entropy_buffer, target_bytes, collected_bytes, 1);
|
||||||
|
|
||||||
|
case ENTROPY_SOURCE_TRUERNG:
|
||||||
|
return collect_truerng_entropy(entropy_buffer, target_bytes, collected_bytes, display_progress);
|
||||||
|
|
||||||
|
case ENTROPY_SOURCE_DICE:
|
||||||
|
return collect_dice_entropy(entropy_buffer, target_bytes, collected_bytes, display_progress);
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (display_progress) {
|
||||||
|
printf("Error: Unknown entropy source\n");
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
double get_precise_time(void) {
|
double get_precise_time(void) {
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
@@ -2848,7 +3243,7 @@ int generate_ascii_armor(const char* chksum, uint64_t offset, const unsigned cha
|
|||||||
strcpy(*ascii_output, "-----BEGIN OTP MESSAGE-----\n");
|
strcpy(*ascii_output, "-----BEGIN OTP MESSAGE-----\n");
|
||||||
|
|
||||||
char temp_line[256];
|
char temp_line[256];
|
||||||
snprintf(temp_line, sizeof(temp_line), "Version: v0.2.109\n");
|
snprintf(temp_line, sizeof(temp_line), "Version: v0.3.8\n");
|
||||||
strcat(*ascii_output, temp_line);
|
strcat(*ascii_output, temp_line);
|
||||||
|
|
||||||
snprintf(temp_line, sizeof(temp_line), "Pad-ChkSum: %s\n", chksum);
|
snprintf(temp_line, sizeof(temp_line), "Pad-ChkSum: %s\n", chksum);
|
||||||
@@ -3728,7 +4123,7 @@ char* select_pad_interactive(const char* title, const char* prompt, pad_filter_t
|
|||||||
pads[pad_count].percentage = (double)used_bytes / st.st_size * 100.0;
|
pads[pad_count].percentage = (double)used_bytes / st.st_size * 100.0;
|
||||||
|
|
||||||
// Set location info using directory display
|
// Set location info using directory display
|
||||||
get_directory_display(full_path, pads[pad_count].location, sizeof(pads[pad_count].location));
|
// get_directory_display(full_path, pads[pad_count].location, sizeof(pads[pad_count].location));
|
||||||
|
|
||||||
pad_count++;
|
pad_count++;
|
||||||
}
|
}
|
||||||
@@ -3961,7 +4356,7 @@ int handle_pads_menu(void) {
|
|||||||
pads[pad_count].percentage = (double)used_bytes / st.st_size * 100.0;
|
pads[pad_count].percentage = (double)used_bytes / st.st_size * 100.0;
|
||||||
|
|
||||||
// Set location info using directory display
|
// Set location info using directory display
|
||||||
get_directory_display(full_path, pads[pad_count].location, sizeof(pads[pad_count].location));
|
// get_directory_display(full_path, pads[pad_count].location, sizeof(pads[pad_count].location));
|
||||||
|
|
||||||
pad_count++;
|
pad_count++;
|
||||||
}
|
}
|
||||||
@@ -4166,188 +4561,243 @@ int handle_pads_menu(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_directory_display(const char* file_path, char* result, size_t result_size) {
|
// To be removed
|
||||||
// Extract directory path from full file path
|
// void get_directory_display(const char* file_path, char* result, size_t result_size) {
|
||||||
char dir_path[512];
|
// // Extract directory path from full file path
|
||||||
char* last_slash = strrchr(file_path, '/');
|
// char dir_path[512];
|
||||||
|
// char* last_slash = strrchr(file_path, '/');
|
||||||
|
|
||||||
if (last_slash) {
|
// if (last_slash) {
|
||||||
size_t dir_len = last_slash - file_path;
|
// size_t dir_len = last_slash - file_path;
|
||||||
if (dir_len >= sizeof(dir_path)) {
|
// if (dir_len >= sizeof(dir_path)) {
|
||||||
dir_len = sizeof(dir_path) - 1;
|
// dir_len = sizeof(dir_path) - 1;
|
||||||
}
|
// }
|
||||||
strncpy(dir_path, file_path, dir_len);
|
// strncpy(dir_path, file_path, dir_len);
|
||||||
dir_path[dir_len] = '\0';
|
// dir_path[dir_len] = '\0';
|
||||||
} else {
|
// } else {
|
||||||
// No directory separator, assume current directory
|
// // No directory separator, assume current directory
|
||||||
strcpy(dir_path, ".");
|
// strcpy(dir_path, ".");
|
||||||
}
|
// }
|
||||||
|
|
||||||
// USB Drive Detection and Smart Shortening
|
// // USB Drive Detection and Smart Shortening
|
||||||
char* home_dir = getenv("HOME");
|
// char* home_dir = getenv("HOME");
|
||||||
|
|
||||||
// Check for USB/removable media mount patterns
|
// // Check for USB/removable media mount patterns
|
||||||
if (strstr(dir_path, "/media/") || strstr(dir_path, "/run/media/") || strstr(dir_path, "/mnt/")) {
|
// if (strstr(dir_path, "/media/") || strstr(dir_path, "/run/media/") || strstr(dir_path, "/mnt/")) {
|
||||||
// Extract USB label/name
|
// // Extract USB label/name
|
||||||
char* media_start = NULL;
|
// char* media_start = NULL;
|
||||||
if (strstr(dir_path, "/media/")) {
|
// if (strstr(dir_path, "/media/")) {
|
||||||
media_start = strstr(dir_path, "/media/");
|
// media_start = strstr(dir_path, "/media/");
|
||||||
} else if (strstr(dir_path, "/run/media/")) {
|
// } else if (strstr(dir_path, "/run/media/")) {
|
||||||
media_start = strstr(dir_path, "/run/media/");
|
// media_start = strstr(dir_path, "/run/media/");
|
||||||
} else if (strstr(dir_path, "/mnt/")) {
|
// } else if (strstr(dir_path, "/mnt/")) {
|
||||||
media_start = strstr(dir_path, "/mnt/");
|
// media_start = strstr(dir_path, "/mnt/");
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (media_start) {
|
// if (media_start) {
|
||||||
// Find the USB label part
|
// // Find the USB label part
|
||||||
char* path_after_media = strchr(media_start + 1, '/');
|
// char* path_after_media = strchr(media_start + 1, '/');
|
||||||
if (path_after_media) {
|
// if (path_after_media) {
|
||||||
path_after_media++; // Skip the slash
|
// path_after_media++; // Skip the slash
|
||||||
|
|
||||||
// For /media/user/LABEL pattern, skip the username to get to the drive label
|
// // For /media/user/LABEL pattern, skip the username to get to the drive label
|
||||||
if (strstr(media_start, "/media/")) {
|
// if (strstr(media_start, "/media/")) {
|
||||||
char* next_slash = strchr(path_after_media, '/');
|
// char* next_slash = strchr(path_after_media, '/');
|
||||||
if (next_slash) {
|
// if (next_slash) {
|
||||||
path_after_media = next_slash + 1;
|
// path_after_media = next_slash + 1;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
// For /run/media/user/LABEL pattern, skip the username
|
// // For /run/media/user/LABEL pattern, skip the username
|
||||||
else if (strstr(media_start, "/run/media/")) {
|
// else if (strstr(media_start, "/run/media/")) {
|
||||||
char* next_slash = strchr(path_after_media, '/');
|
// char* next_slash = strchr(path_after_media, '/');
|
||||||
if (next_slash) {
|
// if (next_slash) {
|
||||||
path_after_media = next_slash + 1;
|
// path_after_media = next_slash + 1;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Extract just the USB label (up to next slash or end)
|
// // Extract just the USB label (up to next slash or end)
|
||||||
char* label_end = strchr(path_after_media, '/');
|
// char* label_end = strchr(path_after_media, '/');
|
||||||
char usb_label[32];
|
// char usb_label[32];
|
||||||
if (label_end) {
|
// if (label_end) {
|
||||||
size_t label_len = label_end - path_after_media;
|
// size_t label_len = label_end - path_after_media;
|
||||||
if (label_len > sizeof(usb_label) - 1) label_len = sizeof(usb_label) - 1;
|
// if (label_len > sizeof(usb_label) - 1) label_len = sizeof(usb_label) - 1;
|
||||||
strncpy(usb_label, path_after_media, label_len);
|
// strncpy(usb_label, path_after_media, label_len);
|
||||||
usb_label[label_len] = '\0';
|
// usb_label[label_len] = '\0';
|
||||||
} else {
|
// } else {
|
||||||
// USB label is the last part
|
// // USB label is the last part
|
||||||
strncpy(usb_label, path_after_media, sizeof(usb_label) - 1);
|
// strncpy(usb_label, path_after_media, sizeof(usb_label) - 1);
|
||||||
usb_label[sizeof(usb_label) - 1] = '\0';
|
// usb_label[sizeof(usb_label) - 1] = '\0';
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Format with USB: prefix, limiting total length to fit in result
|
// // Format with USB: prefix, limiting total length to fit in result
|
||||||
snprintf(result, result_size, "USB:%s", usb_label);
|
// snprintf(result, result_size, "USB:%s", usb_label);
|
||||||
// Truncate if too long
|
// // Truncate if too long
|
||||||
if (strlen(result) > 11) {
|
// if (strlen(result) > 11) {
|
||||||
result[11] = '\0';
|
// result[11] = '\0';
|
||||||
}
|
// }
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Home directory shortening
|
// // Home directory shortening
|
||||||
if (home_dir && strncmp(dir_path, home_dir, strlen(home_dir)) == 0) {
|
// if (home_dir && strncmp(dir_path, home_dir, strlen(home_dir)) == 0) {
|
||||||
if (dir_path[strlen(home_dir)] == '/' || dir_path[strlen(home_dir)] == '\0') {
|
// if (dir_path[strlen(home_dir)] == '/' || dir_path[strlen(home_dir)] == '\0') {
|
||||||
// Replace home directory with ~
|
// // Replace home directory with ~
|
||||||
char temp[512];
|
// char temp[512];
|
||||||
snprintf(temp, sizeof(temp), "~%s", dir_path + strlen(home_dir));
|
// snprintf(temp, sizeof(temp), "~%s", dir_path + strlen(home_dir));
|
||||||
|
|
||||||
// If result is too long, truncate intelligently
|
// // If result is too long, truncate intelligently
|
||||||
if (strlen(temp) > 11) {
|
// if (strlen(temp) > 11) {
|
||||||
// Show ~/...end_part
|
// // Show ~/...end_part
|
||||||
char* last_part = strrchr(temp, '/');
|
// char* last_part = strrchr(temp, '/');
|
||||||
if (last_part && strlen(last_part) < 8) {
|
// if (last_part && strlen(last_part) < 8) {
|
||||||
snprintf(result, result_size, "~...%s", last_part);
|
// snprintf(result, result_size, "~...%s", last_part);
|
||||||
} else {
|
// } else {
|
||||||
strncpy(result, temp, 11);
|
// strncpy(result, temp, 11);
|
||||||
result[11] = '\0';
|
// result[11] = '\0';
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
strncpy(result, temp, result_size - 1);
|
// strncpy(result, temp, result_size - 1);
|
||||||
result[result_size - 1] = '\0';
|
// result[result_size - 1] = '\0';
|
||||||
}
|
// }
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Current working directory
|
// // Current working directory
|
||||||
if (strcmp(dir_path, ".") == 0 || strcmp(dir_path, current_pads_dir) == 0) {
|
// if (strcmp(dir_path, ".") == 0 || strcmp(dir_path, current_pads_dir) == 0) {
|
||||||
strncpy(result, "pads", result_size - 1);
|
// strncpy(result, "pads", result_size - 1);
|
||||||
result[result_size - 1] = '\0';
|
// result[result_size - 1] = '\0';
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// System/other paths - smart truncation with ellipsis
|
// // System/other paths - smart truncation with ellipsis
|
||||||
if (strlen(dir_path) > 11) {
|
// if (strlen(dir_path) > 11) {
|
||||||
// Try to show the most meaningful part
|
// // Try to show the most meaningful part
|
||||||
char* last_part = strrchr(dir_path, '/');
|
// char* last_part = strrchr(dir_path, '/');
|
||||||
if (last_part && strlen(last_part) < 9) {
|
// if (last_part && strlen(last_part) < 9) {
|
||||||
// Show .../last_part
|
// // Show .../last_part
|
||||||
snprintf(result, result_size, "...%s", last_part);
|
// snprintf(result, result_size, "...%s", last_part);
|
||||||
} else {
|
// } else {
|
||||||
// Show first part with ellipsis
|
// // Show first part with ellipsis
|
||||||
strncpy(result, dir_path, 8);
|
// strncpy(result, dir_path, 8);
|
||||||
strncpy(result + 8, "...", result_size - 8 - 1);
|
// strncpy(result + 8, "...", result_size - 8 - 1);
|
||||||
result[result_size - 1] = '\0';
|
// result[result_size - 1] = '\0';
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
// Short enough, use as-is
|
// // Short enough, use as-is
|
||||||
strncpy(result, dir_path, result_size - 1);
|
// strncpy(result, dir_path, result_size - 1);
|
||||||
result[result_size - 1] = '\0';
|
// result[result_size - 1] = '\0';
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
int handle_add_entropy_to_pad(const char* pad_chksum) {
|
int handle_add_entropy_to_pad(const char* pad_chksum) {
|
||||||
printf("\n=== Add Entropy to Pad: %.16s... ===\n", pad_chksum);
|
printf("\n=== Add Entropy to Pad: %.16s... ===\n", pad_chksum);
|
||||||
printf("This will enhance the randomness of your pad using keyboard entropy.\n");
|
|
||||||
printf("The entropy will be processed with Chacha20 and distributed throughout the entire pad.\n\n");
|
|
||||||
|
|
||||||
printf("Entropy collection options:\n");
|
// Present entropy source selection menu with consistent formatting
|
||||||
printf(" 1. Recommended (2048 bytes) - Optimal security\n");
|
printf("Select entropy source:\n");
|
||||||
printf(" 2. Minimum (1024 bytes) - Good security\n");
|
printf(" \033[4mK\033[0meyboard entropy - Random typing for entropy collection\n");
|
||||||
printf(" 3. Maximum (4096 bytes) - Maximum security\n");
|
printf(" \033[4mD\033[0mice rolls - Manual dice roll input for high-quality entropy\n");
|
||||||
printf(" 4. Custom amount\n");
|
printf(" \033[4mT\033[0mrueRNG devices - Hardware random number generators\n");
|
||||||
printf("Enter choice (1-4): ");
|
printf(" E\033[4mx\033[0mit\n");
|
||||||
|
printf("\nSelect option: ");
|
||||||
|
|
||||||
char choice_input[10];
|
char source_input[10];
|
||||||
if (!fgets(choice_input, sizeof(choice_input), stdin)) {
|
if (!fgets(source_input, sizeof(source_input), stdin)) {
|
||||||
printf("Error: Failed to read input\n");
|
printf("Error: Failed to read input\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t target_bytes = 2048; // Default
|
char choice = toupper(source_input[0]);
|
||||||
int choice = atoi(choice_input);
|
entropy_source_t entropy_source;
|
||||||
|
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
case 1:
|
case 'K':
|
||||||
target_bytes = 2048;
|
entropy_source = ENTROPY_SOURCE_KEYBOARD;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 'D':
|
||||||
target_bytes = 1024;
|
entropy_source = ENTROPY_SOURCE_DICE;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 'T':
|
||||||
target_bytes = 4096;
|
entropy_source = ENTROPY_SOURCE_TRUERNG;
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
printf("Enter custom amount (512-8192 bytes): ");
|
|
||||||
char custom_input[32];
|
|
||||||
if (!fgets(custom_input, sizeof(custom_input), stdin)) {
|
|
||||||
printf("Error: Failed to read input\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t custom_amount = (size_t)atoi(custom_input);
|
|
||||||
if (custom_amount < 512 || custom_amount > 8192) {
|
|
||||||
printf("Error: Invalid amount. Must be between 512 and 8192 bytes.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
target_bytes = custom_amount;
|
|
||||||
break;
|
break;
|
||||||
|
case 'X':
|
||||||
|
return 0; // Exit
|
||||||
default:
|
default:
|
||||||
target_bytes = 2048; // Default to recommended
|
printf("Invalid choice. Please select K, D, T, or X.\n");
|
||||||
break;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\nCollecting %zu bytes of entropy...\n", target_bytes);
|
size_t target_bytes;
|
||||||
|
|
||||||
|
// For TrueRNG, automatically use the full pad size
|
||||||
|
if (entropy_source == ENTROPY_SOURCE_TRUERNG) {
|
||||||
|
// Get the pad file size
|
||||||
|
char pad_path[1024];
|
||||||
|
char state_path[1024];
|
||||||
|
get_pad_path(pad_chksum, pad_path, state_path);
|
||||||
|
|
||||||
|
struct stat pad_stat;
|
||||||
|
if (stat(pad_path, &pad_stat) != 0) {
|
||||||
|
printf("Error: Cannot get pad file size\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
target_bytes = (size_t)pad_stat.st_size;
|
||||||
|
printf("\nTrueRNG selected - will enhance entire pad with hardware entropy\n");
|
||||||
|
printf("Pad size: %.2f GB (%zu bytes)\n",
|
||||||
|
(double)target_bytes / (1024.0 * 1024.0 * 1024.0), target_bytes);
|
||||||
|
} else {
|
||||||
|
// For other entropy sources, show the selection menu
|
||||||
|
printf("\nEntropy collection options:\n");
|
||||||
|
printf(" 1. Recommended (2048 bytes) - Optimal security\n");
|
||||||
|
printf(" 2. Minimum (1024 bytes) - Good security\n");
|
||||||
|
printf(" 3. Maximum (4096 bytes) - Maximum security\n");
|
||||||
|
printf(" 4. Custom amount\n");
|
||||||
|
printf("Enter choice (1-4): ");
|
||||||
|
|
||||||
|
char amount_input[10];
|
||||||
|
if (!fgets(amount_input, sizeof(amount_input), stdin)) {
|
||||||
|
printf("Error: Failed to read input\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
target_bytes = 2048; // Default
|
||||||
|
int amount_choice = atoi(amount_input);
|
||||||
|
|
||||||
|
switch (amount_choice) {
|
||||||
|
case 1:
|
||||||
|
target_bytes = 2048;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
target_bytes = 1024;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
target_bytes = 4096;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
printf("Enter custom amount (512-8192 bytes): ");
|
||||||
|
char custom_input[32];
|
||||||
|
if (!fgets(custom_input, sizeof(custom_input), stdin)) {
|
||||||
|
printf("Error: Failed to read input\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t custom_amount = (size_t)atoi(custom_input);
|
||||||
|
if (custom_amount < 512 || custom_amount > 8192) {
|
||||||
|
printf("Error: Invalid amount. Must be between 512 and 8192 bytes.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
target_bytes = custom_amount;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
target_bytes = 2048; // Default to recommended
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nCollecting %zu bytes of entropy from selected source...\n", target_bytes);
|
||||||
|
|
||||||
// Allocate entropy buffer
|
// Allocate entropy buffer
|
||||||
unsigned char* entropy_buffer = malloc(MAX_ENTROPY_BUFFER);
|
unsigned char* entropy_buffer = malloc(MAX_ENTROPY_BUFFER);
|
||||||
@@ -4356,9 +4806,9 @@ int handle_add_entropy_to_pad(const char* pad_chksum) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect entropy with visual feedback
|
// Collect entropy using unified interface
|
||||||
size_t collected_bytes = 0;
|
size_t collected_bytes = 0;
|
||||||
int result = collect_entropy_with_feedback(entropy_buffer, target_bytes, &collected_bytes, 1);
|
int result = collect_entropy_by_source(entropy_source, entropy_buffer, target_bytes, &collected_bytes, 1);
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
printf("Error: Entropy collection failed\n");
|
printf("Error: Entropy collection failed\n");
|
||||||
@@ -4393,8 +4843,9 @@ int handle_add_entropy_to_pad(const char* pad_chksum) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void print_usage(const char* program_name) {
|
void print_usage(const char* program_name) {
|
||||||
printf("OTP Cipher - One Time Pad Implementation v0.2.109\n");
|
printf("OTP Cipher - One Time Pad Implementation v0.3.8\n");
|
||||||
printf("Built for testing entropy system\n");
|
printf("Built for testing entropy system\n");
|
||||||
printf("Usage:\n");
|
printf("Usage:\n");
|
||||||
printf(" %s - Interactive mode\n", program_name);
|
printf(" %s - Interactive mode\n", program_name);
|
||||||
|
|||||||
46
otp.h
46
otp.h
@@ -14,7 +14,13 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
#define MAX_INPUT_SIZE 4096
|
#define MAX_INPUT_SIZE 4096
|
||||||
@@ -92,6 +98,11 @@ int set_default_pad_path(const char* pad_path);
|
|||||||
// OTP thumb drive detection function
|
// OTP thumb drive detection function
|
||||||
int detect_otp_thumb_drive(char* otp_drive_path, size_t path_size);
|
int detect_otp_thumb_drive(char* otp_drive_path, size_t path_size);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// USB DRIVE MANAGEMENT FUNCTIONS
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// EXTERNAL TOOL INTEGRATION FUNCTIONS
|
// EXTERNAL TOOL INTEGRATION FUNCTIONS
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -119,6 +130,13 @@ int decrypt_ascii_file(const char* input_file, const char* output_file);
|
|||||||
// ENHANCED ENTROPY SYSTEM FUNCTIONS
|
// ENHANCED ENTROPY SYSTEM FUNCTIONS
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Entropy source types
|
||||||
|
typedef enum {
|
||||||
|
ENTROPY_SOURCE_KEYBOARD = 1,
|
||||||
|
ENTROPY_SOURCE_DICE = 2,
|
||||||
|
ENTROPY_SOURCE_TRUERNG = 3
|
||||||
|
} entropy_source_t;
|
||||||
|
|
||||||
// Terminal control for entropy collection
|
// Terminal control for entropy collection
|
||||||
int setup_raw_terminal(struct termios* original_termios);
|
int setup_raw_terminal(struct termios* original_termios);
|
||||||
void restore_terminal(struct termios* original_termios);
|
void restore_terminal(struct termios* original_termios);
|
||||||
@@ -130,6 +148,34 @@ void display_entropy_progress(const entropy_collection_state_t* state);
|
|||||||
void draw_progress_bar(double percentage, int width);
|
void draw_progress_bar(double percentage, int width);
|
||||||
void draw_quality_bar(double quality, int width, const char* label);
|
void draw_quality_bar(double quality, int width, const char* label);
|
||||||
|
|
||||||
|
// TrueRNG Device Constants (updated to match otp.c implementation)
|
||||||
|
#define TRUERNG_VID "04D8"
|
||||||
|
#define TRUERNG_PID "F5FE"
|
||||||
|
#define TRUERNGPRO_VID "16D0"
|
||||||
|
#define TRUERNGPRO_PID "0AA0"
|
||||||
|
#define TRUERNGPROV2_VID "04D8"
|
||||||
|
#define TRUERNGPROV2_PID "EBB5"
|
||||||
|
|
||||||
|
// TrueRNG Device Type enumeration
|
||||||
|
typedef enum {
|
||||||
|
TRUERNG_ORIGINAL = 1,
|
||||||
|
TRUERNG_PRO = 2,
|
||||||
|
TRUERNG_PRO_V2 = 3
|
||||||
|
} truerng_device_type_t;
|
||||||
|
|
||||||
|
// TrueRNG entropy collection functions (updated to match implementation)
|
||||||
|
int find_truerng_port(char* port_path, size_t port_path_size, truerng_device_type_t* device_type);
|
||||||
|
int setup_truerng_serial_port(const char* port_path);
|
||||||
|
int collect_truerng_entropy(unsigned char* entropy_buffer, size_t target_bytes, size_t* collected_bytes, int display_progress);
|
||||||
|
const char* get_truerng_device_name(truerng_device_type_t device_type);
|
||||||
|
int read_usb_device_info(const char* port_name, char* vid, char* pid);
|
||||||
|
|
||||||
|
// Dice entropy collection functions (updated to match implementation)
|
||||||
|
int collect_dice_entropy(unsigned char* entropy_buffer, size_t target_bytes, size_t* collected_bytes, int display_progress);
|
||||||
|
|
||||||
|
// Unified entropy collection interface (updated to match implementation)
|
||||||
|
int collect_entropy_by_source(entropy_source_t source, unsigned char* entropy_buffer, size_t target_bytes, size_t* collected_bytes, int display_progress);
|
||||||
|
|
||||||
// Entropy quality calculation
|
// Entropy quality calculation
|
||||||
double calculate_timing_quality(const entropy_collection_state_t* state);
|
double calculate_timing_quality(const entropy_collection_state_t* state);
|
||||||
double calculate_variety_quality(const entropy_collection_state_t* state);
|
double calculate_variety_quality(const entropy_collection_state_t* state);
|
||||||
|
|||||||
1
true_rng
Submodule
1
true_rng
Submodule
Submodule true_rng added at 52ed7af980
Reference in New Issue
Block a user