public void TestDH() { BigInteger g512 = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16); BigInteger p512 = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16); DHParameters dhParams = new DHParameters(p512, g512); DHKeyGenerationParameters parameters = new DHKeyGenerationParameters(new SecureRandom(), dhParams); DHKeyPairGenerator kpGen = new DHKeyPairGenerator(); kpGen.Init(parameters); AsymmetricCipherKeyPair pair = kpGen.GenerateKeyPair(); DHPublicKeyParameters pu1 = (DHPublicKeyParameters)pair.Public; DHPrivateKeyParameters pv1 = (DHPrivateKeyParameters)pair.Private; DHPublicKeyParameters pu2 = new DHPublicKeyParameters(pu1.Y, pu1.Parameters); DHPrivateKeyParameters pv2 = new DHPrivateKeyParameters(pv1.X, pv1.Parameters); DHPublicKeyParameters pu3 = new DHPublicKeyParameters(pv1.X, pu1.Parameters); DHPrivateKeyParameters pv3 = new DHPrivateKeyParameters(pu1.Y, pu1.Parameters); doTest(pu1, pu2, pu3); doTest(pv1, pv2, pv3); DHParameters pr1 = pu1.Parameters; DHParameters pr2 = new DHParameters( pr1.P, pr1.G, pr1.Q, pr1.M, pr1.L, pr1.J, pr1.ValidationParameters); DHParameters pr3 = new DHParameters( pr1.P.Add(BigInteger.Two), pr1.G, pr1.Q, pr1.M, pr1.L, pr1.J, pr1.ValidationParameters); doTest(pr1, pr2, pr3); pr3 = new DHParameters( pr1.P, pr1.G.Add(BigInteger.One), pr1.Q, pr1.M, pr1.L, pr1.J, pr1.ValidationParameters); doTest(pr1, pr2, pr3); pu2 = new DHPublicKeyParameters(pu1.Y, pr2); pv2 = new DHPrivateKeyParameters(pv1.X, pr2); doTest(pu1, pu2, pu3); doTest(pv1, pv2, pv3); DHValidationParameters vp1 = new DHValidationParameters(new byte[20], 1024); DHValidationParameters vp2 = new DHValidationParameters(new byte[20], 1024); DHValidationParameters vp3 = new DHValidationParameters(new byte[24], 1024); doTest(vp1, vp1, vp3); doTest(vp1, vp2, vp3); byte[] bytes = new byte[20]; bytes[0] = 1; vp3 = new DHValidationParameters(bytes, 1024); doTest(vp1, vp2, vp3); vp3 = new DHValidationParameters(new byte[20], 2048); doTest(vp1, vp2, vp3); DHTestKeyParameters k1 = new DHTestKeyParameters(false, null); DHTestKeyParameters k2 = new DHTestKeyParameters(false, null); DHTestKeyParameters k3 = new DHTestKeyParameters(false, pu1.Parameters); doTest(k1, k2, k3); }
public void TestDH() { BigInteger g512 = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16); BigInteger p512 = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16); DHParameters dhParams = new DHParameters(p512, g512); DHKeyGenerationParameters parameters = new DHKeyGenerationParameters(new SecureRandom(), dhParams); DHKeyPairGenerator kpGen = new DHKeyPairGenerator(); kpGen.Init(parameters); AsymmetricCipherKeyPair pair = kpGen.GenerateKeyPair(); DHPublicKeyParameters pu1 = (DHPublicKeyParameters)pair.Public; DHPrivateKeyParameters pv1 = (DHPrivateKeyParameters)pair.Private; DHPublicKeyParameters pu2 = new DHPublicKeyParameters(pu1.Y, pu1.Parameters); DHPrivateKeyParameters pv2 = new DHPrivateKeyParameters(pv1.X, pv1.Parameters); DHPublicKeyParameters pu3 = new DHPublicKeyParameters(pv1.X, pu1.Parameters); DHPrivateKeyParameters pv3 = new DHPrivateKeyParameters(pu1.Y, pu1.Parameters); doTest(pu1, pu2, pu3); doTest(pv1, pv2, pv3); DHParameters pr1 = pu1.Parameters; DHParameters pr2 = new DHParameters( pr1.P, pr1.G, pr1.Q, pr1.M, pr1.L, pr1.J, pr1.ValidationParameters); DHParameters pr3 = new DHParameters( pr1.P.Add(BigInteger.Two), pr1.G, pr1.Q, pr1.M, pr1.L, pr1.J, pr1.ValidationParameters); doTest(pr1, pr2, pr3); pr3 = new DHParameters( pr1.P, pr1.G.Add(BigInteger.One), pr1.Q, pr1.M, pr1.L, pr1.J, pr1.ValidationParameters); doTest(pr1, pr2, pr3); pu2 = new DHPublicKeyParameters(pu1.Y, pr2); pv2 = new DHPrivateKeyParameters(pv1.X, pr2); doTest(pu1, pu2, pu3); doTest(pv1, pv2, pv3); DHValidationParameters vp1 = new DHValidationParameters(new byte[20], 1024); DHValidationParameters vp2 = new DHValidationParameters(new byte[20], 1024); DHValidationParameters vp3 = new DHValidationParameters(new byte[24], 1024); doTest(vp1, vp1, vp3); doTest(vp1, vp2, vp3); byte[] bytes = new byte[20]; bytes[0] = 1; vp3 = new DHValidationParameters(bytes, 1024); doTest(vp1, vp2, vp3); vp3 = new DHValidationParameters(new byte[20], 2048); doTest(vp1, vp2, vp3); DHTestKeyParameters k1 = new DHTestKeyParameters(false, null); DHTestKeyParameters k2 = new DHTestKeyParameters(false, null); DHTestKeyParameters k3 = new DHTestKeyParameters(false, pu1.Parameters); doTest(k1, k2, k3); }