Exemple #1
0
		/**
		 * this test is can take quiet a while
		 */
		private void doTestGeneration(
			int size)
		{
			DHParametersGenerator pGen = new DHParametersGenerator();

			pGen.Init(size, 10, new SecureRandom());

			DHParameters dhParams = pGen.GenerateParameters();

			if (dhParams.L != 0)
			{
				Fail("DHParametersGenerator failed to set J to 0 in generated DHParameters");
			}

			DHKeyGenerationParameters dhkgParams = new DHKeyGenerationParameters(new SecureRandom(), dhParams);

			DHBasicKeyPairGenerator kpGen = new DHBasicKeyPairGenerator();

			kpGen.Init(dhkgParams);

			//
			// generate first pair
			//
			AsymmetricCipherKeyPair pair = kpGen.GenerateKeyPair();

			DHPublicKeyParameters pu1 = (DHPublicKeyParameters)pair.Public;
			DHPrivateKeyParameters pv1 = (DHPrivateKeyParameters)pair.Private;

			//
			// generate second pair
			//
			dhkgParams = new DHKeyGenerationParameters(new SecureRandom(), pu1.Parameters);

			kpGen.Init(dhkgParams);

			pair = kpGen.GenerateKeyPair();

			DHPublicKeyParameters pu2 = (DHPublicKeyParameters)pair.Public;
			DHPrivateKeyParameters pv2 = (DHPrivateKeyParameters)pair.Private;

			//
			// two way
			//
			DHBasicAgreement e1 = new DHBasicAgreement();
			DHBasicAgreement e2 = new DHBasicAgreement();

			e1.Init(new ParametersWithRandom(pv1, new SecureRandom()));
			e2.Init(new ParametersWithRandom(pv2, new SecureRandom()));

			BigInteger k1 = e1.CalculateAgreement(pu2);
			BigInteger k2 = e2.CalculateAgreement(pu1);

			if (!k1.Equals(k2))
			{
				Fail("basic with " + size + " bit 2-way test failed");
			}
		}
Exemple #2
0
        private void testWithRandomParams(int bits)
        {
            DHParametersGenerator paramGen = new DHParametersGenerator();
            paramGen.Init(bits, 25, random);
            DHParameters parameters = paramGen.GenerateParameters();

            BigInteger g = parameters.G;
            BigInteger p = parameters.P;

            testMutualVerification(p, g);
        }
 public static DHParameters GenerateParameters()
 {
     var generator = new DHParametersGenerator();
     generator.Init(256, 30, new SecureRandom());
     return generator.GenerateParameters();
 }
 public static DHParameters GenerateParameters(int keyLength, int probability)
 {
     DHParametersGenerator generator = new DHParametersGenerator();
     generator.Init(keyLength, probability, new SecureRandom());
     return generator.GenerateParameters();
 }
Exemple #5
0
		private void testWithRandomParams(int bits)
		{
	        DHParametersGenerator paramGen = new DHParametersGenerator();
	        paramGen.Init(bits, 25, random);
	        DHParameters parameters = paramGen.GenerateParameters();

            testMutualVerification(new Srp6GroupParameters(parameters.P, parameters.G));
		}
 private static DHParameters GetDiffieHellmanParameters(int bitLength, int probability)
 {
     DHParametersGenerator generator = new DHParametersGenerator();
     generator.Init(bitLength, probability, new SecureRandom());
     return generator.GenerateParameters();
 }