Пример #1
0
Integer ModularRoot(const Integer &a, const Integer &dp, const Integer &dq,
					const Integer &p, const Integer &q, const Integer &u)
{
	Integer p2, q2;
	#pragma omp parallel
		#pragma omp sections
		{
			#pragma omp section
				p2 = ModularExponentiation((a % p), dp, p);
			#pragma omp section
				q2 = ModularExponentiation((a % q), dq, q);
		}
	return CRT(p2, p, q2, q, u);
}
Пример #2
0
/*Generate Group Parameters*/
void GetGroupParameters(Integer &g, Integer &p, Integer &q)
{
	AutoSeededRandomPool rnd;
	unsigned int bits = 1024;

	DH dh;
	dh.AccessGroupParameters().GenerateRandomWithKeySize(rnd, bits);

	if(!dh.GetGroupParameters().ValidateGroup(rnd, 3))
		cout << "Failed to validate prime and generator" << endl;

	size_t count = 0;

	p = dh.GetGroupParameters().GetModulus();
	count = p.BitCount();

	q = dh.GetGroupParameters().GetSubgroupOrder();
	count = q.BitCount();

	g = dh.GetGroupParameters().GetGenerator();
	count = g.BitCount();

	#ifdef DEBUG
	cout << "P (" << std::dec << count << "): " << std::hex << p << endl;
	cout << "Q (" << std::dec << count << "): " << std::hex << q << endl;
	cout << "G (" << std::dec << count << "): " << std::dec << g << endl;
	#endif

	Integer v = ModularExponentiation(g, q, p);
	if(v != Integer::One())
	{
		cout << "Failed to verify order of the subgroup" << endl;
        exit(1);
	}
}