ProcessBlock() public method

public ProcessBlock ( byte input, int inOff, int length ) : byte[]
input byte
inOff int
length int
return byte[]
Esempio n. 1
0
		public void TestInvalidP()
		{
			ElGamalParameters dhParams = new ElGamalParameters(pPgpBogusPSamp, gPgpBogusPSamp, lPgpBogusPSamp);
			ElGamalPublicKeyParameters pu = new ElGamalPublicKeyParameters(yPgpBogusPSamp, dhParams);
			ElGamalPrivateKeyParameters pv = new ElGamalPrivateKeyParameters(xPgpBogusPSamp, dhParams);

			ElGamalEngine e = new ElGamalEngine();

			e.Init(true, pu);

			byte[] message = Hex.Decode("5468697320697320612074657374");

			byte[] pText = message;
			byte[] cText = e.ProcessBlock(pText, 0, pText.Length);

			e.Init(false, pv);

			pText = e.ProcessBlock(cText, 0, cText.Length);

			if (Arrays.AreEqual(message, pText))
			{
				Fail("invalid test failed");
			}
		}
Esempio n. 2
0
		private void doTestEnc(
			int         size,
			int         privateValueSize,
			BigInteger  g,
			BigInteger  p)
		{
			ElGamalParameters dhParams = new ElGamalParameters(p, g, privateValueSize);
			ElGamalKeyGenerationParameters ekgParams = new ElGamalKeyGenerationParameters(new SecureRandom(), dhParams);
			ElGamalKeyPairGenerator kpGen = new ElGamalKeyPairGenerator();

			kpGen.Init(ekgParams);

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

			ElGamalPublicKeyParameters pu = (ElGamalPublicKeyParameters) pair.Public;
			ElGamalPrivateKeyParameters pv = (ElGamalPrivateKeyParameters) pair.Private;

			checkKeySize(privateValueSize, pv);

			ElGamalEngine e = new ElGamalEngine();

			e.Init(true, pu);

			if (e.GetOutputBlockSize() != size / 4)
			{
				Fail(size + " GetOutputBlockSize() on encryption failed.");
			}

			byte[] message = Hex.Decode("5468697320697320612074657374");

			byte[] pText = message;
			byte[] cText = e.ProcessBlock(pText, 0, pText.Length);

			e.Init(false, pv);

			if (e.GetOutputBlockSize() != (size / 8) - 1)
			{
				Fail(size + " GetOutputBlockSize() on decryption failed.");
			}

			pText = e.ProcessBlock(cText, 0, cText.Length);

			if (!Arrays.AreEqual(message, pText))
			{
				Fail(size + " bit test failed");
			}



			e.Init(true, pu);
			byte[] bytes = new byte[e.GetInputBlockSize() + 2];

			try
			{
				e.ProcessBlock(bytes, 0, bytes.Length);

				Fail("out of range block not detected");
			}
			catch (DataLengthException)
			{
				// expected
			}

			try
			{
				bytes[0] = (byte)0xff;

				e.ProcessBlock(bytes, 0, bytes.Length - 1);

				Fail("out of range block not detected");
			}
			catch (DataLengthException)
			{
				// expected
			}

			try
			{
				bytes[0] = (byte)0x7f;

				e.ProcessBlock(bytes, 0, bytes.Length - 1);
			}
			catch (DataLengthException)
			{
				Fail("in range block failed");
			}
		}
Esempio n. 3
0
		/**
		 * this test is can take quiet a while
		 *
		 * @param size size of key in bits.
		 */
		private void doTestGeneration(
			int size)
		{
			ElGamalParametersGenerator pGen = new ElGamalParametersGenerator();

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

			ElGamalParameters elParams = pGen.GenerateParameters();

			if (elParams.L != 0)
			{
				Fail("ElGamalParametersGenerator failed to set L to 0 in generated ElGamalParameters");
			}

			ElGamalKeyGenerationParameters ekgParams = new ElGamalKeyGenerationParameters(new SecureRandom(), elParams);

			ElGamalKeyPairGenerator kpGen = new ElGamalKeyPairGenerator();

			kpGen.Init(ekgParams);

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

			ElGamalPublicKeyParameters pu = (ElGamalPublicKeyParameters)pair.Public;
			ElGamalPrivateKeyParameters pv = (ElGamalPrivateKeyParameters)pair.Private;

			ElGamalEngine e = new ElGamalEngine();

			e.Init(true, new ParametersWithRandom(pu, new SecureRandom()));

			byte[] message = Hex.Decode("5468697320697320612074657374");

			byte[] pText = message;
			byte[] cText = e.ProcessBlock(pText, 0, pText.Length);

			e.Init(false, pv);

			pText = e.ProcessBlock(cText, 0, cText.Length);

			if (!Arrays.AreEqual(message, pText))
			{
				Fail("generation test failed");
			}
		}