{"record":{"id":"14e2bd90ebf42c5e","repo":"TheAlgorithms/C-Sharp","slug":"invalid-parameter-settings-for-ascon-hash","errorCode":null,"errorMessage":"Invalid parameter settings for Ascon Hash","messagePattern":"Invalid parameter settings for Ascon Hash","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Algorithms/Crypto/Digests/AsconDigest.cs","lineNumber":125,"sourceCode":"    /// <list type=\"bullet\">\n    /// <item><description>For <see cref=\"AsconParameters.AsconHash\"/>, 12 permutation rounds are used.</description></item>\n    /// <item><description>For <see cref=\"AsconParameters.AsconHashA\"/>, 8 permutation rounds are used.</description></item>\n    /// </list>\n    /// If an unsupported parameter is provided, the constructor throws an <see cref=\"ArgumentException\"/> to indicate that the parameter is invalid.\n    /// The internal state of the digest is then reset to prepare for processing input data.\n    /// </remarks>\n    /// <exception cref=\"ArgumentException\">Thrown when an invalid parameter setting is provided for Ascon Hash.</exception>\n    public AsconDigest(AsconParameters parameters)\n    {\n        // Set the Ascon parameter (AsconHash or AsconHashA) for this instance.\n        asconParameters = parameters;\n\n        // Determine the number of permutation rounds based on the Ascon variant.\n        asconPbRounds = parameters switch\n        {\n            AsconParameters.AsconHash => 12,  // 12 rounds for Ascon-Hash variant.\n            AsconParameters.AsconHashA => 8,  // 8 rounds for Ascon-HashA variant.\n            _ => throw new ArgumentException(\"Invalid parameter settings for Ascon Hash\"), // Throw exception for invalid parameter.\n        };\n\n        // Reset the internal state to prepare for new input.\n        Reset();\n    }\n\n    /// <summary>\n    /// Gets the name of the cryptographic algorithm based on the selected Ascon parameter.\n    /// </summary>\n    /// <value>\n    /// A string representing the name of the algorithm variant, either \"Ascon-Hash\" or \"Ascon-HashA\".\n    /// </value>\n    /// <remarks>\n    /// This property determines the algorithm name based on the selected Ascon variant when the instance was initialized.\n    /// It supports two variants:\n    /// <list type=\"bullet\">\n    /// <item><description>\"Ascon-Hash\" for the <see cref=\"AsconParameters.AsconHash\"/> variant.</description></item>\n    /// <item><description>\"Ascon-HashA\" for the <see cref=\"AsconParameters.AsconHashA\"/> variant.</description></item>","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Crypto/Digests/AsconDigest.cs#L107-L143","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass only AsconParameters.AsconHash or AsconParameters.AsconHashA to AsconDigest","Use the parameterless AsconDigest() constructor which defaults to the hash variant","Check that the variant chosen by config/factory is actually a hash variant before constructing"],"exampleFix":"// before\nvar digest = new AsconDigest(AsconParameters.AsconAead128);\n// after\nvar digest = new AsconDigest(AsconParameters.AsconHash);","handlingStrategy":"validation","validationCode":"if (variant is not (AsconParameters.AsconHash or AsconParameters.AsconHashA))\n    throw new ArgumentException($\"{variant} is not a hash variant\");\nvar digest = new AsconDigest(variant);","typeGuard":"static bool IsAsconHashVariant(AsconParameters p) =>\n    p is AsconParameters.AsconHash or AsconParameters.AsconHashA;","tryCatchPattern":"try { digest = new AsconDigest(variant); }\ncatch (ArgumentException ex) { /* fallback to default hash variant */ digest = new AsconDigest(AsconParameters.AsconHash); }","preventionTips":["Prefer the parameterless AsconDigest() constructor unless you specifically need HashA","Centralize variant selection in one factory that filters to hash variants","Never feed AEAD AsconParameters members into digest constructors"],"tags":["csharp","crypto","argument-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}