generate_keys.rs
1 use pqcrypto_kyber::kyber1024; 2 use pqcrypto_traits::kem::{PublicKey, SecretKey}; 3 use std::fs; 4 use std::io::{self, Write}; 5 use hex; 6 use sha3::{Sha3_256, digest::{Digest, Update}}; 7 8 fn main() -> Result<(), Box<dyn std::error::Error>> { 9 println!("=== GHOSTLINE KEY GENERATION TOOL ==="); 10 println!("Generate your personal Kyber keypair\n"); 11 12 // 1. GET USER'S NAME 13 println!("1. š¤ YOUR IDENTITY"); 14 print!("Enter your name/nickname (e.g., 'alice'): "); 15 io::stdout().flush()?; 16 let mut name = String::new(); 17 io::stdin().read_line(&mut name)?; 18 let name = name.trim(); 19 20 if name.is_empty() { 21 return Err("Name cannot be empty!".into()); 22 } 23 24 // 2. GENERATE KEYPAIR 25 println!("\n2. š GENERATING KYBER-1024 KEYPAIR"); 26 println!(" (This may take a moment...)"); 27 28 let (public_key, secret_key) = kyber1024::keypair(); 29 30 let public_bytes = public_key.as_bytes(); 31 let secret_bytes = secret_key.as_bytes(); 32 33 println!("ā Keypair generated!"); 34 println!(" Public key: {} bytes (will share)", public_bytes.len()); 35 println!(" Secret key: {} bytes (keep secret)", secret_bytes.len()); 36 37 // 3. CREATE OUTPUT DIRECTORY 38 let keys_dir = "./my_ghostline_keys/"; 39 fs::create_dir_all(keys_dir)?; 40 41 // 4. SAVE KEYS WITH CLEAR NAMES 42 let public_filename = format!("{}_public.key", name); 43 let secret_filename = format!("{}_secret.key", name); 44 45 let public_path = format!("{}{}", keys_dir, public_filename); 46 let secret_path = format!("{}{}", keys_dir, secret_filename); 47 48 fs::write(&public_path, public_bytes)?; 49 fs::write(&secret_path, secret_bytes)?; 50 51 println!("\n3. š¾ KEYS SAVED"); 52 println!(" Public key: {}", public_path); 53 println!(" Secret key: {}", secret_path); 54 55 // 5. CREATE FINGERPRINT FOR VERIFICATION 56 println!("\n4. š PUBLIC KEY FINGERPRINT"); 57 58 let mut hasher = Sha3_256::new(); 59 Update::update(&mut hasher, public_bytes); 60 let fingerprint = hasher.finalize(); 61 62 println!(" SHA3-256: {}", hex::encode(&fingerprint)); 63 println!(" Short: {}...", hex::encode(&fingerprint[..8])); 64 65 // 6. CREATE README WITH INSTRUCTIONS 66 let readme = format!( 67 "=== GHOSTLINE KEYS FOR {} ===\n\ 68 \nš KEY FILES:\n\ 69 1. {}_public.key - SHARE THIS WITH GHOSTLINE ADMIN\n\ 70 2. {}_secret.key - KEEP THIS SECRET AND SAFE\n\ 71 \nš¤ WHAT TO DO:\n\ 72 1. Send '{}_public.key' to GhostLine admin\n\ 73 2. Keep '{}_secret.key' on your computer\n\ 74 3. Never share your secret key with anyone\n\ 75 4. Backup your secret key securely\n\ 76 \nš VERIFICATION:\n\ 77 Public key fingerprint (SHA3-256):\n\ 78 {}\n\ 79 \nShare this fingerprint with admin to verify.\n", 80 name.to_uppercase(), 81 name, name, 82 name, name, 83 hex::encode(&fingerprint) 84 ); 85 86 fs::write(format!("{}/README_{}.txt", keys_dir, name), readme)?; 87 88 // 7. FINAL INSTRUCTIONS 89 println!("\n5. š NEXT STEPS"); 90 println!(" 1. Send this file to GhostLine admin:"); 91 println!(" š¤ {}", public_filename); 92 println!(" 2. Keep this file SECRET on your computer:"); 93 println!(" š {}", secret_filename); 94 println!(" 3. Save this fingerprint for verification:"); 95 println!(" š {}...", hex::encode(&fingerprint[..8])); 96 97 println!("\nā ļø SECURITY WARNING:"); 98 println!(" ⢠Your secret key is like a password - keep it safe!"); 99 println!(" ⢠Never email or message your secret key"); 100 println!(" ⢠Store backup securely (encrypted USB, password manager)"); 101 println!(" ⢠If secret key is lost, you cannot decrypt OTPs"); 102 103 println!("\nā KEY GENERATION COMPLETE!"); 104 println!(" You're now ready to receive GhostLine OTPs."); 105 106 Ok(()) 107 }