private void Clear() { state.Dispose(); e?.Dispose(); s?.Dispose(); foreach (var psk in psks) { Utilities.ZeroMemory(psk); } }
public void Fallback(Protocol protocol, ProtocolConfig config) { ThrowIfDisposed(); Exceptions.ThrowIfNull(protocol, nameof(protocol)); Exceptions.ThrowIfNull(config, nameof(config)); if (protocol.HandshakePattern != HandshakePattern.XX || protocol.Modifiers != PatternModifiers.Fallback) { throw new ArgumentException("The only fallback pattern currently supported is XXfallback."); } if (config.LocalStatic == null) { throw new ArgumentException("Local static private key is required for the XXfallback pattern."); } if (initiator == Role.Bob) { throw new InvalidOperationException("Fallback cannot be applied to a Bob-initiated pattern."); } if (messagePatterns.Count + 1 != this.protocol.HandshakePattern.Patterns.Count()) { throw new InvalidOperationException("Fallback can only be applied after the first handshake message."); } this.protocol = null; initiator = Role.Bob; turnToWrite = role == Role.Bob; s = dh.GenerateKeyPair(config.LocalStatic); rs = null; isPsk = false; isOneWay = false; while (psks.Count > 0) { var psk = psks.Dequeue(); Utilities.ZeroMemory(psk); } state.Dispose(); state = new SymmetricState <CipherType, DhType, HashType>(protocol.Name); state.MixHash(config.Prologue); if (role == Role.Alice) { Debug.Assert(e != null && re == null); state.MixHash(e.PublicKey); } else { Debug.Assert(e == null && re != null); state.MixHash(re); } messagePatterns.Clear(); foreach (var pattern in protocol.HandshakePattern.Patterns.Skip(1)) { messagePatterns.Enqueue(pattern); } }