UNPKG

crypto-keygen-suite

Version:

Key generation utilities for cryptographic operations. YES I RENAMED IT. SIX STATE PROTOCOL!!! See its folder for all <3

74 lines (62 loc) 2.47 kB
import pkg from 'dilithium-crystals'; import yargs from 'yargs/yargs'; import { hideBin } from 'yargs/helpers'; import fs from 'fs'; const Dilithium = pkg.dilithium || pkg.default?.dilithium || pkg; // Ensure correct reference async function generateDilithiumKeys(size, hash, rawOutput, secure) { try { if (!Dilithium.keyPair) { throw new Error("Dilithium module does not expose keyPair correctly. Check the package."); } const { publicKey, privateKey } = await Dilithium.keyPair(); // Directly call the function console.log(`Dilithium Key Pair Generated (Size: ${size}, Hash: ${hash})`); if (rawOutput) { console.log(`Public Key (RAW):`, publicKey); console.log(`Private Key (RAW):`, privateKey); } else { console.log(`Public Key (HEX): ${Buffer.from(publicKey).toString('hex')}`); console.log(`Private Key (HEX): ${Buffer.from(privateKey).toString('hex')}`); } if (secure) { console.log("Secure Mode Enabled: Keys will be stored in a protected file."); fs.writeFileSync(`dilithium_${size}_pubkey.raw`, publicKey); fs.writeFileSync(`dilithium_${size}_privkey.raw`, privateKey); } return { publicKey, privateKey }; } catch (error) { console.error(`Key Generation Failed: ${error.message}`); } } async function main() { const argv = yargs(hideBin(process.argv)) .option('size', { alias: 's', type: 'number', default: 3, choices: [2, 3, 5], // NIST-recommended parameter sets describe: 'Dilithium parameter set (2, 3, or 5)' }) .option('hash', { alias: 'h', type: 'string', default: 'SHA3', choices: ['SHA3', 'Shake256'], describe: 'Hash function used in signing' }) .option('rawOutput', { alias: 'r', type: 'boolean', default: false, describe: 'Output keys in raw format' }) .option('secure', { alias: 'p', type: 'boolean', default: false, describe: 'Enable secure key storage' }) .argv; await generateDilithiumKeys(argv.size, argv.hash, argv.rawOutput, argv.secure); } console.log(pkg); main();