{"record":{"id":"e6f7aed966d8c0ea","repo":"golang/go","slug":"p-point-is-the-point-at-infinity","errorCode":null,"errorMessage":"{{.P}} point is the point at infinity","messagePattern":"(.+?)\\} point is the point at infinity","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/internal/fips140/nistec/generate.go","lineNumber":312,"sourceCode":"\n\tbuf := append(out[:0], 4)\n\tbuf = append(buf, x.Bytes()...)\n\tbuf = append(buf, y.Bytes()...)\n\treturn buf\n}\n\n// BytesX returns the encoding of the x-coordinate of p, as specified in SEC 1,\n// Version 2.0, Section 2.3.5, or an error if p is the point at infinity.\nfunc (p *{{.P}}Point) BytesX() ([]byte, error) {\n\t// This function is outlined to make the allocations inline in the caller\n\t// rather than happen on the heap.\n\tvar out [{{.p}}ElementLength]byte\n\treturn p.bytesX(&out)\n}\n\nfunc (p *{{.P}}Point) bytesX(out *[{{.p}}ElementLength]byte) ([]byte, error) {\n\tif p.z.IsZero() == 1 {\n\t\treturn nil, errors.New(\"{{.P}} point is the point at infinity\")\n\t}\n\n\tzinv := new({{.Element}}).Invert(p.z)\n\tx := new({{.Element}}).Mul(p.x, zinv)\n\n\treturn append(out[:0], x.Bytes()...), nil\n}\n\n// BytesCompressed returns the compressed or infinity encoding of p, as\n// specified in SEC 1, Version 2.0, Section 2.3.3. Note that the encoding of the\n// point at infinity is shorter than all other encodings.\nfunc (p *{{.P}}Point) BytesCompressed() []byte {\n\t// This function is outlined to make the allocations inline in the caller\n\t// rather than happen on the heap.\n\tvar out [1 + {{.p}}ElementLength]byte\n\treturn p.bytesCompressed(&out)\n}\n","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/internal/fips140/nistec/generate.go#L294-L330","documentation":"Generated from generate.go:312. Thrown by BytesX when the point is the identity (z == 0), because the point at infinity has no affine x-coordinate to encode. Distinct from Bytes() which has a defined infinity encoding.","triggerScenarios":"Calling BytesX after a scalar multiplication that produced the identity (e.g. multiplying a point by its order), on a freshly zero-initialized point that was never set, or on the additive identity result of P + (-P).","commonSituations":"ECDSA/ECIES path that assumes a non-identity result, ECDH where the peer sent the identity point (invalid-curve/small-subgroup attack), or uninitialized point defaults.","solutions":["Check the point is not the identity before calling BytesX (e.g. via Bytes() length or an IsInfinity helper).","In ECDH, reject the peer's identity point explicitly to avoid leaking the shared secret computation.","Guard scalar-multiplication results: if the identity is an unexpected outcome, return an error before serializing.","Initialize points via SetBytes / New* rather than leaving the zero value when an affine coordinate will be requested."],"exampleFix":"// before\nx, err := p.BytesX() // panics path when p is identity\n// after\nif p.Bytes()[0] == 0 { // infinity encoding is short / starts with 0x00\n    return errors.New(\"refusing to extract x of identity point\")\n}\nx, err := p.BytesX()","handlingStrategy":"type-guard","validationCode":"// Detect the point at infinity before extracting x.\nif len(p.Bytes()) == 1 { // infinity encoding is a single 0x00 byte\n    return errors.New(\"point is identity; no affine x\")\n}","typeGuard":"func isInfinity(p *nistec.P256Point) bool {\n    enc := p.Bytes()\n    return len(enc) == 1 && enc[0] == 0\n}","tryCatchPattern":"x, err := p.BytesX()\nif err != nil && strings.Contains(err.Error(), \"point at infinity\") {\n    return errors.New(\"refusing x of identity point\")\n}","preventionTips":["Check for the identity point before calling BytesX/BytesY.","In ECDH, reject peer identity points to avoid leaking computation.","Initialize points via SetBytes rather than relying on the zero value."],"tags":["elliptic-curve","fips140","crypto","nistec","point-at-infinity","code-generation"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}