int main(int argc, char **argv) { if (argc != 3) { showUsage(); return 1; } int securityLevel = atoi(argv[1]); string rngSeed(argv[2]); size_t rngSeedLength = 16; string fullLine; string line; while (getline(cin, line)) { fullLine.append(line); } byte *inputData = (byte *) fullLine.data(); int inputLength = fullLine.length(); RegisterFactories(); rngSeed.resize(rngSeedLength); s_globalRNG.SetKeyWithIV((byte *)rngSeed.data(), rngSeedLength, (byte *)rngSeed.data()); int securityIndex = 0; for (int i = 0; i < NUMBER_OF_SECURITY_LENGTHS; i++) { if (securityLevels[i] == securityLevel) { securityIndex = i; break; } } ProfileSignatureSchemes(inputData, inputLength, securityIndex); }
int CRYPTOPP_API main(int argc, char *argv[]) { #ifdef _CRTDBG_LEAK_CHECK_DF // Turn on leak-checking int tempflag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ); tempflag |= _CRTDBG_LEAK_CHECK_DF; _CrtSetDbgFlag( tempflag ); #endif #if defined(__MWERKS__) && defined(macintosh) argc = ccommand(&argv); #endif try { RegisterFactories(); std::string seed = IntToString(time(NULL)); seed.resize(16); s_globalRNG.SetKeyWithIV((byte *)seed.data(), 16, (byte *)seed.data()); std::string command, executableName, macFilename; if (argc < 2) command = 'h'; else command = argv[1]; if (command == "g") { char seed[1024], privFilename[128], pubFilename[128]; unsigned int keyLength; cout << "Key length in bits: "; cin >> keyLength; cout << "\nSave private key to file: "; cin >> privFilename; cout << "\nSave public key to file: "; cin >> pubFilename; cout << "\nRandom Seed: "; ws(cin); cin.getline(seed, 1024); GenerateRSAKey(keyLength, privFilename, pubFilename, seed); } else if (command == "rs") RSASignFile(argv[2], argv[3], argv[4]); else if (command == "rv") { bool verified = RSAVerifyFile(argv[2], argv[3], argv[4]); cout << (verified ? "valid signature" : "invalid signature") << endl; } else if (command == "r") { char privFilename[128], pubFilename[128]; char seed[1024], message[1024]; cout << "Private key file: "; cin >> privFilename; cout << "\nPublic key file: "; cin >> pubFilename; cout << "\nRandom Seed: "; ws(cin); cin.getline(seed, 1024); cout << "\nMessage: "; cin.getline(message, 1024); string ciphertext = RSAEncryptString(pubFilename, seed, message); cout << "\nCiphertext: " << ciphertext << endl; string decrypted = RSADecryptString(privFilename, ciphertext.c_str()); cout << "\nDecrypted: " << decrypted << endl; }
bool Validate(int alg, bool thorough, const char *seedInput) { bool result; std::string seed = seedInput ? std::string(seedInput) : IntToString(time(NULL)); seed.resize(16); cout << "Using seed: " << seed << endl << endl; s_globalRNG.SetKeyWithIV((byte *)seed.data(), 16, (byte *)seed.data()); switch (alg) { case 0: result = ValidateAll(thorough); break; case 1: result = TestSettings(); break; case 2: result = TestOS_RNG(); break; case 3: result = ValidateMD5(); break; case 4: result = ValidateSHA(); break; case 5: result = ValidateDES(); break; case 6: result = ValidateIDEA(); break; case 7: result = ValidateARC4(); break; case 8: result = ValidateRC5(); break; case 9: result = ValidateBlowfish(); break; // case 10: result = ValidateDiamond2(); break; case 11: result = ValidateThreeWay(); break; case 12: result = ValidateBBS(); break; case 13: result = ValidateDH(); break; case 14: result = ValidateRSA(); break; case 15: result = ValidateElGamal(); break; case 16: result = ValidateDSA(thorough); break; // case 17: result = ValidateHAVAL(); break; case 18: result = ValidateSAFER(); break; case 19: result = ValidateLUC(); break; case 20: result = ValidateRabin(); break; // case 21: result = ValidateBlumGoldwasser(); break; case 22: result = ValidateECP(); break; case 23: result = ValidateEC2N(); break; // case 24: result = ValidateMD5MAC(); break; case 25: result = ValidateGOST(); break; case 26: result = ValidateTiger(); break; case 27: result = ValidateRIPEMD(); break; case 28: result = ValidateHMAC(); break; // case 29: result = ValidateXMACC(); break; case 30: result = ValidateSHARK(); break; case 32: result = ValidateLUC_DH(); break; case 33: result = ValidateLUC_DL(); break; case 34: result = ValidateSEAL(); break; case 35: result = ValidateCAST(); break; case 36: result = ValidateSquare(); break; case 37: result = ValidateRC2(); break; case 38: result = ValidateRC6(); break; case 39: result = ValidateMARS(); break; case 40: result = ValidateRW(); break; case 41: result = ValidateMD2(); break; case 42: result = ValidateNR(); break; case 43: result = ValidateMQV(); break; case 44: result = ValidateRijndael(); break; case 45: result = ValidateTwofish(); break; case 46: result = ValidateSerpent(); break; case 47: result = ValidateCipherModes(); break; case 48: result = ValidateCRC32(); break; case 49: result = ValidateECDSA(); break; case 50: result = ValidateXTR_DH(); break; case 51: result = ValidateSKIPJACK(); break; case 52: result = ValidateSHA2(); break; case 53: result = ValidatePanama(); break; case 54: result = ValidateAdler32(); break; case 55: result = ValidateMD4(); break; case 56: result = ValidatePBKDF(); break; case 57: result = ValidateESIGN(); break; case 58: result = ValidateDLIES(); break; case 59: result = ValidateBaseCode(); break; case 60: result = ValidateSHACAL2(); break; case 61: result = ValidateCamellia(); break; case 62: result = ValidateWhirlpool(); break; case 63: result = ValidateTTMAC(); break; case 64: result = ValidateSalsa(); break; case 65: result = ValidateSosemanuk(); break; case 66: result = ValidateVMAC(); break; case 67: result = ValidateCCM(); break; case 68: result = ValidateGCM(); break; case 69: result = ValidateCMAC(); break; default: return false; } time_t endTime = time(NULL); cout << "\nTest ended at " << asctime(localtime(&endTime)); cout << "Seed used was: " << seed << endl; return result; }