MultiMAC 1.0.2

.NET 6.0
Install-Package MultiMAC -Version 1.0.2
dotnet add package MultiMAC --version 1.0.2
<PackageReference Include="MultiMAC" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MultiMAC --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MultiMAC, 1.0.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install MultiMAC as a Cake Addin
#addin nuget:?package=MultiMAC&version=1.0.2

// Install MultiMAC as a Cake Tool
#tool nuget:?package=MultiMAC&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

License: MIT

MultiMAC

Authenticate multiple inputs easily using keyed BLAKE2b in libsodium.

Justification

The standard way of safely computing a MAC for multiple inputs requires worrying about concatenating arrays and converting the length of each array to a fixed number of bytes, such as 4 bytes to represent an integer, consistently in either big- or little-endian, regardless of the endianness of the machine. This is annoying to implement and possibly less efficient than the following approach discussed by Neil Madden, author of API Security in Action.

Installation

NuGet

You can find the NuGet package here.

The easiest way to install this is via the NuGet Package Manager in Visual Studio, as explained here. JetBrains Rider also has a package manager, and instructions can be found here.

Manual

  1. Install the Sodium.Core NuGet package in Visual Studio.
  2. Download the latest release.
  3. Move the downloaded .dll file into your Visual Studio project folder.
  4. Click on the Project tab and Add Project Reference... in Visual Studio.
  5. Go to Browse, click the Browse button, and select the downloaded .dll file.
  6. Add using MultiMAC; to the top of each code file that will use the library.

Requirements

Note that the libsodium library requires the Visual C++ Redistributable for Visual Studio 2015-2019 to work on Windows. If you want your program to be portable, then you must keep the relevant (x86 or x64) vcruntime140.dll file in the same folder as your executable on Windows.

Usage

⚠️WARNING: Never use the same key for key1 and key2.

const TagLength tagLength = TagLength.BLAKE2b256;

// Both keys should be derived using a KDF in practice (e.g. Argon2, HKDF, etc)
byte[] key1 = SodiumCore.GetRandomBytes((int)tagLength);

// The keys must be the same size as the tag length
byte[] key2 = SodiumCore.GetRandomBytes((int)tagLength);

// Gather up the byte arrays to authenticate
byte[] input1 = Encoding.UTF8.GetBytes("Po");

byte[] input2 = Encoding.UTF8.GetBytes("ta");

byte[] input3 = Encoding.UTF8.GetBytes("toes");

byte[] input4 = Encoding.UTF8.GetBytes("Boil 'em, mash 'em, stick 'em in a stew");

// Compute a 256-bit tag
byte[] tag = MultiMac.Compute(key1, key2, tagLength, input1, input2, input3, input4);

// Verify a tag
bool validTag = MultiMac.Verify(tag, key1, key2, input1, input2, input3, input4);
Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 81 1/18/2022