Skip to content

Commit cd7d2a5

Browse files
committed
?
1 parent 9b39239 commit cd7d2a5

13 files changed

Lines changed: 122 additions & 108 deletions

Directory.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<Project>
22
<PropertyGroup>
3+
<TargetFrameworks>net9.0;net8.0;net6.0</TargetFrameworks>
4+
<LangVersion>latest</LangVersion>
35
<Authors>Impostor,Next-Fast</Authors>
46
<PackageLicenseExpression>MIT</PackageLicenseExpression>
57
<RepositoryUrl>https://github.com/Next-Fast/Impostor.Hazel</RepositoryUrl>
68
<RepositoryType>git</RepositoryType>
79
<VersionPrefix>1.0.1</VersionPrefix>
810
<VersionSuffix>dev</VersionSuffix>
11+
<PackageLicense>MIT</PackageLicense>
912
</PropertyGroup>
1013
</Project>

Impostor.Hazel.Tests/Impostor.Hazel.Tests.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
7-
86
<IsPackable>false</IsPackable>
97
</PropertyGroup>
108

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
76
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
87
<RootNamespace>Next.Hazel.Abstractions</RootNamespace>
98
<AssemblyName>Next.Hazel.Abstractions</AssemblyName>
109
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
10+
<PackageId>Next.Hazel.Abstractions</PackageId>
1111
</PropertyGroup>
1212

1313
</Project>

Next.Hazel/ByteSpanExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public static uint ReadLittleEndian32(this ByteSpan input, int offset = 0)
119119
/// <param name="requiredSize">Required size (bytes)</param>
120120
public static ByteSpan ReuseSpanIfPossible(this ByteSpan source, int requiredSize)
121121
{
122-
if (source.Length >= requiredSize) return source.Slice(0, requiredSize);
122+
if (source.Length >= requiredSize) return source[..requiredSize];
123123

124124
return new byte[requiredSize];
125125
}

Next.Hazel/Crypto/AesGcm.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Aes128Gcm(ByteSpan key)
4141

4242
// Allocate scratch space
4343
ByteSpan scratchSpace = new byte[96];
44-
hashSubkey_ = scratchSpace.Slice(0, 16);
44+
hashSubkey_ = scratchSpace[..16];
4545
blockJ_ = scratchSpace.Slice(16, 16);
4646
blockS_ = scratchSpace.Slice(32, 16);
4747
blockZ_ = scratchSpace.Slice(48, 16);
@@ -89,7 +89,7 @@ public void Seal(ByteSpan output, ByteSpan nonce, ByteSpan plaintext, ByteSpan a
8989

9090
// Generate and append the authentication tag
9191
var tagOffset = plaintext.Length;
92-
GenerateAuthenticationTag(output.Slice(tagOffset), output.Slice(0, tagOffset), associatedData);
92+
GenerateAuthenticationTag(output[tagOffset..], output[..tagOffset], associatedData);
9393
}
9494

9595
/// <summary>
@@ -126,8 +126,8 @@ public bool Open(ByteSpan output, ByteSpan nonce, ByteSpan ciphertext, ByteSpan
126126

127127
// Split ciphertext into actual ciphertext and authentication
128128
// tag components.
129-
var authenticationTag = ciphertext.Slice(ciphertext.Length - TagSize);
130-
ciphertext = ciphertext.Slice(0, ciphertext.Length - TagSize);
129+
var authenticationTag = ciphertext[^TagSize..];
130+
ciphertext = ciphertext[..^TagSize];
131131

132132
// Create the initial counter block
133133
nonce.CopyTo(blockJ_);
@@ -158,7 +158,7 @@ private void GenerateAuthenticationTag(ByteSpan output, ByteSpan ciphertext, Byt
158158
if (fullBlocks * 16 < associatedData.Length)
159159
{
160160
SetSpanToZeros(blockScratch_);
161-
associatedData.Slice(fullBlocks * 16).CopyTo(blockScratch_);
161+
associatedData[(fullBlocks * 16)..].CopyTo(blockScratch_);
162162
GHASH(blockS_, blockScratch_, 1);
163163
}
164164

@@ -168,7 +168,7 @@ private void GenerateAuthenticationTag(ByteSpan output, ByteSpan ciphertext, Byt
168168
if (fullBlocks * 16 < ciphertext.Length)
169169
{
170170
SetSpanToZeros(blockScratch_);
171-
ciphertext.Slice(fullBlocks * 16).CopyTo(blockScratch_);
171+
ciphertext[(fullBlocks * 16)..].CopyTo(blockScratch_);
172172
GHASH(blockS_, blockScratch_, 1);
173173
}
174174

@@ -205,7 +205,7 @@ private void GCTR(ByteSpan output, ByteSpan counterBlock, uint counter, ByteSpan
205205
++counter;
206206

207207
// CIPH[k](CB[i])
208-
encryptor_.EncryptBlock(counterBlock.Slice(0, 16), blockScratch_);
208+
encryptor_.EncryptBlock(counterBlock[..16], blockScratch_);
209209

210210
// Y[i] = X[i] xor CIPH[k](CB[i])
211211
for (var jj = 0; jj != 16 && writeIndex < data.Length; ++jj, ++writeIndex)

Next.Hazel/Crypto/Sha256Stream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void AddData(ByteSpan data)
5050
while (data.Length > 0)
5151
{
5252
var offset = hash.TransformBlock(data.GetUnderlyingArray(), data.Offset, data.Length, null, 0);
53-
data = data.Slice(offset);
53+
data = data[offset..];
5454
}
5555
}
5656

Next.Hazel/Dtls/AesGcmRecordProtection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Aes128GcmRecordProtection(ByteSpan masterSecret, ByteSpan serverRandom, B
2727
{
2828
ByteSpan combinedRandom = new byte[serverRandom.Length + clientRandom.Length];
2929
serverRandom.CopyTo(combinedRandom);
30-
clientRandom.CopyTo(combinedRandom.Slice(serverRandom.Length));
30+
clientRandom.CopyTo(combinedRandom[serverRandom.Length..]);
3131

3232
// Expand master_secret to encryption keys
3333
const int ExpandedSize = 0
@@ -42,7 +42,7 @@ public Aes128GcmRecordProtection(ByteSpan masterSecret, ByteSpan serverRandom, B
4242
ByteSpan expandedKey = new byte[ExpandedSize];
4343
PrfSha256.ExpandSecret(expandedKey, masterSecret, PrfLabel.KEY_EXPANSION, combinedRandom);
4444

45-
var clientWriteKey = expandedKey.Slice(0, Aes128Gcm.KeySize);
45+
var clientWriteKey = expandedKey[..Aes128Gcm.KeySize];
4646
var serverWriteKey = expandedKey.Slice(Aes128Gcm.KeySize, Aes128Gcm.KeySize);
4747
clientWriteIV = expandedKey.Slice(2 * Aes128Gcm.KeySize, ImplicitNonceSize);
4848
serverWriteIV = expandedKey.Slice(2 * Aes128Gcm.KeySize + ImplicitNonceSize, ImplicitNonceSize);

0 commit comments

Comments
 (0)