diff --git a/keyutil/jwk.go b/keyutil/jwk.go index 6a25191..e77e256 100644 --- a/keyutil/jwk.go +++ b/keyutil/jwk.go @@ -198,7 +198,8 @@ 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 + // 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 } func (ec *jwkEC) PublicKey() (*ecdsa.PublicKey, error) {