Skip to content

Commit 93e68b0

Browse files
committed
Update to Monocypher 4.0.2
1 parent 380711a commit 93e68b0

File tree

22 files changed

+1073
-3803
lines changed

22 files changed

+1073
-3803
lines changed

.github/workflows/managed.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ jobs:
1414

1515
steps:
1616
- name: Checkout
17-
uses: actions/checkout@v2
17+
uses: actions/checkout@v3
1818
with:
1919
submodules: true
2020
fetch-depth: 0
2121

22-
- name: Install .NET 6.0
23-
uses: actions/setup-dotnet@v1
22+
- name: Install .NET 8.0
23+
uses: actions/setup-dotnet@v4
2424
with:
25-
dotnet-version: '6.0.x'
25+
dotnet-version: '8.0.x'
2626

2727
- name: Build, Test, Pack, Publish
2828
shell: bash

.github/workflows/native.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
runs-on: ${{ matrix.os }}
2121
steps:
2222
- name: Checkout
23-
uses: actions/checkout@v1
23+
uses: actions/checkout@v3
2424
with:
2525
submodules: recursive
2626
- name: Setup Linux

ext/Monocypher

Submodule Monocypher updated 207 files

license.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2021, Alexandre Mutel
1+
Copyright (c) 2021-2024, Alexandre Mutel
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without modification
@@ -25,7 +25,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525
> Monocypher.NET is a simple managed wrapper around https://github.com/LoupVaillant/Monocypher
2626
> which comes with the following license:
2727

