From: js6pak Date: Wed, 10 Nov 2021 13:57:11 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/master' X-Git-Tag: 1.0.0~1 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=74070b8c0798f9a8889d65d3bf5b54f2ef55f4c3;p=rhonda%2Fimpostor.hazel.git Merge remote-tracking branch 'upstream/master' # Conflicts: # Hazel.UnitTests/ThreadLimitedUdpConnectionTests.cs # Hazel.UnitTests/UnityUdpConnectionTests.cs # Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs # Hazel/Hazel.csproj # README.md --- 74070b8c0798f9a8889d65d3bf5b54f2ef55f4c3 diff --cc Hazel.UnitTests/ThreadLimitedUdpConnectionTests.cs index 0000000,4be1628..e69de29 mode 000000,100644..100644 --- a/Hazel.UnitTests/ThreadLimitedUdpConnectionTests.cs +++ b/Hazel.UnitTests/ThreadLimitedUdpConnectionTests.cs diff --cc Hazel.UnitTests/UnityUdpConnectionTests.cs index 0000000,5151ae2..e69de29 mode 000000,100644..100644 --- a/Hazel.UnitTests/UnityUdpConnectionTests.cs +++ b/Hazel.UnitTests/UnityUdpConnectionTests.cs diff --cc Hazel/Crypto/CryptoProvider.cs index 0000000,2c56c70..8a38d77 mode 000000,100644..100644 --- a/Hazel/Crypto/CryptoProvider.cs +++ b/Hazel/Crypto/CryptoProvider.cs @@@ -1,0 -1,36 +1,30 @@@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Hazel.Crypto ++namespace Impostor.Hazel.Crypto + { + public static class CryptoProvider + { + public delegate IAes CreateAesOverrideDelegate(ByteSpan key); + + /// + /// Override the default AES creation function + /// + public static CreateAesOverrideDelegate OverrideCreateAes = null; + + /// + /// Create a new AES cipher + /// + /// Encrtyption key + public static IAes CreateAes(ByteSpan key) + { + if (OverrideCreateAes != null) + { + IAes result = OverrideCreateAes(key); + if (null != result) + { + return result; + } + } + + return new DefaultAes(key); + } + } + } diff --cc Hazel/Crypto/DefaultAes.cs index 0000000,da72fb8..6db66e6 mode 000000,100644..100644 --- a/Hazel/Crypto/DefaultAes.cs +++ b/Hazel/Crypto/DefaultAes.cs @@@ -1,0 -1,49 +1,49 @@@ + using System; + using System.Security.Cryptography; + -namespace Hazel.Crypto ++namespace Impostor.Hazel.Crypto + { + /// + /// AES provider using the default System.Security.Cryptography implementation + /// + public class DefaultAes : IAes + { + private readonly ICryptoTransform encryptor_; + + /// + /// Create a new default instance of the AES block cipher + /// + /// Encryption key + public DefaultAes(ByteSpan key) + { + // Create the AES block cipher + using (Aes aes = Aes.Create()) + { + aes.KeySize = key.Length * 8; + aes.BlockSize = aes.KeySize; + aes.Mode = CipherMode.ECB; + aes.Padding = PaddingMode.Zeros; + aes.Key = key.ToArray(); + + this.encryptor_ = aes.CreateEncryptor(); + } + } + + /// + public void Dispose() + { + this.encryptor_.Dispose(); + } + + /// + public int EncryptBlock(ByteSpan inputSpan, ByteSpan outputSpan) + { + if (inputSpan.Length != outputSpan.Length) + { + throw new ArgumentException($"ouputSpan length ({outputSpan.Length}) does not match inputSpan length ({inputSpan.Length})", nameof(outputSpan)); + } + + return this.encryptor_.TransformBlock(inputSpan.GetUnderlyingArray(), inputSpan.Offset, inputSpan.Length, outputSpan.GetUnderlyingArray(), outputSpan.Offset); + } + } + } diff --cc Hazel/Crypto/IAes.cs index 0000000,6c494cd..e437d03 mode 000000,100644..100644 --- a/Hazel/Crypto/IAes.cs +++ b/Hazel/Crypto/IAes.cs @@@ -1,0 -1,27 +1,23 @@@ + using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + -namespace Hazel.Crypto ++namespace Impostor.Hazel.Crypto + { + /// + /// AES encryption interface + /// + public interface IAes : IDisposable + { + /// + /// Encrypts the specified region of the input byte array and copies + /// the resulting transform to the specified region of the output + /// array. + /// + /// The input for which to encrypt + /// + /// The otput to which to write the encrypted data. This span can + /// overlap with `inputSpan`. + /// + /// The number of bytes written + int EncryptBlock(ByteSpan inputSpan, ByteSpan outputSpan); + } + } diff --cc Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs index 0000000,3053363..e69de29 mode 000000,100644..100644 --- a/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs +++ b/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs diff --cc Hazel/Hazel.csproj index b261534,6b0b91d..34f7595 --- a/Hazel/Hazel.csproj +++ b/Hazel/Hazel.csproj @@@ -1,25 -1,135 +1,26 @@@ - - - + + - Debug - AnyCPU - {02CFBD30-D77D-400F-94B2-700F60EFDD7F} - Library - Properties - Hazel - Hazel - v4.5 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - true - false - 7.3 - - - portable - true - bin\Release\ - TRACE - prompt - 4 - - true - false - 7.3 - true - - - true - - - - - - - true - bin\DebugClient\ - DEBUG;TRACE - true - full - AnyCPU - prompt - MinimumRecommendedRules.ruleset - 7.3 + net5.0 + HAZEL_BAG + Impostor.Hazel + + + + <_Parameter1>Hazel.UnitTests + + + - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code - - - - - - - - + - - - + + ++