Honesty Boundary
The same public key can be written in more than one point format, each a different file; the page compresses a P-256 point by hand and with one command, and lists what these lessons did not show, from point checks to side channels.
The question
The lessons of this book ran real elliptic-curve algorithms on test keys. What do they establish and what do they leave out? And is there anything about a public key that a reader can still get wrong, even after seeing its bytes? One thing is the format: the same public key can be written as 65 bytes or as 33.
The keys in this lesson are P-256 test keys made for these lessons. The point is public; the private keys are test material and protect nothing.
Work it by hand
RFC 5480 section 2.2 allows the first byte of a public point to be 04, the uncompressed form with x and y, or 02 or 03, the compressed form with x only. The hybrid form must not be used. A compressed point keeps x and one bit that says which of the two possible y values is meant. In the test keys the prefix is 02 when the last byte of y is even and 03 when it is odd.
- Uncompressed: 04, x, y: 65 bytes on P-256.
- Compressed: 02 or 03, then x: 33 bytes.
- The key is the same; the file that holds it is not. A public key file with the compressed point is a different text.
What the pages did not show, said once here:
- Choosing a curve and checking a received point. The pages use fixed test keys and never check that a point someone sent lies on the curve.
- Side channels and timing. The runs measure nothing about the time an operation takes or what it leaks.
- Deterministic ECDSA. RFC 6979 (August 2013) defines a way to derive the nonce of ECDSA from the key and the message. The page names it and does not run it.
- Ed25519 variants. RFC 8032 section 5.1 also names Ed25519ctx and Ed25519ph; the pages signed with plain Ed25519 only.
- Key storage, certificates and key agreement with X25519. These are the subjects of other lessons or of none here.
Run it
The program takes the uncompressed point as hexadecimal bytes. Line 1 counts them, line 2 reads the last byte of y, and line 3 turns its parity into the prefix 2 or 3. Line 4 builds the compressed point: the prefix and the 32 bytes of x.
For p256-a the point has 65 bytes, the last byte of y is odd, so the prefix is 3 and the compressed point has 33 bytes. The program returns 33; the extra value compressed shows it.

Public test material, generated for this lesson. Never use it for anything real.
let size = hex_len(point);
let last = hex_u8(point, 64);
let prefix = 2 + last % 2;
let compressed = u8_hex(prefix) + hex_slice(point, 1, 32);
lmcode_return_put("uncompressed_bytes", size);
lmcode_return_put("prefix", prefix);
lmcode_return_put("compressed", compressed);
let answer = hex_len(compressed);
{
"answer": 33,
"uncompressed_bytes": 65,
"prefix": 3,
"compressed": "033c86a17186bb783374b70ae420c31571755eedf239c01a36862b1064d1bd0685"
}You can change the point, but only a 65-byte point gives a meaningful result. A shorter point stops the program with "byte 64 is past the end of the data" at the read of the last byte; a longer one runs and returns 33 for bytes that are not a P-256 point. The program does not check that x and y belong together.
Your turn
The command below reads the private key in in/key.txt and prints its public key. Edit it so that it prints the public key with the compressed point, as a PEM block, and nothing else. Check runs your command on the key shown and on three others, each in the same file.

Public test material, generated for this lesson. Never use it for anything real.
# Reads the private key in in/key.txt.
# Check runs it with other keys in that file.
ec -in in/key.txt -pubout
{
"answer": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE1sxqGGYdRR3ttvYIqmnje5etzFBh\nqkFlIQaXuhYDd5H9cIwQOnjP18GIkecRnqeQ+wARO1jGiGob8OWyUVfJpw==\n-----END PUBLIC KEY-----"
}Write one command that prints the public key of the P-256 private key in in/key.txt as a PEM block in which the point is written in the compressed form, and prints nothing else on standard output. Check runs your command with other keys in that file.
Read the result carefully
Writing a point in another format does not change the key, but a program that compares public key files by text sees two keys. A real program converts to one format before comparing. The page shows the conversion on test keys and gives no advice for any system.
The list above is the boundary of these lessons: the runs show what OpenSSL and the page's programs do with fixed keys. They do not show how to build a system from them. Nothing here says that a curve or a scheme is safe; the standards cited say what they say, and the lessons ran them on test material only.
Recap
- A public point can be uncompressed, 04 with x and y, or compressed, 02 or 03 with x only.
- The same key in another format is a different file.
- A key tool can write the public key with the compressed point; the file differs from the one with the full point.
- The pages left out curve choice, point checks, timing, deterministic ECDSA and the Ed25519 variants.