Elliptic Curve Point Multiplication

Instead, let me break it down for you in a way that even my grandma could understand (well… maybe not).

So what exactly is elliptic curve point multiplication? Well, imagine you have an elliptical shape with some points on it. Now, if you want to multiply two of those points together, all you need to do is add them up a bunch of times! (Yes, really.) But before we get into the details, let’s take a look at an example in Python using the `tinyec` library.

This will be our base point for multiplication:

# Import the `tinyec` library to use for elliptic curve operations
import tinyec

# Define the base point for multiplication, using binary notation for the x and y coordinates
base_point = ec.Point(x=0b10000000000000000000000000000000, y=0b10000000000000000000000000000001)

# Create an elliptic curve object using the `secp256k1` standard
curve = tinyec.registry.get_curve('secp256k1')

# Generate a random private key for the first point
private_key1 = curve.field.random()

# Generate the first point by multiplying the base point by the private key
point1 = private_key1 * base_point

# Generate a random private key for the second point
private_key2 = curve.field.random()

# Generate the second point by multiplying the base point by the private key
point2 = private_key2 * base_point

# Add the two points together to get a third point
point3 = point1 + point2

# Print the coordinates of the third point
print("The coordinates of the third point are: ({}, {})".format(point3.x, point3.y))

# Multiply the third point by the inverse of the first private key to get the original second point
point4 = (point3 * private_key1.inverse())

# Print the coordinates of the original second point
print("The coordinates of the original second point are: ({}, {})".format(point4.x, point4.y))

# Multiply the third point by the inverse of the second private key to get the original first point
point5 = (point3 * private_key2.inverse())

# Print the coordinates of the original first point
print("The coordinates of the original first point are: ({}, {})".format(point5.x, point5.y))

# Multiply the base point by a random private key to get a new point
point6 = private_key1 * base_point

# Check if the new point is equal to the original first point
if point6 == point1:
    print("The new point is equal to the original first point.")
else:
    print("The new point is not equal to the original first point.")

Next, let’s generate a random secret key using the `random.randint()` function:

# Generate a random secret key using the `random.randint()` function
# Import the random module to access the `randint()` function
import random

# Set the variable `secret_key` to a random integer between 1 and 2^256
# The `randint()` function takes two arguments, the lower and upper bounds of the range
# The upper bound is exclusive, so we add 1 to include 2^256 in the range
secret_key = random.randint(1, 2 ** 256 + 1)

Now that we have our base point and secret key, it’s time to multiply them together! This is where the magic happens… or rather, the math-y stuff:

# Initialize result with infinity (the starting point for addition/multiplication)
result = ec.Point(x=0, y=0)

# Loop through 256 times
for i in range(256):
    # Check if the least significant bit of the secret key is 1
    if secret_key & 1 == 1:
        # If it is, add the base point to the result
        result += base_point
    # Square the base point
    base_point *= base_point
    # Shift the secret key to the right by 1 bit
    secret_key >>= 1

Our final result is stored in the `result` variable. But wait… what’s going on here? Why are we multiplying our base point by itself so many times? And why do we keep checking if a certain bit is set or not? Well, that’s where elliptic curve point multiplication gets a little more complicated (but still pretty cool).

In short, the process involves repeatedly doubling and adding points to get to our final result. But instead of doing this in a linear fashion (i.e., `point1 + point2`), we’re using a technique called “windowing” to speed things up. This involves breaking down our secret key into smaller chunks, and then performing multiple additions/doublings at once based on the values of those bits.

It may not be as exciting as watching paint dry or listening to your grandma’s stories about her cat (sorry, Grandma), but it’s definitely a fascinating topic for anyone interested in cryptography and math-y stuff.

Later!

SICORPS