Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"gitversion.tool": {
"version": "6.4.0",
"version": "6.5.0",
"commands": [
"dotnet-gitversion"
],
Expand Down
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*.targets text

libc/*.c text eol=lf
*.diff text eol=lf
*.cfg text

*.razor text
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/runtime-browser-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: >
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ SPDX-License-Identifier: MIT
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' != 'true'">false</ContinuousIntegrationBuild>

<!-- Use the latest .NET SDK -->
<MainTargetFramework>net9.0</MainTargetFramework>
<MainTargetFramework>net10.0</MainTargetFramework>

<!-- Use the latest C# Language standard -->
<LangVersion>13.0</LangVersion>
<LangVersion>14.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>

Expand Down
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ SPDX-License-Identifier: MIT
<PackageVersion Include="Dorssel.GitVersion.MsBuild" Version="1.1.1" />
<!-- example WebApp -->
<PackageVersion Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.10" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.10" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components" Version="4.13.0" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="4.13.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.0" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components" Version="4.13.1" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="4.13.1" />
</ItemGroup>
</Project>
6 changes: 0 additions & 6 deletions Examples/WebAssembly/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,4 @@
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<RunAOTCompilation>true</RunAOTCompilation>
<ProjectGuid>06165be7-c274-4cd4-ad9a-8bd4f3423b8d</ProjectGuid>
Expand Down
2 changes: 2 additions & 0 deletions Xmss/AssemblySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
1 change: 0 additions & 1 deletion Xmss/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
2 changes: 0 additions & 2 deletions Xmss/Internal/Errors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 0 additions & 3 deletions Xmss/Internal/OpaqueStructures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
18 changes: 0 additions & 18 deletions Xmss/Internal/Signing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
3 changes: 0 additions & 3 deletions Xmss/Internal/Verification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 0 additions & 1 deletion Xmss/Internal/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
7 changes: 5 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
15 changes: 15 additions & 0 deletions libc/wasm.diff
Original file line number Diff line number Diff line change
@@ -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}
)
8 changes: 8 additions & 0 deletions libc/xmss.c
Original file line number Diff line number Diff line change
@@ -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
Loading