From d4209dd5bdf4406505827525f6cd2ce56eca6258 Mon Sep 17 00:00:00 2001 From: Victor Lyuboslavsky <2685025+getvictor@users.noreply.github.com> Date: Sun, 13 Jul 2025 12:09:01 +0200 Subject: [PATCH 1/2] Fix P-521 coordinate length calculation The P-521 curve has 521 bits (65.125 bytes), but JWK EC coordinates must be zero-padded to 66 bytes. Using `crv.Params().BitSize/8` truncates to 65 bytes. Updating the calculation to round up --- keyutil/jwk.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keyutil/jwk.go b/keyutil/jwk.go index 6a25191..4b28055 100644 --- a/keyutil/jwk.go +++ b/keyutil/jwk.go @@ -198,7 +198,7 @@ func (ec *jwkEC) params() (crv elliptic.Curve, byteLen int, e error) { default: return nil, 0, fmt.Errorf("Unsupported ECC curve '%s'", ec.Curve) } - return crv, crv.Params().BitSize / 8, nil + return crv, (crv.Params().BitSize + 7) / 8, nil } func (ec *jwkEC) PublicKey() (*ecdsa.PublicKey, error) { From 7fdf9e7888ec2cdfe5097e7bed021909c76dfb03 Mon Sep 17 00:00:00 2001 From: Victor Lyuboslavsky <2685025+getvictor@users.noreply.github.com> Date: Fri, 25 Jul 2025 08:34:12 +0200 Subject: [PATCH 2/2] Update jwk.go --- keyutil/jwk.go | 1 + 1 file changed, 1 insertion(+) diff --git a/keyutil/jwk.go b/keyutil/jwk.go index 4b28055..e77e256 100644 --- a/keyutil/jwk.go +++ b/keyutil/jwk.go @@ -198,6 +198,7 @@ func (ec *jwkEC) params() (crv elliptic.Curve, byteLen int, e error) { default: return nil, 0, fmt.Errorf("Unsupported ECC curve '%s'", ec.Curve) } + // The P-521 curve has 521 bits (65.125 bytes), so we must round up to get the bytes. We need 66 bytes to store 521 bits. return crv, (crv.Params().BitSize + 7) / 8, nil }