28-
Copyright (c) 2017-2020, Loup Vaillant
28+
Copyright (c) 2017-2024, Loup Vaillant
2929
Copyright (c) 2017-2019, Michael Savage
3030
Copyright (c) 2017-2020, Fabio Scotoni
3131
All rights reserved.

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Monocypher.NET is a managed wrapper around [Monocypher](https://github.com/LoupVaillant/Monocypher) cryptographic library.
66

7-
> The current _native_ version of Monocypher used by Monocypher.NET is `3.1.2`
7+
> The current _native_ version of Monocypher used by Monocypher.NET is `4.0.2`
88
## Features
99

1010
- Provides the entire native Monocypher API in an efficient 1-to-1 mapping:
@@ -46,7 +46,7 @@ RNGCryptoServiceProvider.Fill(key);
4646
Span<byte> nonce = stackalloc byte[24];
4747
RNGCryptoServiceProvider.Fill(nonce);
4848

49-
crypto_lock(mac, cipherText, key, nonce, inputText);
49+
crypto_aead_lock(cipherText, mac, key, nonce, ReadOnlySpan<byte>.Empty, inputText);
5050

5151
// mac contains the authenticated code
5252
// cipherText contains the encrypted message
@@ -92,7 +92,7 @@ That being said, if you are building an IoT project using the C Monocypher and y
9292

9393
## How to Build?
9494

95-
You need to install the [.NET 6 SDK](https://dotnet.microsoft.com/download/dotnet/6.0). Then from the root folder:
95+
You need to install the [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0). Then from the root folder:
9696

9797
```console
9898
$ dotnet build src -c Release

src/Monocypher.CodeGen/Monocypher.CodeGen.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<!-- Workaround for issue https://github.com/microsoft/ClangSharp/issues/129 -->
77
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == '' AND '$(PackAsTool)' != 'true'">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
88
<IsPackable>false</IsPackable>
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="HtmlAgilityPack" Version="1.11.42" />
13-
<PackageReference Include="CppAst.CodeGen" Version="0.8.2" />
12+
<PackageReference Include="HtmlAgilityPack" Version="1.11.58" />
13+
<PackageReference Include="CppAst.CodeGen" Version="0.11.3" />
1414
</ItemGroup>
1515

1616
</Project>

src/Monocypher.CodeGen/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public void GeneratePInvoke()
6767
{
6868
e => e.Map<CppField>("crypto_blake2b_vtable").Discard(),
6969
e => e.Map<CppField>("crypto_sha512_vtable").Discard(),
70+
e => e.Map<CppField>("crypto_argon2_no_extras").Discard(),
7071
}
7172
};
7273
csOptions.Plugins.Insert(0, new FixedArrayTypeConverter());

src/Monocypher.Tests/Monocypher.Tests.csproj

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

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<IsPackable>false</IsPackable>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == '' AND '$(PackAsTool)' != 'true'">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="NUnit" Version="3.13.3" />
12-
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
11+
<PackageReference Include="NUnit" Version="4.0.1" />
12+
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
1414
<Content Include="..\Monocypher\runtimes\$(RuntimeIdentifier)\native\*.*">
1515
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1616
</Content>
17+
<Using Include="NUnit.Framework" />
18+
<Using Include="NUnit.Framework.Legacy.ClassicAssert" Alias="Assert" />
19+
<Using Include="NUnit.Framework.Legacy.CollectionAssert" Alias="CollectionAssert" />
20+
<Using Include="NUnit.Framework.Legacy.StringAssert" Alias="StringAssert" />
21+
<Using Include="NUnit.Framework.Legacy.DirectoryAssert" Alias="DirectoryAssert" />
22+
<Using Include="NUnit.Framework.Legacy.FileAssert" Alias="FileAssert" />
1723
</ItemGroup>
1824

1925
<ItemGroup>

src/Monocypher.Tests/Tests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Security.Cryptography;
34
using System.Text;
45
using NUnit.Framework;
@@ -13,24 +14,23 @@ public class Tests
1314
public void SimpleBlake2Init()
1415
{
1516
crypto_blake2b_ctx ctx = default;
16-
crypto_blake2b_init(ref ctx);
17+
crypto_blake2b_init(ref ctx, 256);
1718
Assert.AreNotEqual(0, (int)ctx.hash_size.Value, "Invalid hash_size returned from blake2b_init");
1819
}
1920

2021
[Test]
2122
public void TestChaCha20()
2223
{
23-
Span<byte> ciptherText = stackalloc byte[64];
24+
Span<byte> ciptherText = stackalloc byte[32];
2425
Span<byte> key = new byte[32]
2526
{
2627
0xee, 0xc7, 0xb5, 0x3d, 0x05, 0xd9, 0xcc, 0x81, 0x61, 0x84, 0xc4, 0x9f, 0x65, 0x2f, 0x37, 0x04, 0x70, 0xa4, 0x52, 0x22, 0xa5, 0xc7, 0x4d, 0xa4, 0x2e, 0x7f, 0x09, 0xd6, 0x86, 0x2d, 0x6d, 0xd0,
2728
};
28-
crypto_chacha20(ciptherText, key, new Byte8().AsReadOnlySpan());
29-
30-
Span<byte> expected = new byte[64]
29+
crypto_chacha20_h(ciptherText, key, new Byte16().AsReadOnlySpan());
30+
31+
Span<byte> expected = new byte[32]
3132
{
32-
0x5a, 0x3c, 0x5c, 0xd2, 0x20, 0x8b, 0x75, 0x91, 0x66, 0xbd, 0x25, 0xa8, 0x45, 0xc8, 0xf3, 0xf8, 0x24, 0xe0, 0xdb, 0x9c, 0xfa, 0x1f, 0xb0, 0x14, 0x7d, 0x90, 0xbc, 0xf4, 0xaf, 0x8c, 0xd3, 0x79, 0xf0, 0xbf, 0x31, 0x2b, 0x04,
33-
0xd2, 0xa1, 0xbd, 0x48, 0xd3, 0x50, 0x17, 0xc7, 0x1f, 0x29, 0x52, 0x83, 0x71, 0xba, 0x8c, 0x95, 0xe5, 0xa4, 0x0c, 0x33, 0x59, 0x01, 0x20, 0x65, 0x8c, 0x15, 0x5a
33+
0xf5, 0xc3, 0xeb, 0x70, 0xb2, 0x26, 0x55, 0x5e, 0x34, 0x90, 0xc3, 0x2e, 0xd1, 0x62, 0xd3, 0x8d, 0x83, 0x71, 0xba, 0x8c, 0x95, 0xe5, 0xa4, 0x0c, 0x33, 0x59, 0x01, 0x20, 0x65, 0x8c, 0x15, 0x5a
3434
};
3535

3636
Console.WriteLine(ciptherText.ToHexBytes());
@@ -54,7 +54,7 @@ public void CryptoLockUnlock()
5454
Span<byte> nonce = stackalloc byte[24];
5555
RandomNumberGenerator.Fill(nonce);
5656

57-
crypto_lock(mac, cipherText, key, nonce, inputText);
57+
crypto_aead_lock(cipherText, mac, key, nonce, ReadOnlySpan<byte>.Empty, inputText);
5858

5959
var builder = new StringBuilder();
6060

@@ -69,7 +69,7 @@ public void CryptoLockUnlock()
6969

7070
// Verify that we get the same output from unlock
7171
Span<byte> outputText = stackalloc byte[16];
72-
crypto_unlock(outputText, key, nonce, mac, cipherText);
72+
crypto_aead_unlock(outputText, mac, key, nonce, ReadOnlySpan<byte>.Empty, cipherText);
7373

7474
Assert.True(outputText.SequenceEqual(inputText), "crypto_unlock failed. Spans are different");
7575
}

src/Monocypher/Monocypher.cs

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -508,133 +508,6 @@ public override string ToString()
508508
}
509509
}
510510

511-
/// <summary>
512-
///
513-
/// These functions provide an interface for the Chacha20 encryption primitive.
514-
/// <br/>
515-
///
516-
/// Chacha20 is a low-level primitive. Consider using authenticated encryption,
517-
/// implemented by <see cref="crypto_lock"/>.
518-
/// <br/>
519-
///
520-
/// This overrides considers plain_text input as if it was composed of all of input zero.
521-
///
522-
/// </summary>
523-
/// <param name="key">A 32-byte secret key.</param>
524-
/// <param name="nonce">A 8-byte buffer. An 8-byte or 24-byte number, used only once with any given key. It does
525-
/// not need to be secret or random, but it does have to be unique. Repeating
526-
/// a nonce with the same key reveals the XOR of two different messages, which
527-
/// allows decryption. 24-byte nonces can be selected at random. 8-byte nonces
528-
/// cannot. They are too small, and the same
529-
/// nonce may be selected twice by accident. See
530-
/// intro(3monocypher) for advice about
531-
/// generating random numbers (use the operating system's random number
532-
/// generator).</param>
533-
/// <param name="cipher_text">The encrypted message.</param>
534-
public static unsafe void crypto_chacha20(Span<byte> cipher_text, ReadOnlySpan<byte> key, ReadOnlySpan<byte> nonce)
535-
{
536-
ExpectSize32(nameof(key), key.Length);
537-
ExpectSize8(nameof(nonce), nonce.Length);
538-
fixed (void* cipher_text_ptr = cipher_text)
539-
crypto_chacha20(new IntPtr(cipher_text_ptr), IntPtr.Zero, (Monocypher.size_t)cipher_text.Length, in key.AsByte32(), in nonce.AsByte8());
540-
}
541-
542-
543-
/// <summary>
544-
///
545-
/// These functions provide an interface for the Chacha20 encryption primitive.
546-
/// <br/>
547-
///
548-
/// Chacha20 is a low-level primitive. Consider using authenticated encryption,
549-
/// implemented by <see cref="crypto_lock"/>.
550-
/// <br/>
551-
///
552-
/// This overrides considers plain_text input as if it was composed of all of input zero.
553-
///
554-
/// </summary>
555-
/// <param name="key">A 32-byte secret key.</param>
556-
/// <param name="nonce">A 24-byte buffer. An 8-byte or 24-byte number, used only once with any given key. It does
557-
/// not need to be secret or random, but it does have to be unique. Repeating
558-
/// a nonce with the same key reveals the XOR of two different messages, which
559-
/// allows decryption. 24-byte nonces can be selected at random. 8-byte nonces
560-
/// cannot. They are too small, and the same
561-
/// nonce may be selected twice by accident. See
562-
/// intro(3monocypher) for advice about
563-
/// generating random numbers (use the operating system's random number
564-
/// generator).</param>
565-
/// <param name="cipher_text">The encrypted message.</param>
566-
public static unsafe void crypto_xchacha20(Span<byte> cipher_text, ReadOnlySpan<byte> key, ReadOnlySpan<byte> nonce)
567-
{
568-
ExpectSize32(nameof(key), key.Length);
569-
ExpectSize24(nameof(nonce), nonce.Length);
570-
fixed (void* cipher_text_ptr = cipher_text)
571-
crypto_xchacha20(new IntPtr(cipher_text_ptr), IntPtr.Zero, (Monocypher.size_t)cipher_text.Length, in key.AsByte32(), in nonce.AsByte24());
572-
}
573-
574-
/// <summary>
575-
///
576-
/// These functions provide an interface for the Chacha20 encryption primitive.
577-
/// <br/>
578-
///
579-
/// Chacha20 is a low-level primitive. Consider using authenticated encryption,
580-
/// implemented by <see cref="crypto_lock"/>.
581-
/// <br/>
582-
///
583-
/// This overrides considers plain_text input as if it was composed of all of input zero.
584-
///
585-
/// </summary>
586-
/// <param name="key">A 32-byte secret key.</param>
587-
/// <param name="nonce">A 8-byte buffer. An 8-byte or 24-byte number, used only once with any given key. It does
588-
/// not need to be secret or random, but it does have to be unique. Repeating
589-
/// a nonce with the same key reveals the XOR of two different messages, which
590-
/// allows decryption. 24-byte nonces can be selected at random. 8-byte nonces
591-
/// cannot. They are too small, and the same
592-
/// nonce may be selected twice by accident. See
593-
/// intro(3monocypher) for advice about
594-
/// generating random numbers (use the operating system's random number
595-
/// generator).</param>
596-
/// <param name="cipher_text">The encrypted message.</param>
597-
/// <param name="ctr">The number of 64-byte blocks since the beginning of the stream.</param>
598-
public static unsafe ulong crypto_chacha20_ctr(Span<byte> cipher_text, ReadOnlySpan<byte> key, ReadOnlySpan<byte> nonce, ulong ctr)
599-
{
600-
ExpectSize32(nameof(key), key.Length);
601-
ExpectSize8(nameof(nonce), nonce.Length);
602-
fixed (void* cipher_text_ptr = cipher_text)
603-
return crypto_chacha20_ctr(new IntPtr(cipher_text_ptr), IntPtr.Zero, (Monocypher.size_t)cipher_text.Length, in key.AsByte32(), in nonce.AsByte8(), ctr);
604-
}
605-
606-
/// <summary>
607-
///
608-
/// These functions provide an interface for the Chacha20 encryption primitive.
609-
/// <br/>
610-
///
611-
/// Chacha20 is a low-level primitive. Consider using authenticated encryption,
612-
/// implemented by <see cref="crypto_lock"/>.
613-
/// <br/>
614-
///
615-
/// This overrides considers plain_text input as if it was composed of all of input zero.
616-
///
617-
/// </summary>
618-
/// <param name="key">A 32-byte secret key.</param>
619-
/// <param name="nonce">A 24-byte buffer. An 8-byte or 24-byte number, used only once with any given key. It does
620-
/// not need to be secret or random, but it does have to be unique. Repeating
621-
/// a nonce with the same key reveals the XOR of two different messages, which
622-
/// allows decryption. 24-byte nonces can be selected at random. 8-byte nonces
623-
/// cannot. They are too small, and the same
624-
/// nonce may be selected twice by accident. See
625-
/// intro(3monocypher) for advice about
626-
/// generating random numbers (use the operating system's random number
627-
/// generator).</param>
628-
/// <param name="cipher_text">The encrypted message.</param>
629-
/// <param name="ctr">The number of 64-byte blocks since the beginning of the stream.</param>
630-
public static unsafe ulong crypto_xchacha20_ctr(Span<byte> cipher_text, ReadOnlySpan<byte> key, ReadOnlySpan<byte> nonce, ulong ctr)
631-
{
632-
ExpectSize32(nameof(key), key.Length);
633-
ExpectSize24(nameof(nonce), nonce.Length);
634-
fixed (void* cipher_text_ptr = cipher_text)
635-
return crypto_xchacha20_ctr(new IntPtr(cipher_text_ptr), IntPtr.Zero, (Monocypher.size_t)cipher_text.Length, in key.AsByte32(), in nonce.AsByte24(), ctr);
636-
}
637-
638511
[MethodImpl(MethodImplOptions.AggressiveInlining)]
639512
private static char ByteHighToHex(byte value) => HexBytes[(value >> 4) & 0x0F];
640513
[MethodImpl(MethodImplOptions.AggressiveInlining)]

src/Monocypher/Monocypher.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
<ItemGroup>
2727
<None Include="../../img/monocypher_dotnet.png" Pack="true" PackagePath="" />
28-
<None Include="../../readme.md" Pack="true" PackagePath="/"/>
28+
<None Include="../../readme.md" Pack="true" PackagePath="/" />
2929
</ItemGroup>
3030

3131
<ItemGroup>
@@ -36,18 +36,18 @@
3636
</ItemGroup>
3737

3838
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
39-
<PackageReference Include="System.Memory" Version="4.5.4" />
40-
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
39+
<PackageReference Include="System.Memory" Version="4.5.5" />
40+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
4141
</ItemGroup>
4242

4343
<ItemGroup>
44-
<PackageReference Include="MinVer" Version="3.1.0">
44+
<PackageReference Include="MinVer" Version="4.3.0">
4545
<PrivateAssets>all</PrivateAssets>
4646
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4747
</PackageReference>
4848

4949
<!--Add support for sourcelink-->
50-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
50+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
5151
</ItemGroup>
5252

5353
<Target Name="PatchVersion" AfterTargets="MinVer">

0 commit comments

Comments
 (0)