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);
}
Exemple #2
0
bool RunTestDataFile(const char *filename)
{
	RegisterFactories();
	unsigned int totalTests = 0, failedTests = 0;
	TestDataFile(filename, totalTests, failedTests);
	cout << "\nTests complete. Total tests = " << totalTests << ". Failed tests = " << failedTests << ".\n";
	if (failedTests != 0)
		cout << "SOME TESTS FAILED!\n";
	return failedTests == 0;
}
Exemple #3
0
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
PawsManager::PawsManager(iObjectRegistry* object, const char* skin, const char* skinBase,
                         const char* pawsConfigFile) : render2texture(false)
{
    objectReg = object;
    pawsConfig = pawsConfigFile;

    graphics2D = csQueryRegistry<iGraphics2D > ( objectReg );
    graphics3D = csQueryRegistry<iGraphics3D > ( objectReg );
    soundloader =  csQueryRegistry<iSndSysLoader > ( objectReg);
    soundrenderer =  csQueryRegistry<iSndSysRenderer > ( objectReg);
    nameRegistry = csEventNameRegistry::GetRegistry (objectReg);

    // Initialize event shortcuts
    MouseMove = csevMouseMove (nameRegistry, 0);
    MouseDown = csevMouseDown (nameRegistry, 0);
    MouseDoubleClick = csevMouseDoubleClick (nameRegistry, 0);
    MouseUp = csevMouseUp (nameRegistry, 0);
    KeyboardDown = csevKeyboardDown (objectReg);
    KeyboardUp = csevKeyboardUp (objectReg);

    vfs =  csQueryRegistry<iVFS > ( objectReg);
    xml = csPtr<iDocumentSystem>(new csTinyDocumentSystem);
    csRef<iConfigManager> cfg =  csQueryRegistry<iConfigManager> (objectReg);

    float screenWidth = cfg->GetFloat( "Video.ScreenWidth", 800.0f );
    float screenHeight = cfg->GetFloat( "Video.ScreenHeight", 600.0f );
    fontFactor = min(( screenWidth  / 800.0f ), ( screenHeight /  600.0f ));

    RegisterFactories();

    mainWidget = new pawsMainWidget();

    textureManager = new pawsTextureManager( objectReg );

    prefs = new pawsPrefManager();

    csString prefsFile = cfg->GetStr("PlaneShift.GUI.PrefsFile", "/this/data/prefs.xml");
    csString borderFile = cfg->GetStr("PlaneShift.GUI.BorderFile", "/this/data/gui/borderlist.xml");

    styles = new pawsStyles( objectReg );

    if(!LoadSkinDefinition(skin))
    {
        Error2("Failed to load skin %s!", skin);
        exit(1);
    }

    // now load standard styles for anything else
    if (!styles->LoadStyles("/this/data/gui/styles.xml"))
    {
        Error1("Failed to load PAWS styles, all style application attempts will be ignored");
        delete styles;
        styles = NULL;
    }

    // Mount base skin to satisfy unskinned elements
    if(skinBase)
    {
        if(!LoadSkinDefinition(skinBase))
        {
            Error2("Couldn't load base skin '%s'!\n", skinBase);
        }
    }

    if ( !prefs->LoadPrefFile( prefsFile ) )
        Error2("Failed to load prefsFile '%s'", prefsFile.GetData());
    if ( !prefs->LoadBorderFile( borderFile ) )
        Error2("Failed to load borderFile '%s'", borderFile.GetData());


    mouse = new pawsMouse();
    mouse->ChangeImage("Standard Mouse Pointer");

    resizeImg = textureManager->GetPawsImage("ResizeBox");

    graphics2D->SetMouseCursor( csmcNone );

    currentFocusedWidget = mainWidget;
    movingWidget         = 0;
    focusOverridesControls = false;

    resizingWidget       = 0;
    resizingFlags        = 0;

    modalWidget = 0;
    mouseoverWidget = 0;
    lastfadeWidget = 0;

    assert(cfg);
    csString lang = cfg->GetStr("PlaneShift.GUI.Language", "");
    localization = new psLocalization();
    localization->Initialize(objectReg);
    localization->SetLanguage(lang);

    tipDelay = cfg->GetInt("PlaneShift.GUI.ToolTipDelay", 250);

    hadKeyDown = false;
    dragDropWidget = NULL;
    useSounds = true;
    volume = 1.0;

    soundStatus = false;
    timeOver = 0;

    // Init render texture.
    csRef<iTextureManager> texman = graphics3D->GetTextureManager();
    guiTexture = texman->CreateTexture(graphics3D->GetWidth(), graphics3D->GetHeight(),
      csimg2D, "rgba8", 0x9);
    if(guiTexture.IsValid())
        guiTexture->SetAlphaType (csAlphaMode::alphaBinary);
    else
	render2texture = false;
}
Exemple #4
0
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;
		}