### Install Kdf108 NuGet Package Source: https://github.com/mistial-dev/kdf108/blob/master/docs/README.md Instructions to install the Kdf108 library into a .NET project using the .NET CLI's `dotnet add package` command. This command adds the latest stable version of the Kdf108 package from NuGet to your project's dependencies. ```bash dotnet add package Kdf108 ``` -------------------------------- ### Derive Key using Counter Mode with Split Fixed Input Source: https://github.com/mistial-dev/kdf108/blob/master/docs/README.md Illustrates an advanced usage of `CounterModeKdf` where the fixed input is split into 'before' and 'after' parts, and the counter is inserted in the middle. This example utilizes CMAC-AES128 as the PRF and demonstrates the fluent `KdfOptionsBuilder` for configuration. The derived key is outputted as a hexadecimal string. ```csharp using Kdf108.Domain.Kdf.Modes; using Kdf108.Domain.Kdf; byte[] key = Convert.FromHexString("DFF1E50AC0B69DC40F1051D46C2B069C"); byte[] before = Convert.FromHexString("0011223344"); byte[] after = Convert.FromHexString("AABBCCDDEE"); var opts = KdfOptions.CreateBuilder() .WithPrfType(PrfType.CmacAes128) .WithCounterLengthBits(8) .WithUseCounter(true) .WithCounterLocation(CounterLocation.MiddleFixed) .Build(); byte[] result = new CounterModeKdf() .DeriveWithSplitFixedInput(key, before, after, 128, opts); Console.WriteLine(Convert.ToHexString(result)); ``` -------------------------------- ### Derive Key using NIST SP 800-108 Feedback Mode KDF Source: https://github.com/mistial-dev/kdf108/blob/master/docs/README.md This example showcases key derivation using the `FeedbackModeKdf`, another mode specified in NIST SP 800-108. It configures HMAC-SHA256 as the PRF, uses an 8-bit counter located before the fixed input, and sets options specifically for feedback mode with a null initialization vector (IV). The resulting derived key is displayed. ```csharp using Kdf108.Domain.Kdf.Modes; using Kdf108.Domain.Kdf; var fbOptions = KdfOptions.CreateBuilder() .WithPrfType(PrfType.HmacSha256) .WithCounterLengthBits(8) .WithUseCounter(true) .WithCounterLocation(CounterLocation.BeforeFixed) .ForFeedbackMode(iv: null) .Build(); byte[] fbKey = new FeedbackModeKdf() .DeriveWithFixedInput(kdk, fixedInput, null, 256, fbOptions); Console.WriteLine(Convert.ToHexString(fbKey)); ``` -------------------------------- ### Derive Key using NIST SP 800-108 Counter Mode KDF Source: https://github.com/mistial-dev/kdf108/blob/master/docs/README.md This example demonstrates how to use the `CounterModeKdf` to derive a key according to NIST SP 800-108 Counter Mode. It configures HMAC-SHA256 as the Pseudo-Random Function (PRF), sets the counter length, and specifies the counter's location before the fixed input. The derived key is then printed in hexadecimal format. ```csharp using Kdf108.Domain.Kdf.Modes; using Kdf108.Domain.Kdf; // Key Derivation Key (KDK) byte[] kdk = Convert.FromHexString("4E6F77206973207468"); // Fixed input (Label || Context) byte[] fixedInput = System.Text.Encoding.ASCII.GetBytes("LabelAndContext"); long outputBits = 256; var options = new KdfOptions { PrfType = PrfType.HmacSha256, CounterLengthBits = 32, UseCounter = true, CounterLocation = CounterLocation.BeforeFixed, MaxBitsAllowed = outputBits }; var kdf = new CounterModeKdf(); byte[] derived = kdf.DeriveWithFixedInput(kdk, fixedInput, outputBits, options); Console.WriteLine(Convert.ToHexString(derived)); ``` -------------------------------- ### Run Kdf108 Unit and Integration Tests Source: https://github.com/mistial-dev/kdf108/blob/master/docs/README.md Command to execute the full test suite for the Kdf108 library. These tests include unit tests and validation against NIST SP 800-108 Response Specification (RSP) test vectors, ensuring compliance and correctness of the KDF implementation. ```bash dotnet test ``` -------------------------------- ### Reference Kdf108 Project Directly Source: https://github.com/mistial-dev/kdf108/blob/master/docs/README.md Demonstrates how to include the Kdf108 library in a .NET project by directly referencing its `.csproj` file. This method is typically used during development within a multi-project solution or for local builds, allowing direct access to the source. ```xml ``` -------------------------------- ### Derive Key using NIST SP 800-108 Double-Pipeline Mode KDF Source: https://github.com/mistial-dev/kdf108/blob/master/docs/README.md This snippet demonstrates key derivation using the `DoublePipelineKdf` mode, a specific implementation of NIST SP 800-108. It configures HMAC-SHA256 as the PRF, sets a 16-bit counter, and specifies the counter's location before the fixed input, tailored for double-pipeline operation. The derived key is then printed. ```csharp using Kdf108.Domain.Kdf.Modes; using Kdf108.Domain.Kdf; byte[] context = Convert.FromHexString("CAFEBABE"); var dpOptions = KdfOptions.CreateBuilder() .WithPrfType(PrfType.HmacSha256) .WithCounterLengthBits(16) .WithUseCounter(true) .WithCounterLocation(CounterLocation.BeforeFixed) .ForDoublePipelineMode() .Build(); byte[] dpKey = new DoublePipelineKdf(useCounter: true) .DeriveKey(kdk, "label", context, 512, dpOptions); Console.WriteLine(Convert.ToHexString(dpKey)); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.