TheAlgorithms/C-Sharp · error · ArgumentException

Invalid parameter settings for Ascon Hash

Error message

Invalid parameter settings for Ascon Hash

What it means

AsconDigest's constructor only accepts the Ascon-Hash or Ascon-HashA parameter variants; anything else falls through the switch's discard arm and throws this ArgumentException. It means the caller supplied an AsconParameters value intended for a different primitive (e.g. an AEAD variant) to a hash-mode digest.

Solutions

  1. Pass only AsconParameters.AsconHash or AsconParameters.AsconHashA to AsconDigest
  2. Use the parameterless AsconDigest() constructor which defaults to the hash variant
  3. Check that the variant chosen by config/factory is actually a hash variant before constructing

Example fix

// before
var digest = new AsconDigest(AsconParameters.AsconAead128);
// after
var digest = new AsconDigest(AsconParameters.AsconHash);
Defensive patterns

Strategy: validation

Validate before calling

if (variant is not (AsconParameters.AsconHash or AsconParameters.AsconHashA))
    throw new ArgumentException($"{variant} is not a hash variant");
var digest = new AsconDigest(variant);

Type guard

static bool IsAsconHashVariant(AsconParameters p) =>
    p is AsconParameters.AsconHash or AsconParameters.AsconHashA;

Try / catch

try { digest = new AsconDigest(variant); }
catch (ArgumentException ex) { /* fallback to default hash variant */ digest = new AsconDigest(AsconParameters.AsconHash); }

Prevention

When it happens

Trigger: Calling new AsconDigest(AsconParameters.AsconAead) or any AsconParameters member other than AsconHash/AsconHashA; also when a factory/config maps an Ascon cipher variant onto the digest constructor.

Common situations: Config files or enum-driven factories that select an Ascon variant generically and pass AEAD variants (Ascon-Aead128 etc.) into the hash digest; typos or reordering of the enum between library versions.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of TheAlgorithms/C-Sharp@96e2905cab (2026-09-13). Data as JSON: /api/errors/14e2bd90ebf42c5e. Report an issue: GitHub.

Appendix: source

Thrown at Algorithms/Crypto/Digests/AsconDigest.cs:125

    /// <list type="bullet">
    /// <item><description>For <see cref="AsconParameters.AsconHash"/>, 12 permutation rounds are used.</description></item>
    /// <item><description>For <see cref="AsconParameters.AsconHashA"/>, 8 permutation rounds are used.</description></item>
    /// </list>
    /// If an unsupported parameter is provided, the constructor throws an <see cref="ArgumentException"/> to indicate that the parameter is invalid.
    /// The internal state of the digest is then reset to prepare for processing input data.
    /// </remarks>
    /// <exception cref="ArgumentException">Thrown when an invalid parameter setting is provided for Ascon Hash.</exception>
    public AsconDigest(AsconParameters parameters)
    {
        // Set the Ascon parameter (AsconHash or AsconHashA) for this instance.
        asconParameters = parameters;

        // Determine the number of permutation rounds based on the Ascon variant.
        asconPbRounds = parameters switch
        {
            AsconParameters.AsconHash => 12,  // 12 rounds for Ascon-Hash variant.
            AsconParameters.AsconHashA => 8,  // 8 rounds for Ascon-HashA variant.
            _ => throw new ArgumentException("Invalid parameter settings for Ascon Hash"), // Throw exception for invalid parameter.
        };

        // Reset the internal state to prepare for new input.
        Reset();
    }

    /// <summary>
    /// Gets the name of the cryptographic algorithm based on the selected Ascon parameter.
    /// </summary>
    /// <value>
    /// A string representing the name of the algorithm variant, either "Ascon-Hash" or "Ascon-HashA".
    /// </value>
    /// <remarks>
    /// This property determines the algorithm name based on the selected Ascon variant when the instance was initialized.
    /// It supports two variants:
    /// <list type="bullet">
    /// <item><description>"Ascon-Hash" for the <see cref="AsconParameters.AsconHash"/> variant.</description></item>
    /// <item><description>"Ascon-HashA" for the <see cref="AsconParameters.AsconHashA"/> variant.</description></item>

View on GitHub (pinned to 96e2905cab)