opyeb jwkslab

jwkslab · EC · OKP

EC and OKP curves — coordinate length and crv names

An EC key's coordinate length follows from its curve name. OKP keys are all 32 bytes but the two common curves serve different purposes.

The shape of an EC key

An EC public JWK has kty EC and the members crv, x and y. crv is the curve name and x and y are the point coordinates in Base64URL. Each curve fixes the coordinate length, so a different length means a broken key.

crvBitsCoordinate bytesalg
P-25625632ES256, ECDH-ES
P-38438448ES384, ECDH-ES
P-52152166ES512, ECDH-ES
secp256k125632ES256K

You can also test whether the point lies on the curve: y² = x³ + ax + b must hold, and if it does not, the key is damaged or the values belong to another curve. This tool runs the check for P-256, P-384 and P-521, and for secp256k1 confirms only the length and crv.

Building the PEM

An EC public key's SPKI carries algorithm OID 1.2.840.10045.2.1 and the curve OID, with the uncompressed point starting at 0x04 inside the BIT STRING. The curve OIDs are 1.2.840.10045.3.1.7 for P-256, 1.3.132.0.34 for P-384, 1.3.132.0.35 for P-521 and 1.3.132.0.10 for secp256k1.

JWK does not use compressed points (33 bytes starting with 0x02 or 0x03). It stores x and y separately, so conversion must assemble the uncompressed point.

OKP keys

OKP covers Ed25519, X25519, Ed448 and X448. JOSE in practice uses Ed25519 (signatures, alg EdDSA) and X25519 (key agreement, ECDH-ES family). Both have 32-byte public keys, and the JWK carries only kty=OKP, crv and x. No y is the visible difference from EC.

Sorting out the names

P-256, secp256r1 and prime256v1 are the same curve. JWK uses P-256 while OpenSSL configuration often says prime256v1. P-384 is secp384r1 and P-521 is secp521r1. secp256k1, despite the similar name, is a different curve entirely.

alg names drift from curves too. ES512 does not use a 512-bit curve but P-521. ES256K is secp256k1 only, and putting ES256K on a P-256 key fails verification.

Questions

Why is a P-521 coordinate 66 bytes?

521 bits rounds up to 66 bytes (65.125). x and y are 66 bytes each, and the uncompressed point is 1 + 66 + 66 = 133 bytes.

How do Ed25519 and X25519 differ?

Both belong to Curve25519, but Ed25519 is for signatures and X25519 for key agreement. Their public keys are both 32 bytes, so only crv tells them apart.

Where is secp256k1 used?

In Bitcoin and some blockchain ecosystems. JOSE names it ES256K, and standard library support is narrower than for P-256.

Paste an EC or OKP key and the curve, coordinate length and on-curve check are shown.

Open the tool

This article follows RFC 7517 (JWK), RFC 7518 (JWA), RFC 7638 (JWK thumbprint), RFC 5280 (X.509), RFC 5958 (PKCS#8), RFC 5915 (SEC1) and RFC 8037 (OKP). Every example key is synthetic and was made for this site.