Skip to content

Commit

Permalink
Merge pull request #236 from shinji-san/release-v0.12.0
Browse files Browse the repository at this point in the history
Release - v0.12.0

Added
- Added .NET 9.0 support
- Added use-case interfaces `IMakeSharesUseCase` and `IReconstructUseCase` to the `SecretSharingDotNet` project.
- Added a guide to the `README.md` file on how to use the use-case interfaces with dependency injection.

Changed
- Changed the `Sqrt` signature in the `BigIntCalculator` class from property to method.
- Changed method visibility from `public` to `protected` in the `BigIntCalculator`and `Calculator` classes to restrict access.

Removed
- Removed .NET 7 support, because it retires on May 14, 2024. See [.NET and .NET Core Support Policy](https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core).
- Removed .NET 6 support, because it retires on November 12, 2024. See [.NET and .NET Core Support Policy](https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core).


Resolves: #236
  • Loading branch information
shinji-san authored Nov 17, 2024
2 parents 689827d + 2412d05 commit 3e67d44
Show file tree
Hide file tree
Showing 20 changed files with 299 additions and 186 deletions.
19 changes: 7 additions & 12 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,19 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup .NET 6
uses: actions/[email protected]
with:
dotnet-version: 6.0.416

- name: Setup .NET 7
uses: actions/[email protected]
- name: Setup .NET 8
uses: actions/[email protected]
with:
dotnet-version: 7.0.403
dotnet-version: 8.0.404

- name: Setup .NET 8
uses: actions/setup-dotnet@v4.0.0
- name: Setup .NET 9
uses: actions/setup-dotnet@v4.1.0
with:
dotnet-version: 8.0.100
dotnet-version: 9.0.100

