Crypto Maths

Ethereum One Way Hashing functions explained

Neel Iyer
Coinmonks
Published in
3 min readMay 6, 2021

--

Image by author. Quote from here.

Can you represent 8,018,009 as a product of two prime numbers?

You can use whatever calculator or program you like. I’ll wait.

****

I couldn’t do it either. Nor can a computer.

This is the guiding principle behind Crypto Maths.

In this post we’ll go from a private key to an address using all the mathematical functions in between. Much of this comes from Chapter 4 of the ethereumbook.

Public Keys

You’ve heard many definitions of a Public Key. But here’s the real one:

“An Ethereum public key is a point on an elliptic curve, meaning it is a set of x and y coordinates that satisfy the elliptic curve equation.” — ethereumbook.

But you’re probably thinking: What’s an elliptical curve?

Elliptical Curve

Ethereum uses the same elliptical curve as Bitcoin (secp256k1).

Here’s the equation:

Image from ethereumbook

The mod p indicates that this curve is only valid over the field of prime order p.

So in reality it looks less smooth. For p=17the graph looks something like this:

Image from ethereumbook

The private key is “plugged in” to this curve to generate a public key.

Generating a Public Key

Your private key (k)uses elliptical curve arithmetic to generate the public key. The simplified form of the equation is follows:

Where G is a predetermined point on the curve (called the generator point)

A more intuitive way of expressing this is as follows:

K = (k*G1, k*G2) where G1 and G2 are the x and y coordinates respectively.

Example:

Serialization

Ethereum uses uncompressed keys. So here’s how we can serialize the keys:

Example

Once the public key is obtained we can derive the address. Now people can send you money!

Cryptographic Hash Function

“Much more than encryption algorithms, one-way hash functions are the workhorses of modern cryptography.”— Bruce Schneier

Remember the intro? We saw that representing 8018009 as a product of two primes is difficult.

But 2003 * 4003 is easy.

In other words you can go from x->y. But you can’t go from y->x feasibly. This is what one-way means.

Ethereum uses the Keccak-256 one-way hash function. Keccak-256 converts the public key into a unique address.

An address cannot be used to obtain the public key.

Only the last 20 bytes are used as an address. The prefix `0x` is usually added:

Done!

Hope this article was useful. If it was please let me know and I’ll make more.

--

--