⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 validat2.cpp

📁 300种加密解密的算法源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			fail = (outLen!=8) || memcmp(out, encrypted, 50) || memcmp(plain, outPlain, 8);
			pass = pass && !fail;

			cout << (fail ? "FAILED    " : "PASSED    ");
			cout << "PKCS 2.0 encryption and decryption\n";
		}
	}
	catch (BERDecodeErr)
	{
		cout << "FAILED    Error decoding RSA key\n";
		pass = false;
	}

	return pass;
}

bool DHValidate()
{
	cout << "\nDH validation suite running...\n\n";

	FileSource f("dh512.dat", true, new HexDecoder());
	DH dh(f);
	return SimpleKeyAgreementValidate(dh);
}

bool MQVValidate()
{
	cout << "\nMQV validation suite running...\n\n";

	FileSource f("mqv512.dat", true, new HexDecoder());
	MQV mqv(f);
	return AuthenticatedKeyAgreementValidate(mqv);
}

bool LUCDIFValidate()
{
	cout << "\nLUCDIF validation suite running...\n\n";

	FileSource f("lucdif.dat", true, new HexDecoder());
	LUCDIF dh(f);
	return SimpleKeyAgreementValidate(dh);
}

bool ElGamalValidate()
{
	cout << "\nElGamal validation suite running...\n\n";
	bool pass = true;
	{
		FileSource fc("elgc2048.dat", true, new HexDecoder);
		ElGamalDecryptor privC(fc);
		ElGamalEncryptor pubC(privC);
		pubC.Precompute();

		pass = CryptoSystemValidate(privC, pubC) && pass;
	}
	{
		LC_RNG rng(4780);
		cout << "Generating new encryption key..." << endl;
		ElGamalDecryptor privC(rng, 128);
		ElGamalEncryptor pubC(privC);

		pass = CryptoSystemValidate(privC, pubC) && pass;
	}
	return pass;
}

bool NRValidate()
{
	cout << "\nNR validation suite running...\n\n";
	bool pass = true;
	{
		FileSource f("nr2048.dat", true, new HexDecoder);
		NRSigner<SHA> privS(f);
		privS.Precompute();
		NRVerifier<SHA> pubS(privS);

		pass = SignatureValidate(privS, pubS) && pass;
	}
	{
		LC_RNG rng(4781);
		cout << "Generating new signature key..." << endl;
		NRSigner<SHA> privS(rng, 256);
		NRVerifier<SHA> pubS(privS);

		pass = SignatureValidate(privS, pubS) && pass;
	}
	return pass;
}

bool DSAValidate()
{
	cout << "\nDSA validation suite running...\n\n";

	bool pass = true, fail;
	{
	FileSource fs("dsa512.dat", true, new HexDecoder());
	DSAPrivateKey priv(fs);
	priv.Precompute(16);
	DSAPublicKey pub(priv);

	Integer k("79577ddcaafddc038b865b19f8eb1ada8a2838c6h");
	Integer h("0164b8a914cd2a5e74c4f7ff082c4d97f1edf880h");
	Integer r("9b77,f705,4c81,531c,4e46,a469,2fbf,e0f7,7f7e,bff2h");
	Integer s("95b4,f608,1f8f,890e,4b5a,199e,f10f,fe21,f52b,2d68h");

	Integer pGen, qGen, rOut, sOut;
	int c;

	byte seed[]={0xd5, 0x01, 0x4e, 0x4b, 0x60, 0xef, 0x2b, 0xa8, 0xb6, 0x21, 
				 0x1b, 0x40, 0x62, 0xba, 0x32, 0x24, 0xe0, 0x42, 0x7d, 0xd3};
	Integer p("8df2a494 492276aa 3d25759b b06869cb eac0d83a fb8d0cf7"
			  "cbb8324f 0d7882e5 d0762fc5 b7210eaf c2e9adac 32ab7aac"
			  "49693dfb f83724c2 ec0736ee 31c80291H");
	Integer q("c773218c 737ec8ee 993b4f2d ed30f48e dace915fH");

	fail = !GenerateDSAPrimes(seed, 160, c, pGen, 512, qGen);
	fail = fail || (pGen != p) || (qGen != q);
	pass = pass && !fail;

	cout << (fail ? "FAILED    " : "PASSED    ");
	cout << "prime generation test\n";

	priv.RawSign(k, h, rOut, sOut);
	fail = (rOut != r) || (sOut != s);
	pass = pass && !fail;

	cout << (fail ? "FAILED    " : "PASSED    ");
	cout << "signature test\n";

	fail = !pub.RawVerify(h, r, s);
	pass = pass && !fail;

	cout << (fail ? "FAILED    " : "PASSED    ");
	cout << "valid signature verification\n";

	fail = pub.RawVerify(h+1, r, s);
	pass = pass && !fail;

	cout << (fail ? "FAILED    " : "PASSED    ");
	cout << "invalid signature verification\n";

	pass = SignatureValidate(priv, pub) && pass;
	}
	FileSource fs("dsa1024.dat", true, new HexDecoder());
	DSAPrivateKey priv(fs);
	priv.LoadPrecomputation(fs);
	DSAPublicKey pub(priv);
	pass = SignatureValidate(priv, pub) && pass;
	return pass;
}

