NextBytes() публичный Метод

public NextBytes ( byte bytes ) : void
bytes byte
Результат void
		private void doExpectedTest(IDigest digest, int seed, byte[] expected, byte[] noCycle)
		{
			DigestRandomGenerator rGen = new DigestRandomGenerator(digest);
			byte[] output = new byte[digest.GetDigestSize()];

			rGen.AddSeedMaterial(seed);

			for (int i = 0; i != 1024; i++)
			{
				rGen.NextBytes(output);
			}

			if (noCycle != null)
			{
				if (Arrays.AreEqual(noCycle, output))
				{
					Fail("seed not being cycled!");
				}
			}

			if (!Arrays.AreEqual(expected, output))
			{
				Fail("expected output doesn't match");
			}
		}
Пример #2
0
        private void HandleAuthorizationRequest(AuthorizationRequestPacket packet)
        {
            if (IsInitialized)
                return;

            PlayerRef = new Trainer(packet.Name);

            SendPacket(new AuthorizationResponsePacket { AuthorizationStatus = AuthorizationStatus });

            if (AuthorizationStatus.HasFlag(AuthorizationStatus.EncryprionEnabled))
            {
                var publicKey = Module.RsaKeyPair.PublicKeyToByteArray();

                VerificationToken = new byte[4];
                var drg = new DigestRandomGenerator(new Sha512Digest());
                drg.NextBytes(VerificationToken);

                SendPacket(new EncryptionRequestPacket {PublicKey = publicKey, VerificationToken = VerificationToken});
            }
            else
            {
                if (!IsInitialized)
                {
                    Join();
                    IsInitialized = true;
                }
            }
        }
		private void doCountTest(IDigest digest, byte[] seed, byte[] expectedXors)
		{
			DigestRandomGenerator rGen = new DigestRandomGenerator(digest);
			byte[] output = new byte[digest.GetDigestSize()];
			int[] averages = new int[digest.GetDigestSize()];
			byte[] ands = new byte[digest.GetDigestSize()];
			byte[] xors = new byte[digest.GetDigestSize()];
			byte[] ors = new byte[digest.GetDigestSize()];

			rGen.AddSeedMaterial(seed);

			for (int i = 0; i != 1000000; i++)
			{
				rGen.NextBytes(output);
				for (int j = 0; j != output.Length; j++)
				{
					averages[j] += output[j] & 0xff;
					ands[j] &= output[j];
					xors[j] ^= output[j];
					ors[j] |= output[j];
				}
			}

			for (int i = 0; i != output.Length; i++)
			{
				if ((averages[i] / 1000000) != 127)
				{
					Fail("average test failed for " + digest.AlgorithmName);
				}
				if (ands[i] != 0)
				{
					Fail("and test failed for " + digest.AlgorithmName);
				}
				if ((ors[i] & 0xff) != 0xff)
				{
					Fail("or test failed for " + digest.AlgorithmName);
				}
				if (xors[i] != expectedXors[i])
				{
					Fail("xor test failed for " + digest.AlgorithmName);
				}
			}
		}