Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #41

Merged
merged 5 commits into from
Aug 16, 2024
Merged

Dev #41

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
7 changes: 4 additions & 3 deletions src/wan24-Crypto-BC Tests/wan24-Crypto-BC Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
<IsPackable>false</IsPackable>

<Configurations>Debug;Release;Trunk</Configurations>
<EnablePreviewFeatures Condition="'$(Configuration)' != 'Release'">True</EnablePreviewFeatures>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.2" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="wan24-Crypto-Shared-Tests" Version="2.4.0" />
<PackageReference Include="wan24-Crypto-Shared-Tests" Version="2.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
34 changes: 25 additions & 9 deletions src/wan24-Crypto-BC.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ObjectValidation", "..\..\O
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stream-Serializer-Extensions", "..\..\Stream-Serializer-Extensions\src\Stream-Serializer-Extensions\Stream-Serializer-Extensions.csproj", "{21705885-E17E-4265-9CE7-C00AB7FB63B0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MappingObject", "..\..\Mapping-Object\src\MappingObject\MappingObject.csproj", "{2668557E-CAD7-44CA-921A-A5A6329906D4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wan24-Core-Validation", "..\..\wan24-Core\src\Wan24-Core-Validation\Wan24-Core-Validation.csproj", "{C8B6110C-9FE3-46B5-A1C6-B3FDE42F5385}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Referenced", "Referenced", "{50D28E77-F7A1-4252-893F-72FEF5D7D76E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -40,26 +42,40 @@ Global
{19293508-BC9C-4429-AB47-270C3C7ACE78}.Trunk|Any CPU.Build.0 = Trunk|Any CPU
{678B09FC-7C24-4801-AF72-1800E4C7CD38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{678B09FC-7C24-4801-AF72-1800E4C7CD38}.Release|Any CPU.ActiveCfg = Release|Any CPU
{678B09FC-7C24-4801-AF72-1800E4C7CD38}.Trunk|Any CPU.ActiveCfg = Debug|Any CPU
{678B09FC-7C24-4801-AF72-1800E4C7CD38}.Trunk|Any CPU.ActiveCfg = Trunk|Any CPU
{678B09FC-7C24-4801-AF72-1800E4C7CD38}.Trunk|Any CPU.Build.0 = Trunk|Any CPU
{C77DD1B2-571E-4BA2-94E7-7F9073F084B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C77DD1B2-571E-4BA2-94E7-7F9073F084B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C77DD1B2-571E-4BA2-94E7-7F9073F084B9}.Trunk|Any CPU.ActiveCfg = Debug|Any CPU
{C77DD1B2-571E-4BA2-94E7-7F9073F084B9}.Trunk|Any CPU.ActiveCfg = Trunk|Any CPU
{C77DD1B2-571E-4BA2-94E7-7F9073F084B9}.Trunk|Any CPU.Build.0 = Trunk|Any CPU
{D1EFBD7D-2321-403D-AE88-586E4BB6D455}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1EFBD7D-2321-403D-AE88-586E4BB6D455}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1EFBD7D-2321-403D-AE88-586E4BB6D455}.Trunk|Any CPU.ActiveCfg = Debug|Any CPU
{D1EFBD7D-2321-403D-AE88-586E4BB6D455}.Trunk|Any CPU.ActiveCfg = Trunk|Any CPU
{D1EFBD7D-2321-403D-AE88-586E4BB6D455}.Trunk|Any CPU.Build.0 = Trunk|Any CPU
{2490B026-D9E6-4A5D-830D-CDA9F85A984C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2490B026-D9E6-4A5D-830D-CDA9F85A984C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2490B026-D9E6-4A5D-830D-CDA9F85A984C}.Trunk|Any CPU.ActiveCfg = Debug|Any CPU
{2490B026-D9E6-4A5D-830D-CDA9F85A984C}.Trunk|Any CPU.ActiveCfg = Trunk|Any CPU
{2490B026-D9E6-4A5D-830D-CDA9F85A984C}.Trunk|Any CPU.Build.0 = Trunk|Any CPU
{21705885-E17E-4265-9CE7-C00AB7FB63B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{21705885-E17E-4265-9CE7-C00AB7FB63B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{21705885-E17E-4265-9CE7-C00AB7FB63B0}.Trunk|Any CPU.ActiveCfg = Debug|Any CPU
{2668557E-CAD7-44CA-921A-A5A6329906D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2668557E-CAD7-44CA-921A-A5A6329906D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2668557E-CAD7-44CA-921A-A5A6329906D4}.Trunk|Any CPU.ActiveCfg = Debug|Any CPU
{21705885-E17E-4265-9CE7-C00AB7FB63B0}.Trunk|Any CPU.ActiveCfg = Trunk|Any CPU
{21705885-E17E-4265-9CE7-C00AB7FB63B0}.Trunk|Any CPU.Build.0 = Trunk|Any CPU
{C8B6110C-9FE3-46B5-A1C6-B3FDE42F5385}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C8B6110C-9FE3-46B5-A1C6-B3FDE42F5385}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8B6110C-9FE3-46B5-A1C6-B3FDE42F5385}.Trunk|Any CPU.ActiveCfg = Trunk|Any CPU
{C8B6110C-9FE3-46B5-A1C6-B3FDE42F5385}.Trunk|Any CPU.Build.0 = Trunk|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{678B09FC-7C24-4801-AF72-1800E4C7CD38} = {50D28E77-F7A1-4252-893F-72FEF5D7D76E}
{C77DD1B2-571E-4BA2-94E7-7F9073F084B9} = {50D28E77-F7A1-4252-893F-72FEF5D7D76E}
{D1EFBD7D-2321-403D-AE88-586E4BB6D455} = {50D28E77-F7A1-4252-893F-72FEF5D7D76E}
{2490B026-D9E6-4A5D-830D-CDA9F85A984C} = {50D28E77-F7A1-4252-893F-72FEF5D7D76E}
{21705885-E17E-4265-9CE7-C00AB7FB63B0} = {50D28E77-F7A1-4252-893F-72FEF5D7D76E}
{C8B6110C-9FE3-46B5-A1C6-B3FDE42F5385} = {50D28E77-F7A1-4252-893F-72FEF5D7D76E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {27F0CF2F-65DE-4E39-9D87-5632FA3F15CF}
EndGlobalSection
Expand Down
8 changes: 4 additions & 4 deletions src/wan24-Crypto-BC/AsymmetricSphincsPlusPrivateKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
if (Keys is null) return;
//TODO All parameter fields are private :(
typeof(SphincsPlusPrivateKeyParameters).GetFieldCached("m_sk", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(Keys.Private)!.ClearPrivateByteArrayFields();
typeof(SphincsPlusPrivateKeyParameters).GetFieldCached("m_pk", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(Keys.Private)!.ClearPrivateByteArrayFields();
typeof(SphincsPlusPrivateKeyParameters).GetFieldCached("m_sk", BindingFlags.Instance | BindingFlags.NonPublic)!.Getter!(Keys.Private)!.ClearPrivateByteArrayFields();
typeof(SphincsPlusPrivateKeyParameters).GetFieldCached("m_pk", BindingFlags.Instance | BindingFlags.NonPublic)!.Getter!(Keys.Private)!.ClearPrivateByteArrayFields();
}

/// <inheritdoc/>
Expand All @@ -126,8 +126,8 @@ protected override async Task DisposeCore()
await base.DisposeCore().DynamicContext();
if (Keys is null) return;
//TODO All parameter fields are private :(
typeof(SphincsPlusPrivateKeyParameters).GetFieldCached("m_sk", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(Keys.Private)!.ClearPrivateByteArrayFields();
typeof(SphincsPlusPrivateKeyParameters).GetFieldCached("m_pk", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(Keys.Private)!.ClearPrivateByteArrayFields();
typeof(SphincsPlusPrivateKeyParameters).GetFieldCached("m_sk", BindingFlags.Instance | BindingFlags.NonPublic)!.Getter!(Keys.Private)!.ClearPrivateByteArrayFields();
typeof(SphincsPlusPrivateKeyParameters).GetFieldCached("m_pk", BindingFlags.Instance | BindingFlags.NonPublic)!.Getter!(Keys.Private)!.ClearPrivateByteArrayFields();
}

/// <summary>
Expand Down
12 changes: 6 additions & 6 deletions src/wan24-Crypto-BC/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public static class Extensions
/// <returns>Internal state</returns>
public static byte[] GetState(this VmpcRandomGenerator rng)
{
byte[] p = (byte[])VmpcRandomGeneratorType.GetFieldCached(P_FIELD, BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(rng)!,
byte[] p = (byte[])VmpcRandomGeneratorType.GetFieldCached(P_FIELD, BindingFlags.NonPublic | BindingFlags.Instance)!.Getter!(rng)!,
res = new byte[p.Length + 2];
lock (p)
{
p.AsSpan().CopyTo(res);
p[^2] = (byte)VmpcRandomGeneratorType.GetFieldCached(S_FIELD, BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(rng)!;
p[^1] = (byte)VmpcRandomGeneratorType.GetFieldCached(N_FIELD, BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(rng)!;
p[^2] = (byte)VmpcRandomGeneratorType.GetFieldCached(S_FIELD, BindingFlags.NonPublic | BindingFlags.Instance)!.Getter!(rng)!;
p[^1] = (byte)VmpcRandomGeneratorType.GetFieldCached(N_FIELD, BindingFlags.NonPublic | BindingFlags.Instance)!.Getter!(rng)!;
}
return res;
}
Expand All @@ -53,13 +53,13 @@ public static byte[] GetState(this VmpcRandomGenerator rng)
/// <param name="state">Stored internal state</param>
public static void RestoreState(this VmpcRandomGenerator rng, ReadOnlySpan<byte> state)
{
byte[] p = (byte[])VmpcRandomGeneratorType.GetFieldCached(P_FIELD, BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(rng)!;
byte[] p = (byte[])VmpcRandomGeneratorType.GetFieldCached(P_FIELD, BindingFlags.NonPublic | BindingFlags.Instance)!.Getter!(rng)!;
if (state.Length < p.Length + 2) throw new ArgumentOutOfRangeException(nameof(state));
lock (p)
{
state[..p.Length].CopyTo(p);
VmpcRandomGeneratorType.GetFieldCached(S_FIELD, BindingFlags.NonPublic | BindingFlags.Instance)!.SetValue(rng, state[p.Length]);
VmpcRandomGeneratorType.GetFieldCached(N_FIELD, BindingFlags.NonPublic | BindingFlags.Instance)!.SetValue(rng, state[p.Length + 1]);
VmpcRandomGeneratorType.GetFieldCached(S_FIELD, BindingFlags.NonPublic | BindingFlags.Instance)!.Setter!(rng, state[p.Length]);
VmpcRandomGeneratorType.GetFieldCached(N_FIELD, BindingFlags.NonPublic | BindingFlags.Instance)!.Setter!(rng, state[p.Length + 1]);
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/wan24-Crypto-BC/InternalReflectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static class InternalReflectionExtensions
/// <summary>
/// Private byte array fields (key is the type hash code)
/// </summary>
private static readonly ConcurrentDictionary<int, FieldInfo[]> Fields = new();
private static readonly ConcurrentDictionary<int, FieldInfoExt[]> Fields = new();

/// <summary>
/// Clear all private byte array fields
Expand All @@ -22,15 +22,16 @@ internal static void ClearPrivateByteArrayFields(this object obj)
{
Type type = obj.GetType();
int hashCode = type.GetHashCode();
if (!Fields.TryGetValue(hashCode, out FieldInfo[]? fields))
if (!Fields.TryGetValue(hashCode, out FieldInfoExt[]? fields))
{
Type baType = typeof(byte[]);
fields = (from fi in type.GetFieldsCached(BindingFlags.Instance | BindingFlags.NonPublic)
where fi.FieldType == baType
select fi).ToArray();
fields = [..from fi in type.GetFieldsCached(BindingFlags.Instance | BindingFlags.NonPublic)
where fi.FieldType == baType &&
fi.Getter is not null
select fi];
Fields.TryAdd(hashCode, fields);
}
for (int i = 0, len = fields.Length; i < len; (fields[i].GetValue(obj) as byte[])?.Clear(), i++) ;
for (int i = 0, len = fields.Length; i < len; (fields[i].Getter!(obj) as byte[])?.Clear(), i++) ;
}
}
}
8 changes: 5 additions & 3 deletions src/wan24-Crypto-BC/wan24-Crypto-BC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<PackageId>wan24-Crypto-BC</PackageId>
<Title>wan24-Crypto-BC</Title>
<Version>3.10.1</Version>
<Version>3.11.0</Version>
<Authors>nd1012</Authors>
<Company>Andreas Zimmermann, wan24.de</Company>
<Product>wan24-Crypto-BC</Product>
Expand All @@ -25,6 +25,7 @@
<DebugType>embedded</DebugType>
<EmbedAllSources>true</EmbedAllSources>
<Configurations>Debug;Release;Trunk</Configurations>
<EnablePreviewFeatures Condition="'$(Configuration)' != 'Release'">True</EnablePreviewFeatures>
</PropertyGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition="'$(OS)' == 'Windows_NT'">
Expand All @@ -33,8 +34,9 @@

<ItemGroup>
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
<PackageReference Include="wan24-Core" Version="2.32.0" Condition="'$(Configuration)' != 'Trunk'" />
<PackageReference Include="wan24-Crypto" Version="2.16.1" Condition="'$(Configuration)' != 'Trunk'" />
<PackageReference Include="wan24-Core" Version="2.34.0" Condition="'$(Configuration)' != 'Trunk'" />
<PackageReference Include="wan24-Crypto" Version="2.17.0" Condition="'$(Configuration)' != 'Trunk'" />
<ProjectReference Include="..\..\..\wan24-Core\src\Wan24-Core-Validation\Wan24-Core-Validation.csproj" Condition="'$(Configuration)' == 'Trunk'" />
<ProjectReference Include="..\..\..\wan24-Core\src\Wan24-Core\Wan24-Core.csproj" Condition="'$(Configuration)' == 'Trunk'" />
<ProjectReference Include="..\..\..\wan24-Crypto\src\wan24-Crypto\wan24-Crypto.csproj" Condition="'$(Configuration)' == 'Trunk'" />
</ItemGroup>
Expand Down
Loading