{"record":{"id":"469d29cb5fef8434","repo":"golang/go","slug":"unsupported-kem","errorCode":null,"errorMessage":"unsupported KEM","messagePattern":"unsupported KEM","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/hpke/kem.go","lineNumber":67,"sourceCode":"\t\treturn DHKEM(ecdh.P256()), nil\n\tcase 0x0011: // DHKEM(P-384, HKDF-SHA384)\n\t\treturn DHKEM(ecdh.P384()), nil\n\tcase 0x0012: // DHKEM(P-521, HKDF-SHA512)\n\t\treturn DHKEM(ecdh.P521()), nil\n\tcase 0x0020: // DHKEM(X25519, HKDF-SHA256)\n\t\treturn DHKEM(ecdh.X25519()), nil\n\tcase 0x0041: // ML-KEM-768\n\t\treturn MLKEM768(), nil\n\tcase 0x0042: // ML-KEM-1024\n\t\treturn MLKEM1024(), nil\n\tcase 0x647a: // MLKEM768-X25519\n\t\treturn MLKEM768X25519(), nil\n\tcase 0x0050: // MLKEM768-P256\n\t\treturn MLKEM768P256(), nil\n\tcase 0x0051: // MLKEM1024-P384\n\t\treturn MLKEM1024P384(), nil\n\tdefault:\n\t\treturn nil, errors.New(\"unsupported KEM\")\n\t}\n}\n\n// A PublicKey is an instantiation of a KEM (one of the three components of an\n// HPKE ciphersuite) with an encapsulation key (i.e. the public key).\n//\n// A PublicKey is usually obtained from a method of the corresponding [KEM] or\n// [PrivateKey], such as [KEM.NewPublicKey] or [PrivateKey.PublicKey].\ntype PublicKey interface {\n\t// KEM returns the instantiated KEM.\n\tKEM() KEM\n\n\t// Bytes returns the public key as the output of SerializePublicKey.\n\tBytes() []byte\n\n\tencap() (sharedSecret, enc []byte, err error)\n}\n","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/hpke/kem.go#L49-L85","documentation":"NewKEM maps a numeric KEM ID (IANA HPKE registry) to an implementation. Only specific IDs are recognised: 0x0010-0x0012 (DHKEM P-256/P-384/P-521), 0x0020 (DHKEM X25519), 0x0041/0x0042 (ML-KEM-768/1024), 0x647a (MLKEM768-X25519), 0x0050 (MLKEM768-P256), 0x0051 (MLKEM1024-P384). Any other value falls through to the error.","triggerScenarios":"Calling hpke.NewKEM(id) with an unregistered, mistyped, or unsupported KEM ID. Also hit by byte-order mistakes (e.g. passing 0x1000 instead of 0x0010).","commonSituations":"Hardcoding a KEM ID from memory and transposing digits; reading an ID off the wire that the local build doesn't support; using a future/draft KEM ID not yet implemented.","solutions":["Use a symbolic constructor (DHKEM, MLKEM768, MLKEM768X25519, etc.) instead of a raw numeric ID.","Cross-check the ID against RFC 9180 §36 and the IANA HPKE registry before passing it in.","Verify endianness: KEM IDs in HPKE are big-endian uint16."],"exampleFix":"// before\nkem, err := hpke.NewKEM(0x1000) // transposed -> \"unsupported KEM\"\n\n// after\nkem, err := hpke.NewKEM(0x0010) // DHKEM(P-256)\n// or, preferred:\nkem := hpke.DHKEM(ecdh.P256())","handlingStrategy":"validation","validationCode":"// Allowlist of supported KEM IDs for this build.\nvar supportedKEMs = map[uint16]string{\n    0x0010: \"DHKEM(P-256)\", 0x0011: \"DHKEM(P-384)\", 0x0012: \"DHKEM(P-521)\",\n    0x0020: \"DHKEM(X25519)\", 0x0041: \"ML-KEM-768\", 0x0042: \"ML-KEM-1024\",\n    0x647A: \"MLKEM768-X25519\", 0x0050: \"MLKEM768-P256\", 0x0051: \"MLKEM1024-P384\",\n}\nfunc kemFor(id uint16) (hpke.KEM, error) {\n    if _, ok := supportedKEMs[id]; !ok {\n        return nil, fmt.Errorf(\"KEM 0x%04x not supported by this build\", id)\n    }\n    return hpke.NewKEM(id)\n}","typeGuard":null,"tryCatchPattern":"kem, err := hpke.NewKEM(id)\nif err != nil {\n    if err.Error() == \"unsupported KEM\" {\n        return fmt.Errorf(\"unknown KEM id 0x%04x; check IANA HPKE registry\", id)\n    }\n    return err\n}","preventionTips":["Prefer symbolic constructors (DHKEM, MLKEM768X25519) over numeric IDs.","Cross-check every hardcoded ID against the IANA HPKE registry.","Store KEM IDs in typed constants to avoid digit transposition."],"tags":["hpke","kem","cryptography","validation","go"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}