Org.BouncyCastle.Crypto.Engines.Salsa20Engine.ReturnByte C# (CSharp) Метод

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

public ReturnByte ( byte input ) : byte
input byte
Результат byte
		public byte ReturnByte(
			byte input)
		{
			if (limitExceeded())
			{
				throw new MaxBytesExceededException("2^70 byte limit per IV; Change IV");
			}

			if (index == 0)
			{
				salsa20WordToByte(engineState, keyStream);
				engineState[8]++;
				if (engineState[8] == 0)
				{
					engineState[9]++;
				}
			}
			byte output = (byte)(keyStream[index]^input);
			index = (index + 1) & 63;
	    
			return output;
		}

Usage Example

Пример #1
0
		private void salsa20Test1(
			int rounds,
			ICipherParameters	parameters,
			string				v0,
			string				v192,
			string				v256,
			string				v448)
		{
			IStreamCipher salsa = new Salsa20Engine(rounds);
			byte[]       buf = new byte[64];

			salsa.Init(true, parameters);

			for (int i = 0; i != 7; i++)
			{
				salsa.ProcessBytes(zeroes, 0, 64, buf, 0);
				switch (i)
				{
				case 0:
					if (!AreEqual(buf, Hex.Decode(v0)))
					{
						mismatch("v0/" + rounds, v0, buf);
					}
					break;
				case 3:
					if (!AreEqual(buf, Hex.Decode(v192)))
					{
						mismatch("v192/" + rounds, v192, buf);
					}
					break;
				case 4:
					if (!AreEqual(buf, Hex.Decode(v256)))
					{
						mismatch("v256/" + rounds, v256, buf);
					}
					break;
				default:
					// ignore
					break;
				}
			}

			for (int i = 0; i != 64; i++)
			{
				buf[i] = salsa.ReturnByte(zeroes[i]);
			}

			if (!AreEqual(buf, Hex.Decode(v448)))
			{
				mismatch("v448", v448, buf);
			}       
		}