{"record":{"id":"2b1b3569a4a3a04e","repo":"golang/go","slug":"mldsa-invalid-parameters","errorCode":null,"errorMessage":"mldsa: invalid parameters","messagePattern":"mldsa: invalid parameters","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/mldsa/mldsa_fips140v1.26.go","lineNumber":24,"sourceCode":"\npackage mldsa\n\nimport (\n\t\"crypto\"\n\t\"crypto/internal/fips140/mldsa\"\n\t\"errors\"\n\t\"io\"\n)\n\n// PrivateKey is an in-memory ML-DSA private key. It implements [crypto.Signer]\n// and the informal extended [crypto.PrivateKey] interface.\n//\n// A PrivateKey is safe for concurrent use.\ntype PrivateKey struct {\n\tk mldsa.PrivateKey\n}\n\nvar errInvalidParameters = errors.New(\"mldsa: invalid parameters\")\n\n// GenerateKey generates a new random ML-DSA private key.\nfunc GenerateKey(params Parameters) (*PrivateKey, error) {\n\tswitch params {\n\tcase MLDSA44():\n\t\treturn &PrivateKey{k: *mldsa.GenerateKey44()}, nil\n\tcase MLDSA65():\n\t\treturn &PrivateKey{k: *mldsa.GenerateKey65()}, nil\n\tcase MLDSA87():\n\t\treturn &PrivateKey{k: *mldsa.GenerateKey87()}, nil\n\tdefault:\n\t\treturn nil, errInvalidParameters\n\t}\n}\n\n// NewPrivateKey decodes an ML-DSA private key from the given seed.\n//\n// The seed must be exactly [PrivateKeySize] bytes long.","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/mldsa/mldsa_fips140v1.26.go#L6-L42","documentation":"Returned by mldsa.GenerateKey (in the real, v1.26 implementation) when params does not match MLDSA44(), MLDSA65(), or MLDSA87(). The switch only handles the three NIST FIPS 204 parameter sets; the default branch returns errInvalidParameters. The Parameters type is comparable via switch, so a zero-value or hand-constructed Parameters falls through to default.","triggerScenarios":"Calling GenerateKey with the zero value of Parameters (params := mldsa.Parameters{}), with a Parameters value hand-constructed by filling struct fields instead of using a constructor, or with a value returned from a future/extra parameter set not yet supported.","commonSituations":"Declaring a Parameters variable and forgetting to initialize it; deserializing a Parameters from a config file whose value does not exactly equal one of the three predefined sets; passing a parameter set constant from a different ML-DSA package version.","solutions":["Always use the package-provided constructors: mldsa.MLDSA44(), mldsa.MLDSA65(), or mldsa.MLDSA87().","If reading the parameter set from config, map the string ('ML-DSA-44' etc.) to the constructor explicitly and reject unknown values.","Add a unit test that asserts every code path passes one of the three constants into GenerateKey.","Validate params before calling GenerateKey (see validationCode below)."],"exampleFix":"// before\nvar params mldsa.Parameters // zero value\n_, err := mldsa.GenerateKey(params) // -> errInvalidParameters\n// after\n_, err := mldsa.GenerateKey(mldsa.MLDSA65())","handlingStrategy":"validation","validationCode":"func validMLDSAParams(p mldsa.Parameters) bool {\n    switch p {\n    case mldsa.MLDSA44(), mldsa.MLDSA65(), mldsa.MLDSA87():\n        return true\n    }\n    return false\n}\nif !validMLDSAParams(params) {\n    return errors.New(\"params must be MLDSA44, MLDSA65, or MLDSA87\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a constructor result (MLDSA44/MLDSA65/MLDSA87) — never a zero-value or hand-built Parameters.","When reading the parameter set from config, map the string to a constructor explicitly.","Unit-test that every GenerateKey call site uses one of the three constants."],"tags":["crypto","mldsa","post-quantum","validation","go-stdlib"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}