diff --git a/DotnetCliVersion.txt b/DotnetCliVersion.txt index 80d23bcf..08bb76eb 100644 --- a/DotnetCliVersion.txt +++ b/DotnetCliVersion.txt @@ -1 +1 @@ -3.1.402 \ No newline at end of file +5.0.100 \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 02af2662..e8ca7951 100644 --- a/build.ps1 +++ b/build.ps1 @@ -69,6 +69,19 @@ try { } } + # Make sure we have a 3.1 runtime. At the time of writing GitVersion doesn't have a 5.0 build + # Remove when a 5.0 build is available + if((& $env:DOTNET_EXE --list-runtimes | Out-String) -notlike "*Microsoft.NETCore.App 3.1.*") { + + # Download install script + $DotNetInstallFile = "$TempDirectory\dotnet-install.ps1" + New-Item -ItemType Directory -Path $TempDirectory -Force | Out-Null + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + (New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile) + + ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Channel 3.1 -Runtime dotnet -NoPath } + } + Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)" ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile -- $BuildArguments } diff --git a/build.sh b/build.sh index ea31a5cb..c9d2c433 100755 --- a/build.sh +++ b/build.sh @@ -74,6 +74,22 @@ elif [[ ! (-x "$DOTNET_EXE" && (-z ${DOTNET_VERSION+x} || $($DOTNET_EXE --versio fi fi +# Make sure we have a 3.1 runtime. At the time of writing GitVersion doesn't have a 5.0 build +# Remove when a 5.0 build is available +if [[ $($DOTNET_EXE --list-runtimes) != *"Microsoft.NETCore.App 3.1."* ]]; then + + # Download install script + DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh" + mkdir -p "$TEMP_DIRECTORY" + + if [ ! -x "$DOTNET_INSTALL_FILE" ]; then + curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL" + chmod +x "$DOTNET_INSTALL_FILE" + fi + + "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel 3.1 --runtime dotnet --no-path +fi + echo "Microsoft (R) .NET Core SDK version $("$DOTNET_EXE" --version)" "$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" -- ${BUILD_ARGUMENTS[@]} diff --git a/build/Build.cs b/build/Build.cs index bf44a41a..5ab5d035 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Security.Cryptography; @@ -44,7 +43,7 @@ namespace LibHacBuild AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts"; AbsolutePath SignedArtifactsDirectory => ArtifactsDirectory / "signed"; AbsolutePath TempDirectory => RootDirectory / ".tmp"; - AbsolutePath CliCoreDir => TempDirectory / "hactoolnet_netcoreapp3.1"; + AbsolutePath CliCoreDir => TempDirectory / "hactoolnet_net5.0"; AbsolutePath CliNativeDir => TempDirectory / $"hactoolnet_{HostOsName}"; AbsolutePath CliNativeExe => CliNativeDir / $"hactoolnet{NativeProgramExtension}"; AbsolutePath CliCoreZip => ArtifactsDirectory / $"hactoolnet-{VersionString}-netcore.zip"; @@ -221,7 +220,7 @@ namespace LibHacBuild DotNetPublish(s => publishSettings .SetProject(HactoolnetProject) - .SetFramework("netcoreapp3.1") + .SetFramework("net5.0") .SetOutput(CliCoreDir) .SetNoBuild(true) .SetProperties(VersionProps)); @@ -273,7 +272,7 @@ namespace LibHacBuild .EnableNoBuild() .SetConfiguration(Configuration); - if (EnvironmentInfo.IsUnix) settings = settings.SetProperty("TargetFramework", "netcoreapp3.1"); + if (EnvironmentInfo.IsUnix) settings = settings.SetProperty("TargetFramework", "net5.0"); DotNetTest(s => settings); }); @@ -366,7 +365,6 @@ namespace LibHacBuild } } - [SuppressMessage("ReSharper", "PossibleNullReferenceException")] public void BuildNative() { string buildType = Untrimmed ? "native-untrimmed" : "native"; @@ -614,7 +612,7 @@ namespace LibHacBuild SignAssemblies(password, toSign.Select(x => x.ToString()).ToArray()); // Avoid having multiple signed versions of the same file - File.Copy(nupkgDir / "lib" / "netcoreapp3.0" / "LibHac.dll", coreFxDir / "LibHac.dll", true); + File.Copy(nupkgDir / "lib" / "net5.0" / "LibHac.dll", coreFxDir / "LibHac.dll", true); ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(nupkgFile), nupkgDir, pkgFileList); ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(CliCoreZip), coreFxDir); diff --git a/build/CodeGen/_buildCodeGen.csproj b/build/CodeGen/_buildCodeGen.csproj index f4811b2d..aeacb725 100644 --- a/build/CodeGen/_buildCodeGen.csproj +++ b/build/CodeGen/_buildCodeGen.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net5.0 false LibHacBuild.CodeGen False diff --git a/build/_build.csproj b/build/_build.csproj index aa32db29..5baaa179 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net5.0 false LibHacBuild False diff --git a/src/LibHac/Crypto/Aes.cs b/src/LibHac/Crypto/Aes.cs index 51a8bdba..c2db5418 100644 --- a/src/LibHac/Crypto/Aes.cs +++ b/src/LibHac/Crypto/Aes.cs @@ -1,12 +1,10 @@ // ReSharper disable AssignmentIsFullyDiscarded using System; using System.Runtime.CompilerServices; -using LibHac.Diag; -#if HAS_INTRINSICS using LibHac.Crypto.Detail; +using LibHac.Diag; using AesNi = System.Runtime.Intrinsics.X86.Aes; -#endif namespace LibHac.Crypto { @@ -17,108 +15,95 @@ namespace LibHac.Crypto public static bool IsAesNiSupported() { -#if HAS_INTRINSICS return AesNi.IsSupported; -#else - return false; -#endif } public static ICipher CreateEcbDecryptor(ReadOnlySpan key, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { return new AesEcbDecryptorNi(key); } -#endif + return new AesEcbDecryptor(key); } public static ICipher CreateEcbEncryptor(ReadOnlySpan key, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { return new AesEcbEncryptorNi(key); } -#endif + return new AesEcbEncryptor(key); } public static ICipher CreateCbcDecryptor(ReadOnlySpan key, ReadOnlySpan iv, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { return new AesCbcDecryptorNi(key, iv); } -#endif + return new AesCbcDecryptor(key, iv); } public static ICipher CreateCbcEncryptor(ReadOnlySpan key, ReadOnlySpan iv, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { return new AesCbcEncryptorNi(key, iv); } -#endif + return new AesCbcEncryptor(key, iv); } public static ICipherWithIv CreateCtrDecryptor(ReadOnlySpan key, ReadOnlySpan iv, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { return new AesCtrCipherNi(key, iv); } -#endif + // Encryption and decryption in counter mode is the same operation return CreateCtrEncryptor(key, iv, preferDotNetCrypto); } public static ICipherWithIv CreateCtrEncryptor(ReadOnlySpan key, ReadOnlySpan iv, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { return new AesCtrCipherNi(key, iv); } -#endif + return new AesCtrCipher(key, iv); } public static ICipherWithIv CreateXtsDecryptor(ReadOnlySpan key1, ReadOnlySpan key2, ReadOnlySpan iv, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { return new AesXtsDecryptorNi(key1, key2, iv); } -#endif + return new AesXtsDecryptor(key1, key2, iv); } public static ICipherWithIv CreateXtsEncryptor(ReadOnlySpan key1, ReadOnlySpan key2, ReadOnlySpan iv, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { return new AesXtsEncryptorNi(key1, key2, iv); } -#endif + return new AesXtsEncryptor(key1, key2, iv); } public static void EncryptEcb128(ReadOnlySpan input, Span output, ReadOnlySpan key, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { AesEcbModeNi cipherNi; @@ -128,7 +113,7 @@ namespace LibHac.Crypto cipherNi.Encrypt(input, output); return; } -#endif + ICipher cipher = CreateEcbEncryptor(key, preferDotNetCrypto); cipher.Transform(input, output); @@ -138,7 +123,6 @@ namespace LibHac.Crypto public static void DecryptEcb128(ReadOnlySpan input, Span output, ReadOnlySpan key, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { AesEcbModeNi cipherNi; @@ -148,7 +132,7 @@ namespace LibHac.Crypto cipherNi.Decrypt(input, output); return; } -#endif + ICipher cipher = CreateEcbDecryptor(key, preferDotNetCrypto); cipher.Transform(input, output); @@ -157,7 +141,6 @@ namespace LibHac.Crypto public static void EncryptCbc128(ReadOnlySpan input, Span output, ReadOnlySpan key, ReadOnlySpan iv, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { AesCbcModeNi cipherNi; @@ -167,7 +150,7 @@ namespace LibHac.Crypto cipherNi.Encrypt(input, output); return; } -#endif + ICipher cipher = CreateCbcEncryptor(key, iv, preferDotNetCrypto); cipher.Transform(input, output); @@ -176,7 +159,6 @@ namespace LibHac.Crypto public static void DecryptCbc128(ReadOnlySpan input, Span output, ReadOnlySpan key, ReadOnlySpan iv, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { AesCbcModeNi cipherNi; @@ -186,7 +168,7 @@ namespace LibHac.Crypto cipherNi.Decrypt(input, output); return; } -#endif + ICipher cipher = CreateCbcDecryptor(key, iv, preferDotNetCrypto); cipher.Transform(input, output); @@ -195,7 +177,6 @@ namespace LibHac.Crypto public static void EncryptCtr128(ReadOnlySpan input, Span output, ReadOnlySpan key, ReadOnlySpan iv, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { AesCtrModeNi cipherNi; @@ -205,7 +186,7 @@ namespace LibHac.Crypto cipherNi.Transform(input, output); return; } -#endif + ICipher cipher = CreateCtrEncryptor(key, iv, preferDotNetCrypto); cipher.Transform(input, output); @@ -214,7 +195,6 @@ namespace LibHac.Crypto public static void DecryptCtr128(ReadOnlySpan input, Span output, ReadOnlySpan key, ReadOnlySpan iv, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { AesCtrModeNi cipherNi; @@ -224,7 +204,7 @@ namespace LibHac.Crypto cipherNi.Transform(input, output); return; } -#endif + ICipher cipher = CreateCtrDecryptor(key, iv, preferDotNetCrypto); cipher.Transform(input, output); @@ -233,7 +213,6 @@ namespace LibHac.Crypto public static void EncryptXts128(ReadOnlySpan input, Span output, ReadOnlySpan key1, ReadOnlySpan key2, ReadOnlySpan iv, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { AesXtsModeNi cipherNi; @@ -243,7 +222,7 @@ namespace LibHac.Crypto cipherNi.Encrypt(input, output); return; } -#endif + ICipher cipher = CreateXtsEncryptor(key1, key2, iv, preferDotNetCrypto); cipher.Transform(input, output); @@ -252,7 +231,6 @@ namespace LibHac.Crypto public static void DecryptXts128(ReadOnlySpan input, Span output, ReadOnlySpan key1, ReadOnlySpan key2, ReadOnlySpan iv, bool preferDotNetCrypto = false) { -#if HAS_INTRINSICS if (IsAesNiSupported() && !preferDotNetCrypto) { AesXtsModeNi cipherNi; @@ -262,7 +240,7 @@ namespace LibHac.Crypto cipherNi.Decrypt(input, output); return; } -#endif + ICipher cipher = CreateXtsDecryptor(key1, key2, iv, preferDotNetCrypto); cipher.Transform(input, output); diff --git a/src/LibHac/Crypto/AesCbcCipherNi.cs b/src/LibHac/Crypto/AesCbcCipherNi.cs index 2b2b3ab4..0f393600 100644 --- a/src/LibHac/Crypto/AesCbcCipherNi.cs +++ b/src/LibHac/Crypto/AesCbcCipherNi.cs @@ -1,5 +1,4 @@ -#if HAS_INTRINSICS -using System; +using System; using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; using LibHac.Common; @@ -12,7 +11,7 @@ namespace LibHac.Crypto private AesCbcModeNi _baseCipher; public ref Buffer16 Iv => ref Unsafe.As, Buffer16>(ref _baseCipher.Iv); - + public AesCbcEncryptorNi(ReadOnlySpan key, ReadOnlySpan iv) { _baseCipher = new AesCbcModeNi(); @@ -43,4 +42,3 @@ namespace LibHac.Crypto } } } -#endif \ No newline at end of file diff --git a/src/LibHac/Crypto/AesCtrCipherNi.cs b/src/LibHac/Crypto/AesCtrCipherNi.cs index 13e71486..3562b9cd 100644 --- a/src/LibHac/Crypto/AesCtrCipherNi.cs +++ b/src/LibHac/Crypto/AesCtrCipherNi.cs @@ -1,5 +1,4 @@ -#if HAS_INTRINSICS -using System; +using System; using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; using LibHac.Common; @@ -25,4 +24,3 @@ namespace LibHac.Crypto } } } -#endif diff --git a/src/LibHac/Crypto/AesEcbCipherNi.cs b/src/LibHac/Crypto/AesEcbCipherNi.cs index 234331dc..429edc61 100644 --- a/src/LibHac/Crypto/AesEcbCipherNi.cs +++ b/src/LibHac/Crypto/AesEcbCipherNi.cs @@ -1,5 +1,4 @@ -#if HAS_INTRINSICS -using System; +using System; using LibHac.Crypto.Detail; namespace LibHac.Crypto @@ -36,4 +35,3 @@ namespace LibHac.Crypto } } } -#endif diff --git a/src/LibHac/Crypto/AesXtsCipherNi.cs b/src/LibHac/Crypto/AesXtsCipherNi.cs index d310bfe0..c50dec22 100644 --- a/src/LibHac/Crypto/AesXtsCipherNi.cs +++ b/src/LibHac/Crypto/AesXtsCipherNi.cs @@ -1,5 +1,4 @@ -#if HAS_INTRINSICS -using System; +using System; using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; using LibHac.Common; @@ -43,4 +42,3 @@ namespace LibHac.Crypto } } } -#endif diff --git a/src/LibHac/Crypto/Detail/AesCbcModeNi.cs b/src/LibHac/Crypto/Detail/AesCbcModeNi.cs index 4ee79f7f..bc3e79b6 100644 --- a/src/LibHac/Crypto/Detail/AesCbcModeNi.cs +++ b/src/LibHac/Crypto/Detail/AesCbcModeNi.cs @@ -1,5 +1,4 @@ -#if HAS_INTRINSICS -using System; +using System; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -10,9 +9,7 @@ namespace LibHac.Crypto.Detail { public struct AesCbcModeNi { -#pragma warning disable 649 private AesCoreNi _aesCore; -#pragma warning restore 649 public Vector128 Iv; @@ -110,4 +107,3 @@ namespace LibHac.Crypto.Detail } } } -#endif diff --git a/src/LibHac/Crypto/Detail/AesCoreNi.cs b/src/LibHac/Crypto/Detail/AesCoreNi.cs index 77012b1e..67cb7c13 100644 --- a/src/LibHac/Crypto/Detail/AesCoreNi.cs +++ b/src/LibHac/Crypto/Detail/AesCoreNi.cs @@ -1,5 +1,4 @@ -#if HAS_INTRINSICS -using System; +using System; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -578,4 +577,3 @@ namespace LibHac.Crypto.Detail } } } -#endif diff --git a/src/LibHac/Crypto/Detail/AesCtrModeNi.cs b/src/LibHac/Crypto/Detail/AesCtrModeNi.cs index 55413043..84b901aa 100644 --- a/src/LibHac/Crypto/Detail/AesCtrModeNi.cs +++ b/src/LibHac/Crypto/Detail/AesCtrModeNi.cs @@ -1,5 +1,4 @@ -#if HAS_INTRINSICS -using System; +using System; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -10,9 +9,7 @@ namespace LibHac.Crypto.Detail { public struct AesCtrModeNi { -#pragma warning disable 649 private AesCoreNi _aesCore; -#pragma warning restore 649 public Vector128 Iv; @@ -126,4 +123,3 @@ namespace LibHac.Crypto.Detail } } } -#endif diff --git a/src/LibHac/Crypto/Detail/AesEcbModeNi.cs b/src/LibHac/Crypto/Detail/AesEcbModeNi.cs index c1073a09..f05cd22c 100644 --- a/src/LibHac/Crypto/Detail/AesEcbModeNi.cs +++ b/src/LibHac/Crypto/Detail/AesEcbModeNi.cs @@ -1,13 +1,10 @@ -#if HAS_INTRINSICS -using System; +using System; namespace LibHac.Crypto.Detail { public struct AesEcbModeNi { -#pragma warning disable 649 private AesCoreNi _aesCore; -#pragma warning restore 649 public void Initialize(ReadOnlySpan key, bool isDecrypting) { @@ -25,4 +22,3 @@ namespace LibHac.Crypto.Detail } } } -#endif diff --git a/src/LibHac/Crypto/Detail/AesXtsModeNi.cs b/src/LibHac/Crypto/Detail/AesXtsModeNi.cs index 69c76b98..3578a7a7 100644 --- a/src/LibHac/Crypto/Detail/AesXtsModeNi.cs +++ b/src/LibHac/Crypto/Detail/AesXtsModeNi.cs @@ -1,5 +1,4 @@ -#if HAS_INTRINSICS -using System; +using System; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -11,10 +10,8 @@ namespace LibHac.Crypto.Detail { public struct AesXtsModeNi { -#pragma warning disable 649 private AesCoreNi _dataAesCore; private AesCoreNi _tweakAesCore; -#pragma warning restore 649 public Vector128 Iv; @@ -256,4 +253,3 @@ namespace LibHac.Crypto.Detail } } } -#endif diff --git a/src/LibHac/LibHac.csproj b/src/LibHac/LibHac.csproj index cba4a9bf..c17ad8a7 100644 --- a/src/LibHac/LibHac.csproj +++ b/src/LibHac/LibHac.csproj @@ -3,8 +3,7 @@ Library 0.12.0 - netcoreapp3.0;netstandard2.1 - 8.0 + net5.0 true @@ -27,17 +26,9 @@ $(MSBuildProjectDirectory)=C:/LibHac/ true - $(NoWarn);1591;NU5105 + $(NoWarn);1591 - - $(DefineConstants);HAS_INTRINSICS - - - - - - @@ -45,7 +36,6 @@ - diff --git a/src/hactoolnet/Program.cs b/src/hactoolnet/Program.cs index 935c6292..3c778b22 100644 --- a/src/hactoolnet/Program.cs +++ b/src/hactoolnet/Program.cs @@ -16,11 +16,8 @@ namespace hactoolnet { if (Run(args)) { - // Console.ReadKey(); return 0; } - - } catch (MissingKeyException ex) { diff --git a/src/hactoolnet/hactoolnet.csproj b/src/hactoolnet/hactoolnet.csproj index 6c904041..5058d248 100644 --- a/src/hactoolnet/hactoolnet.csproj +++ b/src/hactoolnet/hactoolnet.csproj @@ -2,8 +2,7 @@ Exe - netcoreapp3.1 - 8.0 + net5.0 diff --git a/tests/LibHac.Tests/LibHac.Tests.csproj b/tests/LibHac.Tests/LibHac.Tests.csproj index b298de9c..ce4e8715 100644 --- a/tests/LibHac.Tests/LibHac.Tests.csproj +++ b/tests/LibHac.Tests/LibHac.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net5.0 false