bool LUCValidate()
{
	cout << "\nLUC validation suite running...\n\n";
	bool pass=true;

	{
		FileSource f("luc512.dat", true, new HexDecoder);
		LUCSSA_PKCS1v15_SHA_Signer priv(f);
		LUCSSA_PKCS1v15_SHA_Verifier pub(priv);
		pass = SignatureValidate(priv, pub) && pass;
	}
	{
		FileSource f("luc512.dat", true, new HexDecoder);
		LUCES_OAEP_SHA_Decryptor priv(f);
		LUCES_OAEP_SHA_Encryptor pub(priv);
		pass = CryptoSystemValidate(priv, pub) && pass;
	}
	return pass;
}

bool LUCELGValidate()
{
	cout << "\nLUCELG validation suite running...\n\n";

	FileSource f("lucs512.dat", true, new HexDecoder);
	LUCELG_Signer<SHA> privS(f);
	LUCELG_Verifier<SHA> pubS(privS);

	bool pass = SignatureValidate(privS, pubS);

	FileSource fc("lucc512.dat", true, new HexDecoder);
	LUCELG_Decryptor privC(fc);
	LUCELG_Encryptor pubC(privC);

	pass = CryptoSystemValidate(privC, pubC) && pass;

	return pass;
}

bool RabinValidate()
{
	cout << "\nRabin validation suite running...\n\n";
	bool pass=true;

	{
		FileSource f("rabi512.dat", true, new HexDecoder);
		RabinSignerWith(SHA) priv(f);
		RabinVerifierWith(SHA) pub(priv);
		pass = SignatureValidate(priv, pub) && pass;
	}
	{
		FileSource f("rabi512.dat", true, new HexDecoder);
		RabinDecryptor priv(f);
		RabinEncryptor pub(priv);
		pass = CryptoSystemValidate(priv, pub) && pass;
	}
	return pass;
}

bool RWValidate()
{
	cout << "\nRW validation suite running...\n\n";

	FileSource f("rw512.dat", true, new HexDecoder);
	RWSigner<SHA> priv(f);
	RWVerifier<SHA> pub(priv);

	return SignatureValidate(priv, pub);
}

bool BlumGoldwasserValidate()
{
	cout << "\nBlumGoldwasser validation suite running...\n\n";

	FileSource f("blum512.dat", true, new HexDecoder);
	BlumGoldwasserPrivateKey priv(f);
	BlumGoldwasserPublicKey pub(priv);

	return CryptoSystemValidate(priv, pub);
}

bool ECPValidate()
{
	cout << "\nECP validation suite running...\n\n";

	Integer modulus("199999999999999999999999980586675243082581144187569");
	Integer a("659942,b7261b,249174,c86bd5,e2a65b,45fe07,37d110h");
	Integer b("3ece7d,09473d,666000,5baef5,d4e00e,30159d,2df49ah");
	Integer x("25dd61,4c0667,81abc0,fe6c84,fefaa3,858ca6,96d0e8h");
	Integer y("4e2477,05aab0,b3497f,d62b5e,78a531,446729,6c3fach");
	Integer r("100000000000000000000000000000000000000000000000151");
	Integer k(2);
	Integer d("76572944925670636209790912427415155085360939712345");

	ECP ec(modulus, a, b);
	ECP::Point P(x, y);
	P = ec.Multiply(k, P);
	ECP::Point Q(ec.Multiply(d, P));
	ECSigner<ECP, SHA> priv(ec, P, Q, r, d);
	ECVerifier<ECP, SHA> pub(priv);
	ECDHC<ECP> ecdhc(ec, P, r, k);
	ECMQVC<ECP> ecmqvc(ec, P, r, k);

	priv.Precompute();
	ByteQueue queue;
	priv.SavePrecomputation(queue);
	pub.LoadPrecomputation(queue);

	bool pass = SignatureValidate(priv, pub);
	pass = CryptoSystemValidate(priv, pub) && pass;
	pass = SimpleKeyAgreementValidate(ecdhc) && pass;
	pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass;

	return pass;
}

bool EC2NValidate()
{
	cout << "\nEC2N validation suite running...\n\n";

	Integer r("3805993847215893016155463826195386266397436443");
	Integer k(12);
	Integer d("2065729449256706362097909124274151550853609397");

	GF2N gf2n(155, 62, 0);
	byte b[]={0x7, 0x33, 0x8f};
	EC2N ec(gf2n, PolynomialMod2::Zero(), PolynomialMod2(b,3));
	EC2N::Point P(0x7B, 0x1C8);
	P = ec.Multiply(k, P);
	EC2N::Point Q(ec.Multiply(d, P));
	ECSigner<EC2N, SHA> priv(ec, P, Q, r, d);
	ECVerifier<EC2N, SHA> pub(priv);
	ECDHC<EC2N> ecdhc(ec, P, r, k);
	ECMQVC<EC2N> ecmqvc(ec, P, r, k);

	priv.Precompute();
	ByteQueue queue;
	priv.SavePrecomputation(queue);
	pub.LoadPrecomputation(queue);

	bool pass = SignatureValidate(priv, pub);
	pass = CryptoSystemValidate(priv, pub) && pass;
	pass = SimpleKeyAgreementValidate(ecdhc) && pass;
	pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass;

	return pass;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -