コード例 #1
0
        static byte[] ComputeRecordMAC(TlsProtocolCode protocol, HMac hmac, ulong seqnum, ContentType contentType, IBufferOffsetSize fragment)
        {
            var header = new TlsBuffer(13);

            header.Write(seqnum);
            header.Write((byte)contentType);
            header.Write((short)protocol);
            header.Write((short)fragment.Size);

            hmac.Reset();
            hmac.TransformBlock(header.Buffer, 0, header.Size);
            hmac.TransformBlock(fragment.Buffer, fragment.Offset, fragment.Size);
            return(hmac.TransformFinalBlock());
        }
コード例 #2
0
		protected SecureBuffer Expand (DisposeContext d, HMac hmac, string label, SecureBuffer seed, int length)
		{
			var blockSize = hmac.MacSize;
			var iterations = (int)(length / blockSize);
			if ((length % blockSize) > 0)
				iterations++;

			var resMacs = d.CreateBuffer (length);
			var resOff = 0;

			var tempBuf = d.CreateBuffer (blockSize);

			var labelBytes = Encoding.ASCII.GetBytes (label);

			for (int i = 1; i <= iterations; i++) {
				hmac.Reset ();
				if (i == 1) {
					hmac.TransformBlock (labelBytes, 0, labelBytes.Length);
					hmac.TransformBlock (seed.Buffer, 0, seed.Size);
				} else {
					hmac.TransformBlock (tempBuf.Buffer, 0, blockSize);
				}
				hmac.TransformFinalBlock (tempBuf.Buffer, 0, blockSize);

				hmac.Reset ();
				hmac.TransformBlock (tempBuf.Buffer, 0, blockSize);
				hmac.TransformBlock (labelBytes, 0, labelBytes.Length);
				hmac.TransformBlock (seed.Buffer, 0, seed.Size);
				hmac.TransformFinalBlock (resMacs.Buffer, resOff, Min (length - resOff, blockSize));
				resOff += blockSize;
			}

			return new SecureBuffer (resMacs.StealBuffer ());
		}
コード例 #3
0
		static byte[] ComputeRecordMAC (TlsProtocolCode protocol, HMac hmac, ulong seqnum, ContentType contentType, IBufferOffsetSize fragment)
		{
			var header = new TlsBuffer (13);
			header.Write (seqnum);
			header.Write ((byte)contentType);
			header.Write ((short)protocol);
			header.Write ((short)fragment.Size);

			hmac.Reset ();
			hmac.TransformBlock (header.Buffer, 0, header.Size);
			hmac.TransformBlock (fragment.Buffer, fragment.Offset, fragment.Size);
			return hmac.TransformFinalBlock ();
		}
コード例 #4
0
		protected SecureBuffer Expand (DisposeContext d, HMac hmac, string label, SecureBuffer seed, int length)
		{
			var blockSize = hmac.MacSize;
			var iterations = (int)(length / blockSize);
			if ((length % blockSize) > 0)
				iterations++;

			var resMacs = d.CreateBuffer (length);
			var resOff = 0;

			var tempBuf = d.CreateBuffer (blockSize);

			var labelBytes = Encoding.ASCII.GetBytes (label);

			for (int i = 1; i <= iterations; i++) {
				hmac.Reset ();
				if (i == 1) {
					hmac.TransformBlock (labelBytes, 0, labelBytes.Length);
					hmac.TransformBlock (seed.Buffer, 0, seed.Size);
				} else {
					hmac.TransformBlock (tempBuf.Buffer, 0, blockSize);
				}
				hmac.TransformFinalBlock (tempBuf.Buffer, 0, blockSize);

				hmac.Reset ();
				hmac.TransformBlock (tempBuf.Buffer, 0, blockSize);
				hmac.TransformBlock (labelBytes, 0, labelBytes.Length);
				hmac.TransformBlock (seed.Buffer, 0, seed.Size);
				hmac.TransformFinalBlock (resMacs.Buffer, resOff, Min (length - resOff, blockSize));
				resOff += blockSize;
			}

			return new SecureBuffer (resMacs.StealBuffer ());
		}