Skip to content

Commit a0f4dd2

Browse files
authored
Merge pull request #161 from shinji-san/release-v0.10.2
Release - v0.10.2 Changed - FinitePoint: Use `ReadOnlySpan<char>` for `string` parameters in ctor and methods. Deprecated - The Secret Legacy Mode is marked as deprecated and will be removed in one of the next releases. Fixed - Fixed NETSDK1187 warning (see #151). Locale 'de-de' is normalized to the standard locale 'de-DE'. Resolves: #161
2 parents de63002 + e63a63f commit a0f4dd2

21 files changed

+300
-72
lines changed

.github/workflows/codeql-analysis.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@ jobs:
3939

4040
steps:
4141
- name: Checkout repository
42-
uses: actions/checkout@v3
42+
uses: actions/checkout@v4
4343

4444
- name: Setup .NET 6
45-
uses: actions/setup-dotnet@v3.0.3
45+
uses: actions/setup-dotnet@v3.2.0
4646
with:
47-
dotnet-version: 6.0.100
47+
dotnet-version: 6.0.414
4848

4949
- name: Setup .NET 7
50-
uses: actions/setup-dotnet@v3.0.3
50+
uses: actions/setup-dotnet@v3.2.0
5151
with:
52-
dotnet-version: 7.0.100
52+
dotnet-version: 7.0.401
5353

5454
- name: .NET Core SxS
5555
run: |
56-
rsync -a ${DOTNET_ROOT/7.0.100/6.0.100}/* $DOTNET_ROOT/
56+
rsync -a ${DOTNET_ROOT/7.0.401/6.0.414}/* $DOTNET_ROOT/
5757
5858
# Initializes the CodeQL tools for scanning.
5959
- name: Initialize CodeQL

.github/workflows/dotnet.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ jobs:
1717
DOTNET_CLI_TELEMETRY_OPTOUT: true
1818
strategy:
1919
matrix:
20-
dotnet: [ '6.0.100', '7.0.100' ]
20+
dotnet: [ '6.0.414', '7.0.401' ]
2121
name: Dotnet ${{ matrix.dotnet }}
2222

2323
steps:
24-
- uses: actions/checkout@v3
24+
- uses: actions/checkout@v4
2525
- name: Setup .NET Core
26-
uses: actions/setup-dotnet@v3.0.3
26+
uses: actions/setup-dotnet@v3.2.0
2727
with:
2828
dotnet-version: ${{ matrix.dotnet }}
2929
- name: Build with dotnet SDK v6.0
30-
if: matrix.dotnet == '6.0.100'
30+
if: matrix.dotnet == '6.0.414'
3131
run: dotnet build --configuration Release SecretSharingDotNet6.sln
3232
- name: Test with dotnet SDK v6.0
33-
if: matrix.dotnet == '6.0.100'
33+
if: matrix.dotnet == '6.0.414'
3434
run: dotnet test --configuration Release SecretSharingDotNet6.sln
3535
- name: Build with dotnet SDK v7.0
36-
if: matrix.dotnet == '7.0.100'
36+
if: matrix.dotnet == '7.0.401'
3737
run: dotnet build --configuration Release SecretSharingDotNet7.sln
3838
- name: Test with dotnet SDK v7.0
39-
if: matrix.dotnet == '7.0.100'
39+
if: matrix.dotnet == '7.0.401'
4040
run: dotnet test --configuration Release SecretSharingDotNet7.sln

.github/workflows/dotnetall.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ jobs:
1616
env:
1717
DOTNET_CLI_TELEMETRY_OPTOUT: true
1818
steps:
19-
- uses: actions/checkout@v3
19+
- uses: actions/checkout@v4
2020

2121
- name: Setup .NET 6
22-
uses: actions/setup-dotnet@v3.0.3
22+
uses: actions/setup-dotnet@v3.2.0
2323
with:
24-
dotnet-version: 6.0.100
24+
dotnet-version: 6.0.414
2525

2626
- name: Setup .NET 7
27-
uses: actions/setup-dotnet@v3.0.3
27+
uses: actions/setup-dotnet@v3.2.0
2828
with:
29-
dotnet-version: 7.0.100
29+
dotnet-version: 7.0.401
3030

3131
- name: .NET Core SxS
3232
run: |
33-
rsync -a ${DOTNET_ROOT/7.0.100/6.0.100}/* $DOTNET_ROOT/
33+
rsync -a ${DOTNET_ROOT/7.0.401/6.0.414}/* $DOTNET_ROOT/
3434
3535
- name: Restore
3636
run: dotnet restore SecretSharingDotNet.sln

.github/workflows/dotnetfx.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
steps:
1818
- name: checkout
19-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
2020

2121
- name: Setup Nuget.exe
2222
uses: nuget/[email protected]

.github/workflows/publishing.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ jobs:
1414
env:
1515
DOTNET_CLI_TELEMETRY_OPTOUT: true
1616
steps:
17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
1818

1919
- name: Setup .NET 6
20-
uses: actions/setup-dotnet@v3.0.3
20+
uses: actions/setup-dotnet@v3.2.0
2121
with:
22-
dotnet-version: 6.0.100
22+
dotnet-version: 6.0.414
2323

2424
- name: Setup .NET 7
25-
uses: actions/setup-dotnet@v3.0.3
25+
uses: actions/setup-dotnet@v3.2.0
2626
with:
27-
dotnet-version: 7.0.100
27+
dotnet-version: 7.0.401
2828

2929
- name: .NET Core SxS
3030
run: |
31-
rsync -a ${DOTNET_ROOT/7.0.100/6.0.100}/* $DOTNET_ROOT/
31+
rsync -a ${DOTNET_ROOT/7.0.401/6.0.414}/* $DOTNET_ROOT/
3232
3333
- name: Decrypt large secret
3434
run: ./.github/secrets/decrypt_publisher_snk.sh

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.10.2] - 2023-09-16
8+
### Changed
9+
- FinitePoint: Use `ReadOnlySpan<char>` for `string` parameters in ctor and methods.
10+
11+
### Deprecated
12+
- The Secret Legacy Mode is marked as deprecated and will be removed in one of the next releases.
13+
14+
### Fixed
15+
- Fixed NETSDK1187 warning (see #151). Locale 'de-de' is normalized to the standard locale 'de-DE'.
16+
717
## [0.10.1] - 2023-05-08
818
### Fixed
919
- Fixed BigIntCalculator's Equals method to avoid timing attacks. The slow equal implementation is used now.
@@ -182,6 +192,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
182192
- Added `LICENSE.md`
183193
- Added `README.md`
184194

195+
[0.10.2]: https://github.com/shinji-san/SecretSharingDotNet/compare/v0.10.1...v0.10.2
185196
[0.10.1]: https://github.com/shinji-san/SecretSharingDotNet/compare/v0.10.0...v0.10.1
186197
[0.10.0]: https://github.com/shinji-san/SecretSharingDotNet/compare/v0.9.0...v0.10.0
187198
[0.9.0]: https://github.com/shinji-san/SecretSharingDotNet/compare/v0.8.0...v0.9.0

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ An C# implementation of Shamir's Secret Sharing.
7474
</thead>
7575
<tbody>
7676
<tr>
77-
<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.10.1" alt="SecretSharingDotNet NuGet"/></a></td>
78-
<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.10.1"/></a></td>
79-
<td rowspan=9><a href="https://github.com/shinji-san/SecretSharingDotNet/tree/v0.10.1" target="_blank"><img src="https://img.shields.io/badge/SecretSharingDotNet-0.10.1-green.svg?logo=github&logoColor=959da5&color=2ebb4e&labelColor=2b3137" alt="Tag"/></a></td>
77+
<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.10.2" alt="SecretSharingDotNet NuGet"/></a></td>
78+
<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.10.2"/></a></td>
79+
<td rowspan=9><a href="https://github.com/shinji-san/SecretSharingDotNet/tree/v0.10.2" target="_blank"><img src="https://img.shields.io/badge/SecretSharingDotNet-0.10.2-green.svg?logo=github&logoColor=959da5&color=2ebb4e&labelColor=2b3137" alt="Tag"/></a></td>
8080
<td>Standard 2.0</td>
8181
</tr>
8282
<tr>
@@ -110,10 +110,10 @@ An C# implementation of Shamir's Secret Sharing.
110110

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

113-
2. Use the following command to install version 0.10.1 of the SecretSharingDotNet package:
113+
2. Use the following command to install version 0.10.2 of the SecretSharingDotNet package:
114114

115115
```dotnetcli
116-
dotnet add package SecretSharingDotNet -v 0.10.1 -f <FRAMEWORK>
116+
dotnet add package SecretSharingDotNet -v 0.10.2 -f <FRAMEWORK>
117117
```
118118
119119
3. After the completition of the command, look at the project file to make sure that the package is successfuly installed.
@@ -122,7 +122,7 @@ An C# implementation of Shamir's Secret Sharing.
122122
123123
```xml
124124
<ItemGroup>
125-
<PackageReference Include="SecretSharingDotNet" Version="0.10.1" />
125+
<PackageReference Include="SecretSharingDotNet" Version="0.10.2" />
126126
</ItemGroup>
127127
```
128128
## Remove SecretSharingDotNet package
@@ -146,13 +146,13 @@ Afterwards, use the function `Reconstruction` to re-construct the original secre
146146
147147
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.
148148
149-
## Attention: Breaking change - Normal and legacy mode in v0.7.0
149+
## Attention: Breaking change - Normal and legacy mode in v0.7.0 [Deprecated]
150150
151151
Library version 0.7.0 introduces a normal mode and a legacy mode for secrets. The normal mode is the new and default mode. The legacy mode is for backward compatibility.
152152
153153
*Why was the normal mode introduced?*
154154
155-
The normal mode supports positive secret values and also negative secret values like negative integer numbers or byte arrays with most significant byte greater than 0x7F. The legacy mode generates shares that can't be used to reconstruct negative secret values. So the original secret and the reconstructed secret aren't identical for negative secret values (e.g. `BigInetger secret = -2000`). The legacy mode only returns correct results for positive secret values.
155+
The normal mode supports positive secret values and also negative secret values like negative integer numbers or byte arrays with most significant byte greater than 0x7F. The legacy mode generates shares that can't be used to reconstruct negative secret values. So the original secret and the reconstructed secret aren't identical for negative secret values (e.g. `BigInteger secret = -2000`). The legacy mode only returns correct results for positive secret values.
156156
157157
*Mode overview*
158158

src/Cryptography/FinitePoint.cs src/Cryptography/FinitePoint`1.cs

+47-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ----------------------------------------------------------------------------
2-
// <copyright file="FinitePoint.cs" company="Private">
3-
// Copyright (c) 2019 All Rights Reserved
2+
// <copyright file="FinitePoint`1.cs" company="Private">
3+
// Copyright (c) 2023 All Rights Reserved
44
// </copyright>
55
// <author>Sebastian Walther</author>
6-
// <date>04/20/2019 10:52:28 PM</date>
6+
// <date>05/27/2023 06:05:12 PM</date>
77
// ----------------------------------------------------------------------------
88

99
#region License
@@ -36,7 +36,11 @@ namespace SecretSharingDotNet.Cryptography
3636
using System.Collections.Generic;
3737
using System.Globalization;
3838
using System.Linq;
39+
#if !NET6_0_OR_GREATER
3940
using System.Text;
41+
#else
42+
using System.Runtime.CompilerServices;
43+
#endif
4044

4145
/// <summary>
4246
/// Represents the support point of the polynomial
@@ -73,17 +77,33 @@ public FinitePoint(Calculator<TNumber> x, ICollection<Calculator<TNumber>> polyn
7377
/// </summary>
7478
/// <param name="serialized">string representation of the <see cref="FinitePoint{TNumber}"/> struct</param>
7579
/// <exception cref="T:System.ArgumentNullException"><paramref name="serialized"/> is <see langword="null"/></exception>
80+
#if NET6_0_OR_GREATER
81+
public FinitePoint(ReadOnlySpan<char> serialized)
82+
#else
7683
public FinitePoint(string serialized)
84+
#endif
7785
{
86+
#if NET6_0_OR_GREATER
87+
if (serialized == null || serialized.IsEmpty)
88+
#else
7889
if (string.IsNullOrWhiteSpace(serialized))
90+
#endif
7991
{
8092
throw new ArgumentNullException(nameof(serialized));
8193
}
8294

83-
string[] s = serialized.Split('-');
95+
#if NET6_0_OR_GREATER
96+
var xReadOnlySpan = serialized[..serialized.IndexOf(SharedSeparator.CoordinateSeparator)];
97+
var yReadOnlySpan = serialized[(serialized.IndexOf(SharedSeparator.CoordinateSeparator) + 1)..];
98+
var numberType = typeof(TNumber);
99+
this.x = Calculator.Create(ToByteArray(xReadOnlySpan), numberType) as Calculator<TNumber>;
100+
this.y = Calculator.Create(ToByteArray(yReadOnlySpan), numberType) as Calculator<TNumber>;
101+
#else
102+
string[] s = serialized.Split(SharedSeparator.CoordinateSeparatorArray);
84103
var numberType = typeof(TNumber);
85104
this.x = Calculator.Create(ToByteArray(s[0]), numberType) as Calculator<TNumber>;
86105
this.y = Calculator.Create(ToByteArray(s[1]), numberType) as Calculator<TNumber>;
106+
#endif
87107
}
88108

89109
/// <summary>
@@ -95,6 +115,16 @@ public FinitePoint(string serialized)
95115
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "x")]
96116
public FinitePoint(Calculator<TNumber> x, Calculator<TNumber> y)
97117
{
118+
if (x == null)
119+
{
120+
throw new ArgumentNullException(nameof(x));
121+
}
122+
123+
if (y == null)
124+
{
125+
throw new ArgumentNullException(nameof(y));
126+
}
127+
98128
this.x = x;
99129
this.y = y;
100130
}
@@ -196,7 +226,7 @@ public override bool Equals(object obj)
196226
/// Returns the string representation of the <see cref="FinitePoint{TNumber}"/> structure.
197227
/// </summary>
198228
/// <returns></returns>
199-
public override string ToString() => string.Format(CultureInfo.InvariantCulture, "{0}-{1}", ToHexString(this.x.ByteRepresentation), ToHexString(this.y.ByteRepresentation));
229+
public override string ToString() => string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", ToHexString(this.x.ByteRepresentation), SharedSeparator.CoordinateSeparator.ToString(), ToHexString(this.y.ByteRepresentation));
200230

201231
/// <summary>
202232
/// Evaluates polynomial (coefficient tuple) at x, used to generate a shamir pool.
@@ -225,8 +255,14 @@ private static Calculator<TNumber> Evaluate(IEnumerable<Calculator<TNumber>> pol
225255
/// <remarks>
226256
/// Based on discussion on <see href="https://stackoverflow.com/questions/623104/byte-to-hex-string/5919521#5919521">stackoverflow</see>
227257
/// </remarks>
258+
#if NET6_0_OR_GREATER
259+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
260+
#endif
228261
private static string ToHexString(IEnumerable<byte> bytes)
229262
{
263+
#if NET6_0_OR_GREATER
264+
return Convert.ToHexString(bytes as byte[] ?? bytes.ToArray());
265+
#else
230266
byte[] byteArray = bytes as byte[] ?? bytes.ToArray();
231267
var hexRepresentation = new StringBuilder(byteArray.Length * 2);
232268
foreach (byte b in byteArray)
@@ -236,13 +272,18 @@ private static string ToHexString(IEnumerable<byte> bytes)
236272
}
237273

238274
return hexRepresentation.ToString();
275+
#endif
239276
}
240277

241278
/// <summary>
242279
/// Converts a hexadecimal string to a byte array.
243280
/// </summary>
244281
/// <param name="hexString">hexadecimal string</param>
245282
/// <returns>Returns a byte array</returns>
283+
#if NET6_0_OR_GREATER
284+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
285+
private static byte[] ToByteArray(ReadOnlySpan<char> hexString) => Convert.FromHexString(hexString);
286+
#else
246287
private static byte[] ToByteArray(string hexString)
247288
{
248289
byte[] bytes = new byte[hexString.Length / 2];
@@ -281,5 +322,6 @@ private static byte[] ToByteArray(string hexString)
281322

282323
return bytes;
283324
}
325+
#endif
284326
}
285327
}

src/Cryptography/Secret.cs

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class Secret
4747
/// Gets or sets the legacy mode on (<see langword="true"/>) or <see langword="off"/> to be compatible with
4848
/// v0.6.0 or older.
4949
/// </summary>
50+
[Obsolete("Legacy mode is deprecated and will be removed in the next versions.")]
5051
public static readonly ThreadLocal<bool> LegacyMode = new ThreadLocal<bool> {Value = false};
5152

5253
/// <summary>
@@ -118,6 +119,7 @@ internal static Secret<TNumber> CreateRandom<TNumber>(Calculator<TNumber> prime)
118119
/// <summary>
119120
/// Creates an array from a base64 string as in version 0.6.0 or older
120121
/// </summary>
122+
[Obsolete("Legacy mode is deprecated and will be removed in the next versions.")]
121123
protected static readonly Func<string, byte[]> FromBase64Legacy = base64 =>
122124
{
123125
var bytes = Convert.FromBase64String(base64).ToList();

src/Cryptography/SharedSeparator.cs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// ----------------------------------------------------------------------------
2+
// <copyright file="SharedSeparator.cs" company="Private">
3+
// Copyright (c) 2023 All Rights Reserved
4+
// </copyright>
5+
// <author>Sebastian Walther</author>
6+
// <date>05/27/2023 06:05:12 PM</date>
7+
// ----------------------------------------------------------------------------
8+
9+
#region License
10+
// ----------------------------------------------------------------------------
11+
// Copyright 2019 Sebastian Walther
12+
//
13+
// Permission is hereby granted, free of charge, to any person obtaining a copy
14+
// of this software and associated documentation files (the "Software"), to deal
15+
// in the Software without restriction, including without limitation the rights
16+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17+
// copies of the Software, and to permit persons to whom the Software is
18+
// furnished to do so, subject to the following conditions:
19+
//
20+
// The above copyright notice and this permission notice shall be included in
21+
// all copies or substantial portions of the Software.
22+
//
23+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29+
// THE SOFTWARE.
30+
#endregion
31+
32+
namespace SecretSharingDotNet.Cryptography
33+
{
34+
internal static class SharedSeparator
35+
{
36+
/// <summary>
37+
/// The separator between the X and Y coordinate
38+
/// </summary>
39+
internal const char CoordinateSeparator = '-';
40+
41+
/// <summary>
42+
/// Separator array for <see cref="string.Split(char[])"/> method usage to avoid allocation of a new array.
43+
/// </summary>
44+
internal static readonly char[] CoordinateSeparatorArray = { CoordinateSeparator };
45+
}
46+
47+
}

0 commit comments

Comments
 (0)