private void ExtractFinalChannelKeysForInitiator() { Span <byte> skAndRk = stackalloc byte[64]; _hkdf.ExtractAndExpand(HandshakeContext.ChainingKey, new byte[0].AsSpan(), skAndRk); _messageTransformer.SetKeys(HandshakeContext.ChainingKey, skAndRk.Slice(0, 32), skAndRk.Slice(32)); }
private void KeyRecycle(ICipherFunction cipherFunction, byte[] chainingKey) { if (cipherFunction.GetNonce() < LightningNetworkConfig.NUMBER_OF_NONCE_BEFORE_KEY_RECYCLE) { return; } _logger.LogDebug($"Recycling cipher key"); Span <byte> keys = stackalloc byte[Aead.KEY_SIZE * 2]; _hkdf.ExtractAndExpand(chainingKey, cipherFunction.GetKey(), keys); // set new chaining key keys.Slice(0, Aead.KEY_SIZE) .CopyTo(chainingKey); // set new key cipherFunction.SetKey(keys.Slice(Aead.KEY_SIZE)); _logger.LogDebug($"Cipher key recycled successfully"); }