feat: Implement DefaultCryptoHmac for compliance-aware HMAC operations
- Added DefaultCryptoHmac class implementing ICryptoHmac interface. - Introduced purpose-based HMAC computation methods. - Implemented verification methods for HMACs with constant-time comparison. - Created HmacAlgorithms and HmacPurpose classes for well-known identifiers. - Added compliance profile support for HMAC algorithms. - Included asynchronous methods for HMAC computation from streams.
This commit is contained in:
55
src/__Libraries/StellaOps.Cryptography/HmacAlgorithms.cs
Normal file
55
src/__Libraries/StellaOps.Cryptography/HmacAlgorithms.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
namespace StellaOps.Cryptography;
|
||||
|
||||
/// <summary>
|
||||
/// Well-known HMAC algorithm identifiers used by compliance profiles.
|
||||
/// </summary>
|
||||
public static class HmacAlgorithms
|
||||
{
|
||||
/// <summary>
|
||||
/// HMAC using SHA-256 (FIPS 198-1, RFC 2104).
|
||||
/// Used by: world, fips, kcmvp, eidas profiles.
|
||||
/// </summary>
|
||||
public const string HmacSha256 = "HMAC-SHA256";
|
||||
|
||||
/// <summary>
|
||||
/// HMAC using SHA-384 (FIPS 198-1, RFC 2104).
|
||||
/// </summary>
|
||||
public const string HmacSha384 = "HMAC-SHA384";
|
||||
|
||||
/// <summary>
|
||||
/// HMAC using SHA-512 (FIPS 198-1, RFC 2104).
|
||||
/// </summary>
|
||||
public const string HmacSha512 = "HMAC-SHA512";
|
||||
|
||||
/// <summary>
|
||||
/// HMAC using GOST R 34.11-2012 Stribog 256-bit (RFC 6986).
|
||||
/// Used by: gost profile.
|
||||
/// </summary>
|
||||
public const string HmacGost3411 = "HMAC-GOST3411";
|
||||
|
||||
/// <summary>
|
||||
/// HMAC using SM3 (GB/T 32905-2016).
|
||||
/// Used by: sm profile.
|
||||
/// </summary>
|
||||
public const string HmacSm3 = "HMAC-SM3";
|
||||
|
||||
/// <summary>
|
||||
/// All known HMAC algorithms for validation.
|
||||
/// </summary>
|
||||
public static readonly IReadOnlyList<string> All = new[]
|
||||
{
|
||||
HmacSha256,
|
||||
HmacSha384,
|
||||
HmacSha512,
|
||||
HmacGost3411,
|
||||
HmacSm3
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Validates whether the given algorithm is a known HMAC algorithm.
|
||||
/// </summary>
|
||||
/// <param name="algorithmId">The algorithm identifier to validate.</param>
|
||||
/// <returns>True if the algorithm is known; otherwise, false.</returns>
|
||||
public static bool IsKnown(string? algorithmId)
|
||||
=> !string.IsNullOrWhiteSpace(algorithmId) && All.Contains(algorithmId);
|
||||
}
|
||||
Reference in New Issue
Block a user