Perform Point Addition with tinyec

This section provides a tutorial example on how to perform the point addition operation on a given elliptic curve with tinyec Python library.

If you want to perform point addition operation on an elliptic curve with tinyec Python library, you must do it in three steps.

1. Create the elliptic curve. For example:

>>> import tinyec.ec as ec

>>> s = ec.SubGroup(p=97,g=(0,0),n=1,h=1)

>>> c = ec.Curve(a=2,b=3,field=s,name='p97a2b3')

2. Create ec.Point objects with their x and y coordinates an ec.Curve object. For example:

>>> p = ec.Point(curve=c,x=3,y=6)
>>> q = ec.Point(curve=c,x=80,y=10)

>>> print(p)
(3, 6) on "p97a2b3" => y^2 = x^3 + 2x + 3 (mod 97)

>>> print(q)
(80, 10) on "p97a2b3" => y^2 = x^3 + 2x + 3 (mod 97)

3. Perform the point addition with the "+" operator. For example:

>>> r = p + q

>>> print(r)
(80, 87) on "p97a2b3" => y^2 = x^3 + 2x + 3 (mod 97)

Ok. The point addition is performed correctly, you can verify it manually.

If you create an ec.Point object with an invalid curve point, tinyec will tell you the point is off the curve:

>>> t = ec.Point(curve=c,x=1,y=1)

>>> print(t)
(1, 1) off "p97a2b3" => y^2 = x^3 + 2x + 3 (mod 97)

Or you can verify if a given point is on or off the curve with the ec.curve.on_curve() method:

>>> c.on_curve(1,1)
False

>>> c.on_curve(3,6)
True

Table of Contents

 About This Book

 Running Python Code Online

 Python on macOS Computers

 Python on Linux Computers

 Built-in Data Types

 Variables, Operations and Expressions

 Statements - Execution Units

 Function Statement and Function Call

 Iterators and Generators

 List, Set and Dictionary Comprehensions

 Classes and Instances

 Modules and Module Files

 Packages and Package Directories

 "sys" and "os" Modules

 "pathlib" - Object-Oriented Filesystem Paths

 "pip" - Package Installer for Python

 SciPy.org - Python Libraries for Science

 pandas - Data Analysis and Manipulation

 Communicating with HTTPS Servers

tinyec - Tiny Library for ECC

 What Is tinyec

 Download and Install tinyec

 Build New Curves with tinyec

Perform Point Addition with tinyec

 Find Subgroup with Point Addition

 Set Subgroup Order to Higher Value

 Generating EC Public-Private Keys

 Anaconda - Python Environment Manager

 Jupyter Notebook and JupyterLab

 References

 Full Version in PDF/EPUB