-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from dorssel/ephemeral
Add ephemeral state manager
- Loading branch information
Showing
4 changed files
with
157 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// SPDX-FileCopyrightText: 2025 Frans van Dorsselaer | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
using Dorssel.Security.Cryptography; | ||
|
||
namespace UnitTests; | ||
|
||
[TestClass] | ||
sealed class XmssEphemeralStateManagerTests | ||
{ | ||
[TestMethod] | ||
public void Constructor() | ||
{ | ||
_ = new XmssEphemeralStateManager(); | ||
} | ||
|
||
[TestMethod] | ||
public void Store() | ||
{ | ||
var stateManager = new XmssEphemeralStateManager(); | ||
stateManager.Store(XmssKeyPart.Public, [1]); | ||
} | ||
|
||
[TestMethod] | ||
public void StoreStoreStatefulPart() | ||
{ | ||
var stateManager = new XmssEphemeralStateManager(); | ||
stateManager.Store(XmssKeyPart.PrivateStateful, [1]); | ||
|
||
stateManager.StoreStatefulPart([1], [2]); | ||
} | ||
|
||
[TestMethod] | ||
public void Load() | ||
{ | ||
var data = new byte[] { 1, 2, 3 }; | ||
|
||
var stateManager = new XmssEphemeralStateManager(); | ||
stateManager.Store(XmssKeyPart.Public, data); | ||
|
||
var read = new byte[data.Length]; | ||
|
||
Assert.ThrowsException<NotImplementedException>(() => | ||
{ | ||
stateManager.Load(XmssKeyPart.Public, read); | ||
}); | ||
} | ||
|
||
[TestMethod] | ||
public void DeletePublicPart() | ||
{ | ||
var stateManager = new XmssEphemeralStateManager(); | ||
stateManager.Store(XmssKeyPart.Public, [1]); | ||
|
||
stateManager.DeletePublicPart(); | ||
} | ||
|
||
[TestMethod] | ||
public void DeletePublicPart_NotExists() | ||
{ | ||
var stateManager = new XmssEphemeralStateManager(); | ||
|
||
stateManager.DeletePublicPart(); | ||
} | ||
|
||
[TestMethod] | ||
public void DeleteAll() | ||
{ | ||
var stateManager = new XmssEphemeralStateManager(); | ||
stateManager.Store(XmssKeyPart.PrivateStateless, [1]); | ||
stateManager.Store(XmssKeyPart.PrivateStateful, [2]); | ||
stateManager.Store(XmssKeyPart.Public, [3]); | ||
|
||
stateManager.DeleteAll(); | ||
} | ||
|
||
[TestMethod] | ||
public void DeleteAll_NotExist() | ||
{ | ||
var stateManager = new XmssEphemeralStateManager(); | ||
|
||
stateManager.DeleteAll(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task Use() | ||
{ | ||
using var xmss = new Xmss(); | ||
|
||
xmss.GeneratePrivateKey(new XmssEphemeralStateManager(), XmssParameterSet.XMSS_SHA2_10_256, false); | ||
await xmss.CalculatePublicKeyAsync(); | ||
var message = new byte[] { 1, 2, 3 }; | ||
var signature = xmss.Sign(message); | ||
|
||
Assert.IsTrue(xmss.Verify(message, signature)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-FileCopyrightText: 2025 Frans van Dorsselaer | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
namespace Dorssel.Security.Cryptography; | ||
|
||
/// <summary> | ||
/// TODO | ||
/// </summary> | ||
public sealed class XmssEphemeralStateManager() | ||
: IXmssStateManager | ||
{ | ||
/// <inheritdoc/> | ||
public void Store(XmssKeyPart part, ReadOnlySpan<byte> data) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void StoreStatefulPart(ReadOnlySpan<byte> expected, ReadOnlySpan<byte> data) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void Load(XmssKeyPart part, Span<byte> destination) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void DeletePublicPart() | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void DeleteAll() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters