{"record":{"id":"0b7dd6bc339f8b39","repo":"golang/go","slug":"crypto-dsa-invalid-parametersizes","errorCode":null,"errorMessage":"crypto/dsa: invalid ParameterSizes","messagePattern":"crypto/dsa: invalid ParameterSizes","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/dsa/dsa.go","lineNumber":91,"sourceCode":"\t// seed doesn't appear to be exported or used by other code and\n\t// omitting it makes the code cleaner.\n\n\tvar L, N int\n\tswitch sizes {\n\tcase L1024N160:\n\t\tL = 1024\n\t\tN = 160\n\tcase L2048N224:\n\t\tL = 2048\n\t\tN = 224\n\tcase L2048N256:\n\t\tL = 2048\n\t\tN = 256\n\tcase L3072N256:\n\t\tL = 3072\n\t\tN = 256\n\tdefault:\n\t\treturn errors.New(\"crypto/dsa: invalid ParameterSizes\")\n\t}\n\n\tqBytes := make([]byte, N/8)\n\tpBytes := make([]byte, L/8)\n\n\tq := new(big.Int)\n\tp := new(big.Int)\n\trem := new(big.Int)\n\tone := new(big.Int)\n\tone.SetInt64(1)\n\nGeneratePrimes:\n\tfor {\n\t\tif _, err := io.ReadFull(rand, qBytes); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tqBytes[len(qBytes)-1] |= 1","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/dsa/dsa.go#L73-L109","documentation":"GenerateParameters accepts only four enumerated ParameterSizes values (L1024N160, L2048N224, L2048N256, L3072N256) corresponding to FIPS 186-3 Table 4.2 prime sizes. Any other value falls through the switch to the default branch, returning this error.","triggerScenarios":"Calling dsa.GenerateParameters with a ParameterSizes value outside the four defined constants, e.g. an untyped integer cast or a zero value (0, which is not a valid constant).","commonSituations":"Passing 0 because the ParameterSizes field was not initialized; casting an arbitrary int; using a value computed from input without validation.","solutions":["Use one of the four named constants: dsa.L1024N160, dsa.L2048N224, dsa.L2048N256, or dsa.L3072N256.","Validate a caller-supplied size against the known constants before calling GenerateParameters.","Default to L2048N256 (a common modern choice) when none is specified."],"exampleFix":"// before\ndsa.GenerateParameters(&params, rand.Reader, ParameterSizes(0))\n// after\ndsa.GenerateParameters(&params, rand.Reader, dsa.L2048N256)","handlingStrategy":"validation","validationCode":"var validSizes = map[dsa.ParameterSizes]bool{\n    dsa.L1024N160: true, dsa.L2048N224: true,\n    dsa.L2048N256: true, dsa.L3072N256: true,\n}\nfunc genDSAParams(params *dsa.Parameters, rand io.Reader, sizes dsa.ParameterSizes) error {\n    if !validSizes[sizes] {\n        return fmt.Errorf(\"unsupported DSA ParameterSizes: %d\", sizes)\n    }\n    return dsa.GenerateParameters(params, rand, sizes)\n}","typeGuard":"func isValidDSASize(s dsa.ParameterSizes) bool {\n    switch s {\n    case dsa.L1024N160, dsa.L2048N224, dsa.L2048N256, dsa.L3072N256:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Never cast arbitrary ints to ParameterSizes; use the named constants only.","Default to L2048N256 when callers omit a size.","Add a unit test asserting every accepted size value."],"tags":["crypto","dsa","validation","go"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}