コード例 #1
0
        public byte[] TestDigest(HandshakeHashType algorithm, byte[] data)
        {
            var hash = CreateHash(algorithm);

            hash.TransformFinalBlock(data, 0, data.Length);
            return(hash.Hash);
        }
コード例 #2
0
		public byte[] TestPRF (HandshakeHashType algorithm, byte[] secret, string seed, byte[] data, int length)
		{
			var prf = new PseudoRandomFunctionTls12 (algorithm);

			var result = prf.PRF (SecureBuffer.CreateCopy (secret), seed, SecureBuffer.CreateCopy (data), length);
			return result.StealBuffer ();
		}
コード例 #3
0
        public byte[] TestPRF(HandshakeHashType algorithm, byte[] secret, string seed, byte[] data, int length)
        {
            var prf = new PseudoRandomFunctionTls12(algorithm);

            var result = prf.PRF(SecureBuffer.CreateCopy(secret), seed, SecureBuffer.CreateCopy(data), length);

            return(result.StealBuffer());
        }
コード例 #4
0
		HashAlgorithm CreateHash (HandshakeHashType algorithm)
		{
			switch (algorithm) {
			case HandshakeHashType.SHA256:
				return SHA256.Create ();
			case HandshakeHashType.SHA384:
				return SHA384.Create ();
			default:
				throw new NotSupportedException ();
			}
		}
コード例 #5
0
		NativeCryptoHashType GetAlgorithm (HandshakeHashType algorithm)
		{
			switch (algorithm) {
			case HandshakeHashType.SHA256:
				return NativeCryptoHashType.SHA256;
			case HandshakeHashType.SHA384:
				return NativeCryptoHashType.SHA384;
			default:
				throw new NotSupportedException ();
			}
		}
コード例 #6
0
ファイル: HandshakeHash.cs プロジェクト: VimalKumarS/mono-tls
		IHashAlgorithm GetAlgorithm (HandshakeHashType type)
		{
			switch (type) {
			case HandshakeHashType.MD5SHA1:
				return hashes [0];
			case HandshakeHashType.SHA256:
				return hashes [3];
			case HandshakeHashType.SHA384:
				return hashes [4];
			default:
				throw new InvalidOperationException ();
			}
		}
コード例 #7
0
        public byte[] TestHMac(HandshakeHashType algorithm, byte[] key, byte[] data)
        {
            var hmac = HMac.Create(algorithm, SecureBuffer.CreateCopy(key));

            hmac.Reset();
            hmac.TransformBlock(data, 0, data.Length);

            var output = new byte [hmac.MacSize];

            hmac.TransformFinalBlock(output, 0, output.Length);

            return(output);
        }
コード例 #8
0
        int GetMacSize(HandshakeHashType algorithm)
        {
            switch (algorithm)
            {
            case HandshakeHashType.SHA256:
                return(32);

            case HandshakeHashType.SHA384:
                return(48);

            default:
                throw new NotSupportedException();
            }
        }
コード例 #9
0
        int GetAlgorithm(HandshakeHashType algorithm)
        {
            switch (algorithm)
            {
            case HandshakeHashType.SHA256:
                return(native_crypto_test_get_prf_algorithm_sha256());

            case HandshakeHashType.SHA384:
                return(native_crypto_test_get_prf_algorithm_sha384());

            default:
                throw new NotSupportedException();
            }
        }
コード例 #10
0
        HashAlgorithm CreateHash(HandshakeHashType algorithm)
        {
            switch (algorithm)
            {
            case HandshakeHashType.SHA256:
                return(SHA256.Create());

            case HandshakeHashType.SHA384:
                return(SHA384.Create());

            default:
                throw new NotSupportedException();
            }
        }
コード例 #11
0
        public static HMac Create(HandshakeHashType type, SecureBuffer key)
        {
            switch (type)
            {
            case HandshakeHashType.SHA256:
                return(new HMac(SHA256.Create(), 64, key));

            case HandshakeHashType.SHA384:
                return(new HMac(SHA384.Create(), 128, key));

            default:
                throw new NotSupportedException();
            }
        }
コード例 #12
0
        NativeCryptoHashType GetAlgorithm(HandshakeHashType algorithm)
        {
            switch (algorithm)
            {
            case HandshakeHashType.SHA256:
                return(NativeCryptoHashType.SHA256);

            case HandshakeHashType.SHA384:
                return(NativeCryptoHashType.SHA384);

            default:
                throw new NotSupportedException();
            }
        }
コード例 #13
0
        public byte[] TestHMac(HandshakeHashType algorithm, byte[] key, byte[] data)
        {
            var type    = GetAlgorithm(algorithm);
            int macSize = GetMacSize(algorithm);

            var output = new byte [macSize];

            int ret = native_crypto_test_HMac(type, data, data.Length, null, 0, null, 0, null, 0, null, 0, key, key.Length, output, macSize);

            if (ret != 1)
            {
                throw new InvalidOperationException();
            }

            return(output);
        }
