From 66c5535430b6aa222385b9ece74fbab84adbee26 Mon Sep 17 00:00:00 2001
From: Frans van Dorsselaer <17404029+dorssel@users.noreply.github.com>
Date: Sun, 5 Jan 2025 01:26:18 +0100
Subject: [PATCH] Enable tests for WASM runtime
---
.github/workflows/runtime-browser-wasm.yml | 8 +++-
Xmss/XmssFileStateManager.cs | 46 ++++++++++------------
Xmss/XmssMemoryStateManager.cs | 14 ++++++-
3 files changed, 40 insertions(+), 28 deletions(-)
diff --git a/.github/workflows/runtime-browser-wasm.yml b/.github/workflows/runtime-browser-wasm.yml
index 6b04abe..5c27da5 100644
--- a/.github/workflows/runtime-browser-wasm.yml
+++ b/.github/workflows/runtime-browser-wasm.yml
@@ -41,11 +41,17 @@ jobs:
-S xmss-library
-B build
-DXMSS_C99_COMPATIBLE=OFF
- -DXMSS_BUILD_TESTS=OFF
+ -DCMAKE_EXE_LINKER_FLAGS="-s NODERAWFS=1"
- name: Build
run: cmake --build build
+ - name: Test
+ working-directory: build
+ env:
+ NODE_OPTIONS: --no-experimental-fetch
+ run: ctest
+
- name: Copy artifact
run: |
mkdir -p "Xmss/runtimes/${{ env.RUNTIME }}/nativeassets"
diff --git a/Xmss/XmssFileStateManager.cs b/Xmss/XmssFileStateManager.cs
index 303e30b..6e2076b 100644
--- a/Xmss/XmssFileStateManager.cs
+++ b/Xmss/XmssFileStateManager.cs
@@ -7,9 +7,20 @@
namespace Dorssel.Security.Cryptography;
///
-/// TODO
+/// Manages the state of an XMSS key as files in a given folder.
///
-/// TODO
+///
+/// The folder given by must already exist; it will not be created.
+///
+/// This class will manage the following three files within the folder:
+///
+/// - xmss_private_stateless
+/// - xmss_private_stateful
+/// - xmss_public
+///
+///
+///
+/// The path to the folder holding the state files.
public sealed class XmssFileStateManager(string path)
: IXmssStateManager
{
@@ -37,11 +48,7 @@ string GetPath(XmssKeyPart part)
return TryGetPath(part, out var partPath) ? partPath : throw new ArgumentOutOfRangeException(nameof(part));
}
- ///
- /// TODO
- ///
- /// TODO
- /// TODO
+ ///
public void Store(XmssKeyPart part, ReadOnlySpan data)
{
using var file = File.Open(GetPath(part), FileMode.CreateNew);
@@ -49,12 +56,7 @@ public void Store(XmssKeyPart part, ReadOnlySpan data)
file.Flush();
}
- ///
- /// TODO
- ///
- /// TODO
- /// TODO
- /// TODO
+ ///
public void StoreStatefulPart(ReadOnlySpan expected, ReadOnlySpan data)
{
if (data.Length != expected.Length)
@@ -85,12 +87,7 @@ public void StoreStatefulPart(ReadOnlySpan expected, ReadOnlySpan da
file.Flush();
}
- ///
- /// TODO
- ///
- /// TODO
- /// TODO
- /// TODO
+ ///
public void Load(XmssKeyPart part, Span destination)
{
using var file = File.OpenRead(GetPath(part));
@@ -101,9 +98,7 @@ public void Load(XmssKeyPart part, Span destination)
file.ReadExactly(destination);
}
- ///
- /// TODO
- ///
+ ///
public void DeletePublicPart()
{
File.Delete(GetPath(XmssKeyPart.Public));
@@ -138,9 +133,10 @@ static void SecureDelete(string path)
File.Delete(path);
}
- ///
- /// TODO
- ///
+ ///
+ ///
+ /// This method overwrites files containing private data with zeros before deleting the file.
+ ///
public void Purge()
{
SecureDelete(GetPath(XmssKeyPart.PrivateStateless));
diff --git a/Xmss/XmssMemoryStateManager.cs b/Xmss/XmssMemoryStateManager.cs
index c1b8be8..5a9eeb4 100644
--- a/Xmss/XmssMemoryStateManager.cs
+++ b/Xmss/XmssMemoryStateManager.cs
@@ -8,8 +8,12 @@
namespace Dorssel.Security.Cryptography;
///
-/// TODO
+/// Manages the state of an XMSS key in process memory.
///
+///
+/// The maximum lifetime of the key is bound to the lifetime of the current process.
+/// This class implements to ensure the memory is securely erased before being freed.
+///
public sealed class XmssMemoryStateManager()
: IXmssStateManager, IDisposable
{
@@ -103,7 +107,10 @@ public void DeletePublicPart()
}
}
- ///
+ ///
+ ///
+ /// This method overwrites memory containing private data with zeros before freeing the memory.
+ ///
public void Purge()
{
lock (State)
@@ -121,6 +128,9 @@ public void Purge()
bool IsDisposed;
///
+ ///
+ /// This method calls to ensure that any private data is purged before the memory is freed.
+ ///
public void Dispose()
{
lock (State)