diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 3aa6141..dd6a3b4 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "gitversion.tool": { - "version": "6.4.0", + "version": "6.5.0", "commands": [ "dotnet-gitversion" ], diff --git a/.editorconfig b/.editorconfig index 08ab8fe..1085368 100644 --- a/.editorconfig +++ b/.editorconfig @@ -79,6 +79,7 @@ csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion csharp_style_inlined_variable_declaration = true:suggestion csharp_style_namespace_declarations = file_scoped:suggestion csharp_style_prefer_extended_property_pattern = true:suggestion +csharp_style_prefer_implicitly_typed_lambda_expression = true:suggestion csharp_style_prefer_index_operator = true:suggestion csharp_style_prefer_local_over_anonymous_function = true:suggestion csharp_style_prefer_method_group_conversion = true:suggestion @@ -89,6 +90,7 @@ csharp_style_prefer_primary_constructors = true:suggestion csharp_style_prefer_range_operator = true:suggestion csharp_style_prefer_readonly_struct = true:suggestion csharp_style_prefer_readonly_struct_member = true:suggestion +csharp_style_prefer_simple_property_accessors = true:suggestion csharp_style_prefer_switch_expression = true:suggestion csharp_style_prefer_top_level_statements = true:suggestion csharp_style_prefer_tuple_swap = true:suggestion @@ -196,6 +198,9 @@ indent_size = 2 [*.{json,yaml,yml}] indent_size = 2 +[*.{diff,patch}] +indent_size = unset + [*.sh] charset = utf-8 end_of_line = lf diff --git a/.gitattributes b/.gitattributes index ddd7074..4ea09cf 100644 --- a/.gitattributes +++ b/.gitattributes @@ -26,6 +26,7 @@ *.targets text libc/*.c text eol=lf +*.diff text eol=lf *.cfg text *.razor text diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8992673..fd4da7f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -151,7 +151,7 @@ jobs: - name: Test run: | dotnet test --configuration Release --no-build \ - -p:TestingPlatformCommandLineArguments="--report-trx --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml" + --report-trx --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml - name: Package run: | diff --git a/.github/workflows/runtime-browser-wasm.yml b/.github/workflows/runtime-browser-wasm.yml index aceccc9..6075457 100644 --- a/.github/workflows/runtime-browser-wasm.yml +++ b/.github/workflows/runtime-browser-wasm.yml @@ -30,6 +30,11 @@ jobs: with: submodules: recursive + - name: Patch for WASM + run: | + cp libc/xmss.c xmss-library/src/ + patch --directory=xmss-library --strip=1 < libc/wasm.diff + - name: Prepare packages run: | sudo apt-get update @@ -42,6 +47,7 @@ jobs: -B build -DXMSS_C99_COMPATIBLE=OFF -DCMAKE_EXE_LINKER_FLAGS="-s NODERAWFS=1" + -DCMAKE_STATIC_LIBRARY_PREFIX_C="" - name: Configure (pthread) run: > @@ -51,6 +57,7 @@ jobs: -DXMSS_C99_COMPATIBLE=OFF -DCMAKE_C_FLAGS="-pthread" -DCMAKE_EXE_LINKER_FLAGS="-s NODERAWFS=1" + -DCMAKE_STATIC_LIBRARY_PREFIX_C="" - name: Build run: cmake --build build @@ -73,8 +80,8 @@ jobs: - name: Copy artifacts run: | mkdir -p "Xmss/runtimes/${{ env.RUNTIME }}/nativeassets" - cp build/src/libxmss.a "Xmss/runtimes/${{ env.RUNTIME }}/nativeassets/xmss.a" - cp build-pthread/src/libxmss.a "Xmss/runtimes/${{ env.RUNTIME }}/nativeassets/xmss-pthread.a" + cp build/src/xmss.a "Xmss/runtimes/${{ env.RUNTIME }}/nativeassets/xmss.a" + cp build-pthread/src/xmss.a "Xmss/runtimes/${{ env.RUNTIME }}/nativeassets/xmss-pthread.a" - name: Save runtime cache id: save-runtime-cache diff --git a/Directory.Build.props b/Directory.Build.props index c08b1ba..fcb03d8 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -11,10 +11,10 @@ SPDX-License-Identifier: MIT false - net9.0 + net10.0 - 13.0 + 14.0 enable enable diff --git a/Directory.Packages.props b/Directory.Packages.props index 3882469..6ceab0f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -10,9 +10,9 @@ SPDX-License-Identifier: MIT - - - - + + + + \ No newline at end of file diff --git a/Examples/WebAssembly/App.razor b/Examples/WebAssembly/App.razor index 2d7c767..324e781 100644 --- a/Examples/WebAssembly/App.razor +++ b/Examples/WebAssembly/App.razor @@ -8,10 +8,4 @@ - - Not found - -

Sorry, there's nothing at this address.

-
-
diff --git a/Examples/WebAssembly/Properties/PublishProfiles/FolderProfile.pubxml b/Examples/WebAssembly/Properties/PublishProfiles/FolderProfile.pubxml index 3a73ab2..fe61821 100644 --- a/Examples/WebAssembly/Properties/PublishProfiles/FolderProfile.pubxml +++ b/Examples/WebAssembly/Properties/PublishProfiles/FolderProfile.pubxml @@ -19,7 +19,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. FileSystem <_TargetId>Folder - net9.0 + net10.0 browser-wasm true 06165be7-c274-4cd4-ad9a-8bd4f3423b8d diff --git a/Xmss/AssemblySettings.cs b/Xmss/AssemblySettings.cs index a4d4368..e089259 100644 --- a/Xmss/AssemblySettings.cs +++ b/Xmss/AssemblySettings.cs @@ -3,6 +3,8 @@ // SPDX-License-Identifier: MIT using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; [assembly: DisableRuntimeMarshalling] [assembly: InternalsVisibleTo("Internal.UnitTests")] +[assembly: DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)] diff --git a/Xmss/GlobalSuppressions.cs b/Xmss/GlobalSuppressions.cs index ff611b9..bfc8671 100644 --- a/Xmss/GlobalSuppressions.cs +++ b/Xmss/GlobalSuppressions.cs @@ -9,5 +9,4 @@ using System.Diagnostics.CodeAnalysis; -[assembly: SuppressMessage("Security", "CA5393:Do not use unsafe DllImportSearchPath value", Justification = "Required to load native runtime library.")] [assembly: SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Matches native library names.", Scope = "NamespaceAndDescendants", Target = "~N:Dorssel.Security.Cryptography.Internal")] diff --git a/Xmss/Internal/Errors.cs b/Xmss/Internal/Errors.cs index 553884c..8a59939 100644 --- a/Xmss/Internal/Errors.cs +++ b/Xmss/Internal/Errors.cs @@ -11,10 +11,8 @@ namespace Dorssel.Security.Cryptography.Internal; static partial class UnsafeNativeMethods { [LibraryImport("xmss", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(ErrorStringMarshaller))] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static partial string xmss_error_to_name(XmssError error); [LibraryImport("xmss", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(ErrorStringMarshaller))] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static partial string xmss_error_to_description(XmssError error); } diff --git a/Xmss/Internal/OpaqueStructures.cs b/Xmss/Internal/OpaqueStructures.cs index 03cf5e6..de43216 100644 --- a/Xmss/Internal/OpaqueStructures.cs +++ b/Xmss/Internal/OpaqueStructures.cs @@ -19,7 +19,6 @@ static partial class Defines static partial class UnsafeNativeMethods { [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static unsafe partial void xmss_free_signing_context(XmssSigningContext* signing_context); } @@ -74,7 +73,6 @@ internal static int XMSS_KEY_CONTEXT_SIZE(XmssParameterSetOID param_set, XmssInd static partial class UnsafeNativeMethods { [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static unsafe partial void xmss_free_key_context(XmssKeyContext* key_context); } @@ -95,6 +93,5 @@ internal static int XMSS_KEY_GENERATION_CONTEXT_SIZE(int generation_partitions) static partial class UnsafeNativeMethods { [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static unsafe partial void xmss_free_key_generation_context(XmssKeyGenerationContext* key_generation_context); } diff --git a/Xmss/Internal/Signing.cs b/Xmss/Internal/Signing.cs index f4b4d12..d89bf9c 100644 --- a/Xmss/Internal/Signing.cs +++ b/Xmss/Internal/Signing.cs @@ -12,7 +12,6 @@ static partial class UnsafeNativeMethods { // WASM requires function pointers to be passed as nuint; it cannot handle any form of delegate (neither managed nor unmanaged). [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] private static unsafe partial XmssError xmss_context_initialize(ref XmssSigningContext* context, XmssParameterSetOID parameter_set, nuint custom_realloc, nuint custom_free, nuint zeroize); @@ -24,82 +23,65 @@ internal static unsafe XmssError xmss_context_initialize(ref XmssSigningContext* } [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static unsafe partial XmssError xmss_load_private_key(ref XmssKeyContext* key_context, in XmssPrivateKeyStatelessBlob private_key, in XmssPrivateKeyStatefulBlob key_usage, in XmssSigningContext context); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static unsafe partial XmssError xmss_load_public_key(ref XmssInternalCache* cache, ref XmssKeyContext key_context, in XmssPublicKeyInternalBlob public_key); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static unsafe partial XmssError xmss_generate_private_key(ref XmssKeyContext* key_context, ref XmssPrivateKeyStatelessBlob* private_key, ref XmssPrivateKeyStatefulBlob* key_usage, in XmssBuffer secure_random, XmssIndexObfuscationSetting index_obfuscation_setting, in XmssBuffer random, in XmssSigningContext context); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static unsafe partial XmssError xmss_generate_public_key(ref XmssKeyGenerationContext* generation_buffer, ref XmssInternalCache* cache, ref XmssInternalCache* generation_cache, in XmssKeyContext key_context, XmssCacheType cache_type, byte cache_level, uint generation_partitions); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static partial XmssError xmss_calculate_public_key_part(ref XmssKeyGenerationContext generation_buffer, uint partition_index); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] public static unsafe partial XmssError xmss_finish_calculate_public_key(ref XmssPublicKeyInternalBlob* public_key, ref XmssKeyGenerationContext* generation_buffer, ref XmssKeyContext key_context); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static unsafe partial XmssError xmss_request_future_signatures(ref XmssPrivateKeyStatefulBlob* new_key_usage, ref XmssKeyContext key_context, uint signature_count); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static unsafe partial XmssError xmss_sign_message(ref XmssSignatureBlob* signature, ref XmssKeyContext key_context, in XmssBuffer message); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static unsafe partial XmssError xmss_partition_signature_space(ref XmssPrivateKeyStatefulBlob* new_partition, ref XmssPrivateKeyStatefulBlob* updated_current_partition, ref XmssKeyContext key_context, uint new_partition_size); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static unsafe partial XmssError xmss_merge_signature_space(ref XmssPrivateKeyStatefulBlob* new_key_usage, ref XmssKeyContext key_context, in XmssPrivateKeyStatefulBlob partition_extension); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static partial XmssError xmss_get_signature_count(out nuint total_count, out nuint remaining_count, in XmssKeyContext key_context); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static partial XmssError xmss_verify_public_key(in XmssPublicKeyInternalBlob pub_key, in XmssPrivateKeyStatelessBlob private_key, in XmssKeyContext key_context); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static partial XmssError xmss_verify_private_key_stateless(in XmssPrivateKeyStatelessBlob private_key, in XmssSigningContext context); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static partial XmssError xmss_verify_private_key_stateful(in XmssPrivateKeyStatefulBlob key_usage, in XmssPrivateKeyStatelessBlob private_key, in XmssKeyContext key_context, in XmssSigningContext signing_context); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static partial XmssError xmss_get_caching_in_public_key(out XmssCacheType cache_type, out uint cache_level, in XmssPublicKeyInternalBlob pub_key); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static partial XmssError xmss_export_public_key(out XmssPublicKey exported_pub_key, in XmssKeyContext key_context); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static partial XmssError xmss_verify_exported_public_key(in XmssPublicKey exported_pub_key, in XmssKeyContext key_context); } diff --git a/Xmss/Internal/Verification.cs b/Xmss/Internal/Verification.cs index 58a8e60..b585f2e 100644 --- a/Xmss/Internal/Verification.cs +++ b/Xmss/Internal/Verification.cs @@ -11,16 +11,13 @@ namespace Dorssel.Security.Cryptography.Internal; static partial class UnsafeNativeMethods { [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static partial XmssError xmss_verification_init(out XmssVerificationContext context, in XmssPublicKey public_key, in XmssSignature signature, nuint signature_length); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static unsafe partial XmssError xmss_verification_update(ref XmssVerificationContext context, byte* part, nuint part_length, out byte* part_verify); [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static partial XmssError xmss_verification_check(ref XmssVerificationContext context, in XmssPublicKey public_key); } diff --git a/Xmss/Internal/Version.cs b/Xmss/Internal/Version.cs index c290f6c..af31cfc 100644 --- a/Xmss/Internal/Version.cs +++ b/Xmss/Internal/Version.cs @@ -40,7 +40,6 @@ internal static byte XMSS_LIBRARY_GET_VERSION_PATCH(uint version) static partial class SafeNativeMethods { [LibraryImport("xmss")] - [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static partial uint xmss_library_get_version(); } diff --git a/global.json b/global.json index 7e779c0..7c0fa0f 100644 --- a/global.json +++ b/global.json @@ -1,11 +1,14 @@ { "sdk": { - "version": "9.0.306", + "version": "10.0.100", "allowPrerelease": false, "rollForward": "latestFeature" }, "msbuild-sdks": { "Microsoft.Build.NoTargets": "3.7.134", - "MSTest.Sdk": "4.0.1" + "MSTest.Sdk": "4.0.2" + }, + "test": { + "runner": "Microsoft.Testing.Platform" } } \ No newline at end of file diff --git a/libc/wasm.diff b/libc/wasm.diff new file mode 100644 index 0000000..5b7f0e4 --- /dev/null +++ b/libc/wasm.diff @@ -0,0 +1,15 @@ +SPDX-FileCopyrightText: 2025 Frans van Dorsselaer + +SPDX-License-Identifier: MIT + +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -67,7 +67,7 @@ endif() + + # Our actual library target amalgamates all sources into one; see comment in libxmss.c for rationale. + add_library(xmss +- libxmss.c ++ xmss.c + ${XMSS_HASH_OVERRIDE_SOURCES} + ${ADDITIONAL_SOURCES} + ) diff --git a/libc/xmss.c b/libc/xmss.c new file mode 100644 index 0000000..51c3178 --- /dev/null +++ b/libc/xmss.c @@ -0,0 +1,8 @@ +// SPDX-FileCopyrightText: 2025 Frans van Dorsselaer +// +// SPDX-License-Identifier: MIT + +// WASM (.NET 10) requires that the object file has the same name as the DllImport/LibraryImport name. +// Previously, xmss/libxmss did not matter, but now it does. + +#include "libxmss.c" // NOLINT