public Task Initialize(TestContext ctx, CancellationToken cancellationToken) { return(Task.Run(() => { if (Parameters == null) { return; } cipher = CipherSuiteFactory.CreateCipherSuite(Parameters.Protocol, Parameters.Code); if (Parameters.IsGCM) { crypto = new MyGaloisCounterCipher(Parameters, cipher); crypto.ServerWriteKey = SecureBuffer.CreateCopy(Parameters.Key); crypto.ClientWriteKey = SecureBuffer.CreateCopy(Parameters.Key); crypto.ServerWriteIV = SecureBuffer.CreateCopy(Parameters.ImplicitNonce); crypto.ClientWriteIV = SecureBuffer.CreateCopy(Parameters.ImplicitNonce); crypto.InitializeCipher(); } else { crypto = new MyCbcBlockCipher(Parameters, cipher); crypto.ServerWriteKey = SecureBuffer.CreateCopy(Parameters.Key); crypto.ClientWriteKey = SecureBuffer.CreateCopy(Parameters.Key); crypto.ServerWriteMac = SecureBuffer.CreateCopy(Parameters.MAC); crypto.ClientWriteMac = SecureBuffer.CreateCopy(Parameters.MAC); crypto.InitializeCipher(); } })); }
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()); }
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); }
public void InitializeGCM(CipherSuiteCode code, byte[] key, byte[] implNonce, byte[] explNonce) { Cipher = CipherSuiteFactory.CreateCipherSuite(Protocol, code); #if DEBUG_FULL Cipher.EnableDebugging = EnableDebugging; #endif Crypto = Add(new MyGaloisCounterCipher(IsServer, Protocol, Cipher, explNonce)); Crypto.ServerWriteKey = SecureBuffer.CreateCopy(key); Crypto.ClientWriteKey = SecureBuffer.CreateCopy(key); Crypto.ServerWriteIV = SecureBuffer.CreateCopy(implNonce); Crypto.ClientWriteIV = SecureBuffer.CreateCopy(implNonce); Crypto.InitializeCipher(); }
public void InitializeCBC(CipherSuiteCode code, byte[] key, byte[] mac, byte[] iv) { Cipher = CipherSuiteFactory.CreateCipherSuite(Protocol, code); #if DEBUG_FULL Cipher.EnableDebugging = EnableDebugging; #endif Crypto = Add(new MyCbcBlockCipher(this, iv)); Crypto.ServerWriteKey = SecureBuffer.CreateCopy(key); Crypto.ClientWriteKey = SecureBuffer.CreateCopy(key); Crypto.ServerWriteMac = SecureBuffer.CreateCopy(mac); Crypto.ClientWriteMac = SecureBuffer.CreateCopy(mac); Crypto.InitializeCipher(); }