public void SetKeys(ReadOnlySpan <byte> chainingKey, ReadOnlySpan <byte> senderKey, ReadOnlySpan <byte> receiverKey) { chainingKey.CopyTo(_writerChainingKey.AsSpan()); chainingKey.CopyTo(_readerChainingKey.AsSpan()); _writer.SetKey(senderKey); _reader.SetKey(receiverKey); _keysSet = true; }
private void ExtractNextKeys(ReadOnlySpan <byte> se) { Span <byte> ckAndTempKey = stackalloc byte[64]; _hkdf.ExtractAndExpand(HandshakeContext.ChainingKey, se, ckAndTempKey); ckAndTempKey.Slice(0, 32).CopyTo(HandshakeContext.ChainingKey); _aeadConstruction.SetKey(ckAndTempKey.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"); }