private void CompleteInitiatorHandshake(ReadOnlySpan <byte> re, IBufferWriter <byte> output) { //act three initiator Span <byte> outputText = output.GetSpan(66); Span <byte> cipher = outputText.Slice(1, 49); _aeadConstruction.EncryptWithAd(HandshakeContext.Hash, _keyGenerator.GetPublicKey(HandshakeContext.PrivateKey).ToArray(), cipher); _hasher.Hash(HandshakeContext.Hash, cipher, HandshakeContext.Hash); var se = _curveActions.Multiply(HandshakeContext.PrivateKey, re); ExtractNextKeys(se); _aeadConstruction.EncryptWithAd(HandshakeContext.Hash, new byte[0], outputText.Slice(50, 16)); ExtractFinalChannelKeysForInitiator(); output.Advance(66); }
public int WriteMessage(ReadOnlySequence <byte> message, IBufferWriter <byte> output) { if (message.Length + Aead.TAG_SIZE > LightningNetworkConfig.MAX_MESSAGE_LENGTH) { throw new ArgumentException($"Noise message must be less than or equal to {LightningNetworkConfig.MAX_MESSAGE_LENGTH} bytes in length."); } _logger.LogDebug($"Write message {message.Length} to encrypted"); int numOfBytesWritten = _writer.EncryptWithAd(null, message.ToArray(), // TODO David here we call to array should be replaced output.GetSpan((int)message.Length + Aead.TAG_SIZE)); output.Advance(numOfBytesWritten); KeyRecycle(_writer, _writerChainingKey); return(numOfBytesWritten); }