コード例 #14
0
        public byte[] TestPRF(HandshakeHashType algorithm, byte[] secret, string seed, byte[] data, int length)
        {
            var digest_mask = GetAlgorithm(algorithm);

            var output = new byte [length];
            var temp   = new byte [length];

            var seedBytes = Encoding.ASCII.GetBytes(seed);
            int ret       = native_crypto_test_PRF(digest_mask, seedBytes, seedBytes.Length, data, data.Length,
                                                   null, 0, null, 0, null, 0, secret, secret.Length, output, temp, length);

            if (ret != 1)
            {
                throw new InvalidOperationException();
            }
            return(output);
        }
コード例 #15
0
        public byte[] TestDigest(HandshakeHashType algorithm, byte[] data)
        {
            var type = GetAlgorithm(algorithm);

            var output = new byte [200];
            var ret    = native_crypto_test_digest(type, data, data.Length, output, output.Length);

            if (ret <= 0)
            {
                throw new InvalidOperationException();
            }

            var buffer = new byte [ret];

            Buffer.BlockCopy(output, 0, buffer, 0, ret);
            return(buffer);
        }
コード例 #16
0
ファイル: HandshakeHash.cs プロジェクト: VimalKumarS/mono-tls
        IHashAlgorithm GetAlgorithm(HandshakeHashType type)
        {
            switch (type)
            {
            case HandshakeHashType.MD5SHA1:
                return(hashes [0]);

            case HandshakeHashType.SHA256:
                return(hashes [3]);

            case HandshakeHashType.SHA384:
                return(hashes [4]);

            default:
                throw new InvalidOperationException();
            }
        }
コード例 #17
0
		public byte[] TestDigest (HandshakeHashType algorithm, byte[] data)
		{
			var hash = CreateHash (algorithm);
			hash.TransformFinalBlock (data, 0, data.Length);
			return hash.Hash;
		}
コード例 #18
0
		public byte[] TestPRF (HandshakeHashType algorithm, byte[] secret, string seed, byte[] data, int length)
		{
			var digest_mask = GetAlgorithm (algorithm);

			var output = new byte [length];
			var temp = new byte [length];

			var seedBytes = Encoding.ASCII.GetBytes (seed);
			int ret = native_crypto_test_PRF (digest_mask, seedBytes, seedBytes.Length, data, data.Length,
				null, 0, null, 0, null, 0, secret, secret.Length, output, temp, length);
			if (ret != 1)
				throw new InvalidOperationException ();
			return output;
		}
コード例 #19
0
		public byte[] TestHMac (HandshakeHashType algorithm, byte[] key, byte[] data)
		{
			var type = GetAlgorithm (algorithm);
			int macSize = GetMacSize (algorithm);

			var output = new byte [macSize];

			int ret = native_crypto_test_HMac (type, data, data.Length, null, 0, null, 0, null, 0, null, 0, key, key.Length, output, macSize);
			if (ret != 1)
				throw new InvalidOperationException ();

			return output;
		}
コード例 #20
0
		public byte[] TestDigest (HandshakeHashType algorithm, byte[] data)
		{
			var type = GetAlgorithm (algorithm);

			var output = new byte [200];
			var ret = native_crypto_test_digest (type, data, data.Length, output, output.Length);
			if (ret <= 0)
				throw new InvalidOperationException ();

			var buffer = new byte [ret];
			Buffer.BlockCopy (output, 0, buffer, 0, ret);
			return buffer;
		}
コード例 #21
0
		public PseudoRandomFunctionTls12 (HandshakeHashType hashType)
		{
			HandshakeHashType = hashType;
		}
コード例 #22
0
ファイル: HMac.cs プロジェクト: VimalKumarS/mono-tls
		public static HMac Create (HandshakeHashType type, SecureBuffer key)
		{
			switch (type) {
			case HandshakeHashType.SHA256:
				return new HMac (SHA256.Create (), 64, key);
			case HandshakeHashType.SHA384:
				return new HMac (SHA384.Create (), 128, key);
			default:
				throw new NotSupportedException ();
			}
		}
コード例 #23
0
ファイル: HandshakeHash.cs プロジェクト: VimalKumarS/mono-tls
 public SecureBuffer GetHash(HandshakeHashType type)
 {
     return(new SecureBuffer(GetAlgorithm(type).GetRunningHash()));
 }
コード例 #24
0
ファイル: HandshakeHash.cs プロジェクト: VimalKumarS/mono-tls
		public SecureBuffer GetHash (HandshakeHashType type)
		{
			return new SecureBuffer (GetAlgorithm (type).GetRunningHash ());
		}
コード例 #25
0
		int GetMacSize (HandshakeHashType algorithm)
		{
			switch (algorithm) {
			case HandshakeHashType.SHA256:
				return 32;
			case HandshakeHashType.SHA384:
				return 48;
			default:
				throw new NotSupportedException();
			}
		}
コード例 #26
0
 public PseudoRandomFunctionTls12(HandshakeHashType hashType)
 {
     HandshakeHashType = hashType;
 }
コード例 #27
0
		public byte[] TestHMac (HandshakeHashType algorithm, byte[] key, byte[] data)
		{
			var hmac = HMac.Create (algorithm, SecureBuffer.CreateCopy (key));

			hmac.Reset ();
			hmac.TransformBlock (data, 0, data.Length);

			var output = new byte [hmac.MacSize];
			hmac.TransformFinalBlock (output, 0, output.Length);

			return output;
		}