- name: .NET Core SxS
run: |
rsync -a ${DOTNET_ROOT/8.0.100/7.0.403/6.0.416}/* $DOTNET_ROOT/
rsync -a ${DOTNET_ROOT/8.0.404/9.0.100}/* $DOTNET_ROOT/
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
17 changes: 6 additions & 11 deletions .github/workflows/dotnetall.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup .NET 6
uses: actions/[email protected]
with:
dotnet-version: 6.0.416

- name: Setup .NET 7
uses: actions/[email protected]
- name: Setup .NET 8
uses: actions/[email protected]
with:
dotnet-version: 7.0.403
dotnet-version: 8.0.404

- name: Setup .NET 8
uses: actions/setup-dotnet@v4.0.0
- name: Setup .NET 9
uses: actions/setup-dotnet@v4.1.0
with:
dotnet-version: 8.0.100
dotnet-version: 9.0.100

- name: Restore
run: dotnet restore SecretSharingDotNet.sln
Expand Down
17 changes: 6 additions & 11 deletions .github/workflows/publishing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup .NET 6
uses: actions/[email protected]
with:
dotnet-version: 6.0.416

- name: Setup .NET 7
uses: actions/[email protected]
- name: Setup .NET 8
uses: actions/[email protected]
with:
dotnet-version: 7.0.403
dotnet-version: 8.0.404

- name: Setup .NET 8
uses: actions/setup-dotnet@v4.0.0
- name: Setup .NET 9
uses: actions/setup-dotnet@v4.1.0
with:
dotnet-version: 8.0.100
dotnet-version: 9.0.100

- name: Decrypt large secret
run: ./.github/secrets/decrypt_publisher_snk.sh
Expand Down
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.12.0] - 2024-11-17
### Added
- Added .NET 9.0 support
- Added use-case interfaces `IMakeSharesUseCase` and `IReconstructUseCase` to the `SecretSharingDotNet` project.
- Added a guide to the `README.md` file on how to use the use-case interfaces with dependency injection.

### Changed
- Changed the `Sqrt` signature in the `BigIntCalculator` class from property to method.
- Changed method visibility from `public` to `protected` in the `BigIntCalculator`and `Calculator` classes to restrict access.

### Removed
- Removed .NET 7 support, because it retires on May 14, 2024. See [.NET and .NET Core Support Policy](https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core).
- Removed .NET 6 support, because it retires on November 12, 2024. See [.NET and .NET Core Support Policy](https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core).

## [0.11.0] - 2023-12-30
### Added
- Added support for .NET FX v4.8.1
Expand Down Expand Up @@ -206,7 +220,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `LICENSE.md`
- Added `README.md`

[Unreleased]: https://github.com/shinji-san/SecretSharingDotNet/compare/v0.11.0...develop
[Unreleased]: https://github.com/shinji-san/SecretSharingDotNet/compare/v0.12.0...develop
[0.12.0]: https://github.com/shinji-san/SecretSharingDotNet/compare/v0.11.0...v0.12.0
[0.11.0]: https://github.com/shinji-san/SecretSharingDotNet/compare/v0.10.2...v0.11.0
[0.10.2]: https://github.com/shinji-san/SecretSharingDotNet/compare/v0.10.1...v0.10.2
[0.10.1]: https://github.com/shinji-san/SecretSharingDotNet/compare/v0.10.0...v0.10.1
Expand Down
74 changes: 53 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ An C# implementation of Shamir's Secret Sharing.
</thead>
<tbody>
<tr>
<td rowspan=10><a href ="https://github.com/shinji-san/SecretSharingDotNet/actions?query=workflow%3A%22SecretSharingDotNet+%28All+supported+TFM%29%22" target="_blank"><img src="https://github.com/shinji-san/SecretSharingDotNet/workflows/SecretSharingDotNet%20(All%20supported%20TFM)/badge.svg" alt="Build status"/></a></td>
<td rowspan=10><code>SecretSharingDotNet.sln</code></td>
<td rowspan=10>SDK</td>
<td rowspan=9><a href ="https://github.com/shinji-san/SecretSharingDotNet/actions?query=workflow%3A%22SecretSharingDotNet+%28All+supported+TFM%29%22" target="_blank"><img src="https://github.com/shinji-san/SecretSharingDotNet/workflows/SecretSharingDotNet%20(All%20supported%20TFM)/badge.svg" alt="Build status"/></a></td>
<td rowspan=9><code>SecretSharingDotNet.sln</code></td>
<td rowspan=9>SDK</td>
<td>Standard 2.0</td>
</tr>
<tr>
Expand All @@ -37,13 +37,10 @@ An C# implementation of Shamir's Secret Sharing.
<td>FX 4.8</td>
</tr>
<tr>
<td>.NET 6</td>
</tr>
<tr>
<td>.NET 7</td>
<td>.NET 8</td>
</tr>
<tr>
<td>.NET 8</td>
<td>.NET 9</td>
</tr>
</tbody>
</table>
Expand All @@ -61,9 +58,9 @@ An C# implementation of Shamir's Secret Sharing.
</thead>
<tbody>
<tr>
<td rowspan=10><a href="https://github.com/shinji-san/SecretSharingDotNet/actions?query=workflow%3A%22SecretSharingDotNet+NuGet%22" target="_blank"><img src="https://github.com/shinji-san/SecretSharingDotNet/workflows/SecretSharingDotNet%20NuGet/badge.svg?branch=v0.11.0" alt="SecretSharingDotNet NuGet"/></a></td>
<td rowspan=10><a href="https://badge.fury.io/nu/SecretSharingDotNet" target="_blank"><img src="https://badge.fury.io/nu/SecretSharingDotNet.svg" alt="NuGet Version 0.11.0"/></a></td>
<td rowspan=10><a href="https://github.com/shinji-san/SecretSharingDotNet/tree/v0.11.0" target="_blank"><img src="https://img.shields.io/badge/SecretSharingDotNet-0.11.0-green.svg?logo=github&logoColor=959da5&color=2ebb4e&labelColor=2b3137" alt="Tag"/></a></td>
<td rowspan=9><a href="https://github.com/shinji-san/SecretSharingDotNet/actions?query=workflow%3A%22SecretSharingDotNet+NuGet%22" target="_blank"><img src="https://github.com/shinji-san/SecretSharingDotNet/workflows/SecretSharingDotNet%20NuGet/badge.svg?branch=v0.12.0" alt="SecretSharingDotNet NuGet"/></a></td>
<td rowspan=9><a href="https://badge.fury.io/nu/SecretSharingDotNet" target="_blank"><img src="https://badge.fury.io/nu/SecretSharingDotNet.svg" alt="NuGet Version 0.12.0"/></a></td>
<td rowspan=9><a href="https://github.com/shinji-san/SecretSharingDotNet/tree/v0.12.0" target="_blank"><img src="https://img.shields.io/badge/SecretSharingDotNet-0.12.0-green.svg?logo=github&logoColor=959da5&color=2ebb4e&labelColor=2b3137" alt="Tag"/></a></td>
<td>Standard 2.0</td>
</tr>
<tr>
Expand All @@ -85,13 +82,10 @@ An C# implementation of Shamir's Secret Sharing.
<td>FX 4.8</td>
</tr>
<tr>
<td>.NET 6</td>
<td>.NET 8</td>
</tr>
<tr>
<td>.NET 7</td>
</tr>
<tr>
<td>.NET 8</td>
<td>.NET 9</td>
</tr>
</tbody>
</table>
Expand All @@ -100,10 +94,10 @@ An C# implementation of Shamir's Secret Sharing.

1. Open a console and switch to the directory, containing your project file.

2. Use the following command to install version 0.11.0 of the SecretSharingDotNet package:
2. Use the following command to install version 0.12.0 of the SecretSharingDotNet package:

```dotnetcli
dotnet add package SecretSharingDotNet -v 0.11.0 -f <FRAMEWORK>
dotnet add package SecretSharingDotNet -v 0.12.0 -f <FRAMEWORK>
```
3. After the completion of the command, look at the project file to make sure that the package is successfully installed.
Expand All @@ -112,7 +106,7 @@ An C# implementation of Shamir's Secret Sharing.
```xml
<ItemGroup>
<PackageReference Include="SecretSharingDotNet" Version="0.11.0" />
<PackageReference Include="SecretSharingDotNet" Version="0.12.0" />
</ItemGroup>
```
## Remove SecretSharingDotNet package
Expand All @@ -134,7 +128,45 @@ An C# implementation of Shamir's Secret Sharing.
Use the function `MakeShares` to generate the shares, based on a random or pre-defined secret.
Afterwards, use the function `Reconstruction` to re-construct the original secret.
The length of the shares is based on the security level. It's possible to pre-define a security level by `ctor` or the `SecurityLevel` property. The pre-defined security level will be overriden, if the secret size is greater than the Mersenne prime, which is calculated by means of the security level. It is not necessary to define a security level for a re-construction.
The length of the shares is based on the security level. It is possible to pre-define a security level by `ctor` or the `SecurityLevel` property. The pre-defined security level will be overriden, if the secret size is greater than the Mersenne prime, which is calculated by means of the security level. It is not necessary to define a security level for a re-construction.
## Using the SecretSharingDotNet library with DI in a .NET project.
This guide will demonstrate how to use the SecretSharingDotNet library with Dependency Injection (DI) in a .NET project.
Firstly, add the following dependencies:
```csharp
using Microsoft.Extensions.DependencyInjection;
using SecretSharingDotNet.Cryptography;
using SecretSharingDotNet.Math;
using System.Numerics;
```
Next, initialize a `ServiceCollection` instance and add dependencies to the DI container:
```csharp
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton<IExtendedGcdAlgorithm<BigInteger>, ExtendedEuclideanAlgorithm<BigInteger>>();
serviceCollection.AddSingleton<IMakeSharesUseCase<BigInteger>, ShamirsSecretSharing<BigInteger>>();
serviceCollection.AddSingleton<IReconstructionUseCase<BigInteger>, ShamirsSecretSharing<BigInteger>>();
using var serviceProvider = serviceCollection.BuildServiceProvider();
```
In the code above, the `ServiceCollection` registers an implementation for each of the main components of the SecretSharingDotNet library.

Next, create an instance of the `IMakeSharesUseCase<BigInteger>`:
```csharp
var makeSharesUseCase = serviceProvider.GetRequiredService<IMakeSharesUseCase<BigInteger>>();
```
Using this instance, it is possible to create shares from a secret:
```csharp
var shares = makeSharesUseCase.MakeShares(3, 7, "Hello!");
Console.WriteLine(shares);
```
Similarly, an instance of `IReconstructionUseCase<BigInteger>` can be created to rebuild the original secret:
```csharp
var reconstructionUseCase = serviceProvider.GetRequiredService<IReconstructionUseCase<BigInteger>>();
var reconstruction = reconstructionUseCase.Reconstruction(shares.Where(p => p.X.IsEven).ToArray());
Console.WriteLine(reconstruction);
```

The code above reconstructs the original secret from the shares, and then outputs it.

## Random secret
Create a random secret in conjunction with the generation of shares. The length of the generated shares and of the secret are based on the security level. Here is an example with a pre-defined security level of 127:
Expand Down Expand Up @@ -409,7 +441,7 @@ You can find the Mono installation instructions [here](https://www.mono-project.

The .NET Frameworks 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 and 4.8.1 can be found [here](https://dotnet.microsoft.com/download/dotnet-framework).

The .NET SDKs 6.0, 7.0 and 8.0 can be found [here](https://dotnet.microsoft.com/download/dotnet).
The .NET SDKs 8.0 and 9.0 can be found [here](https://dotnet.microsoft.com/download/dotnet).

## Build and test the solution
You can use the `SecretSharingDotNet.sln` solution file with the `dotnet` command to build the [SecretSharingDotNet](#secretsharingdotnet) library in the `Debug` or `Release` configuration. You can also use the `dotnet` command to start the unit tests.
Expand Down
33 changes: 16 additions & 17 deletions src/Cryptography/FinitePoint`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,45 +154,45 @@ public FinitePoint(Calculator<TNumber> x, Calculator<TNumber> y)
/// </summary>
/// <param name="left">The left operand</param>
/// <param name="right">The right operand</param>
/// <returns>Returns <see langword="true"/> if its operands are not equal, otherwise <see langword="false"/>.</returns>
/// <returns>Returns <see langword="true"/> if its operands aren't equal, otherwise <see langword="false"/>.</returns>
public static bool operator !=(FinitePoint<TNumber> left, FinitePoint<TNumber> right) => !left.Equals(right);

/// <summary>
/// Greater than operator
/// </summary>
/// <param name="left">The 1st operand</param>
/// <param name="right">The 2nd operand</param>
/// <returns>Returns <see langword="true"/> if its 1st operand is greater than its 2nd operand, otherwise <see langword="false"/>.</returns>
/// <param name="left">The first operand</param>
/// <param name="right">The second operand</param>
/// <returns>Returns <see langword="true"/> if its first operand is greater than its second operand, otherwise <see langword="false"/>.</returns>
public static bool operator >(FinitePoint<TNumber> left, FinitePoint<TNumber> right) => left.CompareTo(right) == 1;

/// <summary>
/// Less than operator
/// </summary>
/// <param name="left">The 1st operand</param>
/// <param name="right">The 2nd operand</param>
/// <returns>Returns <see langword="true"/> if its 1st operand is less than its 2nd operand, otherwise <see langword="false"/>.</returns>
/// <param name="left">The first operand</param>
/// <param name="right">The second operand</param>
/// <returns>Returns <see langword="true"/> if its first operand is less than its second operand, otherwise <see langword="false"/>.</returns>
public static bool operator <(FinitePoint<TNumber> left, FinitePoint<TNumber> right) => left.CompareTo(right) == -1;

/// <summary>
/// Greater than or equal operator
/// </summary>
/// <param name="left">The 1st operand</param>
/// <param name="right">The 2nd operand</param>
/// <returns>Returns <see langword="true"/> if its 1st operand is greater than or equal to its 2nd operand, otherwise <see langword="false"/>.</returns>
/// <param name="right">The second operand</param>
/// <returns>Returns <see langword="true"/> if its first operand is greater than or equal to its second operand, otherwise <see langword="false"/>.</returns>
public static bool operator >=(FinitePoint<TNumber> left, FinitePoint<TNumber> right) => left.CompareTo(right) >= 0;

/// <summary>
/// Less than or equal operator
/// </summary>
/// <param name="left">The 1st operand</param>
/// <param name="right">The 2nd operand</param>
/// <returns>Returns <see langword="true"/> if its 1st operand is less than or equal to its 2nd operand, otherwise <see langword="false"/>.</returns>
/// <param name="left">The first operand</param>
/// <param name="right">The second operand</param>
/// <returns>Returns <see langword="true"/> if its first operand is less than or equal to its second operand, otherwise <see langword="false"/>.</returns>
public static bool operator <=(FinitePoint<TNumber> left, FinitePoint<TNumber> right) => left.CompareTo(right) <= 0;

/// <inheritdoc />
public int CompareTo(FinitePoint<TNumber> other)
{
return ((this.X.Pow(2) + this.Y.Pow(2)).Sqrt - (other.X.Pow(2) + other.Y.Pow(2)).Sqrt).Sign;
return ((this.X.Pow(2) + this.Y.Pow(2)).Sqrt() - (other.X.Pow(2) + other.Y.Pow(2)).Sqrt()).Sign;
}

/// <summary>
Expand Down Expand Up @@ -251,7 +251,7 @@ private static Calculator<TNumber> Evaluate(IEnumerable<Calculator<TNumber>> pol
/// Converts a byte collection to hexadecimal string.
/// </summary>
/// <param name="bytes"></param>
/// <returns>human readable / printable string</returns>
/// <returns>human-readable / printable string</returns>
/// <remarks>
/// Based on discussion on <see href="https://stackoverflow.com/questions/623104/byte-to-hex-string/5919521#5919521">stackoverflow</see>
/// </remarks>
Expand Down Expand Up @@ -287,8 +287,7 @@ private static string ToHexString(IEnumerable<byte> bytes)
private static byte[] ToByteArray(string hexString)
{
byte[] bytes = new byte[hexString.Length / 2];
var hexValues = Array.AsReadOnly(new[]
{
var hexValues = Array.AsReadOnly([
0x00,
0x01,
0x02,
Expand All @@ -312,7 +311,7 @@ private static byte[] ToByteArray(string hexString)
0x0D,
0x0E,
0x0F
});
]);

for (int i = 0, j = 0; j < hexString.Length; j += 2, i += 1)
{
Expand Down
Loading

0 comments on commit 3e67d44

Please sign in to comment.