Ed25519 and Cu25519: A Practical Introduction

When learning about cryptography, you will often encounter two different requirements:
- Authenticity: How can I verify who signed this message and whether it has been changed?
- Confidentiality: How can I communicate with someone without letting other people read our messages?
Ed25519 and Cu25519 help address these requirements in different ways. Ed25519 provides digital signatures. Cu25519 refers here to Curve25519-based key agreement, commonly implemented using the standardized X25519 function.
To understand the difference, let's follow two people, Alice and Bob, who want to communicate securely.
1. Start with Public and Private Keys
Both algorithms use a key pair:
| Key | Who can access it? | Purpose |
|---|---|---|
| Private key | Only its owner | Perform a secret operation, such as signing or key agreement |
| Public key | Anyone | Verify a signature or participate in key agreement |
2. Ed25519: Signing a Message
Suppose Alice sends Bob this message:
Please transfer 100 points to Charlie.
Bob wants to detect whether someone changes the amount or sends a forged message pretending to be Alice.
Alice uses her Ed25519 private key to produce a signature:
// pseudocode
signature = sign(aliceSigningPrivateKey, message)She sends Bob two things:
Message: Please transfer 100 points to Charlie.
Signature: <signature bytes>Bob verifies the signature using Alice's public key:
bool valid = verify(alicSigningPublicKey, message, signature);if an attacker changes 100 to 1000, verification fails. The signature was generated for the original message.
if the attacker creates a new message, the cannot feasibly generate a valid signature without Alice's private key.
A valid signature establishes that the message matches the signature and the corresponding private key. To conclude that Alice signed it, Bob must also know that the public key really belongs to Alice. Ed25519 itself does not establish that identity relationship.
Does signing hide the message?
No. the message can remain readable to everyone who receives it.
Think of a signature as a way to verify a document, rather than an envelope that conceals its contents.
3. Cu25519: Agreeing on a Shared Secret
Now Alice and Bob want to keep their conversation private.
They need a secret encryption key. but sending that key as an ordinary message would expose it to anyone observing the network.
X25519 allows them to calculate the same shared secret independently.
Alice generates a key pair:
Alice's private key: a
Alice's public key: ABob generates another:
Bob's private key: b
Bob's public key: BThe exchange only their public keys. Alice calculates:
secretA = X25519(a, B);Bob calculates:
secretB = X25519(b, A);The mathematical construction gives them the same result:
secretA = secretBAn observer who sees A and B cannot feasibly calculate that shared secret from the public keys alone.
Why does this work?
A simplified mathematical model helps explain the idea.
Let G be a public base point. Alice's public key corresponds to multiplying that point by her private value, and Bob does the same:
A = a x G
B = b x GAlice then calculates:
a X B = a X (b X G)Bob calculates:
b X A = b X (a X G)Both arrive at the same mathematical result.
These expressions illustrate the principle; actual X25519 uses specific scalar processing and point-coordinate representations.
4. Turn the Shared Secret into Encryption Keys
The shared secret is an input to key derivation. The application uses a key derivation function, such as HKDF, together with suitable protocol context:
encryptionKey = HKDF(sharedSecret, salt, context);Alice can then encrypt messages using an authenticated encryption algorithm:
ciphertext = encrypt(encryptionKey, nonce, message);Bob derives the matching key and decrypts the message:
message = decrypt(encryptionKey, nonce, ciphertext);Libraries can provide key exchange APIs that combine shared-secret calculation with key derivation. For example, libsodium's key exchange API derives separate keys for sending and receiving.
X25519 establishes shared secret material. A symmetric encryption algorithm protects the actual message.
5. The Missing Piece: Who Owns the Public Key?
There is a problem with the exchange we described: Alice and Bob have not yet verified each other's public keys.
Suppose Mallory intercepts their communication. Instead of forwarding Bob's public key to Alice, Mallory sends her own.
Mallory can establish one shared secret with Alice and another with Bob. She can then decrypt, read, and forward their messages.
The mathematics still works, but Alice and Bob are agreeing on secrets with the wrong person.
This is why key agreement needs authentication. X25519 alone does not prevent a man in the middle attack.
6. Using Ed25519 and C725519 Together
One possible protocol uses Ed25519 to authenticate the public keys used for key agreement.
For example:
- Alice signs her key-agreement public key, together with the required protocol context, using her Ed25519 private key.
- Bob verifies that signature using Alice's trusted Ed25519 public key.
- Bob uses the authenticated key-aggreement public key to calculate a shared secret.
- The protocol derives encryption keys and protects the conversation.
This is an illustrative design, not a complete secure messaging protocol.
The word trusted matters. If Mallory can replace both Alice's signing public key and her key-agreement public key.
checking the signature alone does not solve the problem.
Alice and Bob may establish trust by comparing public-key fingerprints out of band-through an independent channel, such as an in-person meeting or a phone call to a known number.
A fingerprint is a compact representation derived from a public key. Comparing fingerprints helps users check that they have the same key.
7. Compare Their Roles
| Question | Ed25519 | Cu25519 |
|---|---|---|
| What does it do? | Creates and verifies digital signatures | Establishes a shared secret |
| What does it produce? | A signature | Shared secret material |
| Does it directly encrypt a message? | No | No |
| Does it independently prove a person's identity? | No; the verification key must be trusted | No; the peer's key must be authenticated |
| Typical use | Signing messages, software, or public keys | Establishing keys for encrypted communication |
When reading code, look at the operation being performed. A function that signs or verifies data belongs to the Ed25519 side. A function that combines a private key with a peer's public key to derive shared secret material belongs to the X25519 side.
