Appendix A. Code and tools
This appendix introduces the practical software tools needed to work with elliptic curve cryptography in C on Linux. It focuses on three supporting libraries or tools: GMP for large-integer arithmetic, PARI/gp for mathematical verification and experimentation, and KangarooTwelve as an additional library built from source. The overall aim is to give developers the tooling needed to handle numbers far larger than native C types can support.
For large-number computation, the text recommends GMP because it is free, actively maintained, and well suited to the huge bit sizes required in cryptographic work. It explains how to download, unpack, configure, compile, test, and install the library, and notes that programs should include the GMP header and link against the correct library location. It also points out that GMP offers both standard and constant-time “secure” routines, with the latter being useful against side-channel attacks, though system constraints such as power use and performance may influence which approach is practical.
The appendix then turns to PARI/gp, describing PARI as a mathematical library and gp as its command-line interface. It explains that PARI is useful both for direct API calls and as a trusted reference for checking C code that uses GMP, especially in finite-field elliptic curve work. The installation process is presented as straightforward: download, unpack, configure, and install, then use the PARI header in C programs and adapt the example makefile for one’s own target so PARI libraries are linked correctly.
A.3 Building KangarooTwelve library
KangarooTwelve unpacks into a directory called K12-master, but I prefer to create a directory so the zip file is separated from all my other files. I issued the command
and cut and paste https://github.com/XKCP/K12/archive/refs/heads/master.zip into a browser, which I then direct to save into the K12 directory. The next step is to change into the K12 directory and unpack the download with
This creates a directory K12-master. Change to that directory and type make:
The makefile lists many options to build. The simplest and most direct for 64-bit machines is the generic64/libk12.a static library. That’s what I’m using for the examples in this book.
Building is very quick, and then we can copy the library into a standard location. The commands are
The k12.header directory in the example source code contains files copied from the K12-master/lib and K12-master/lib/Optimized64 directories. There is more there to explore.
FAQ
What is the GNU Multiple Precision Arithmetic Library (GMP) used for in elliptic curve cryptography?
GMP is used to handle very large numbers efficiently, which are required for elliptic curve cryptography. Standard C integer types are too small for the bit sizes needed, so GMP provides the low-level multi-precision arithmetic routines.Why does the book recommend GMP instead of using built-in C number types?
Built-in C types likelong are too short for cryptographic-size integers. GMP is free, regularly updated, and already implements the large-number operations needed for elliptic curve computations.How do you download and unpack GMP on Linux?
You can get GMP fromhttps://gmplib.org/. After downloading a release archive, unpack it with tar xf gmp-x.y.z.tar.*, where the extension may be gz, lz, or zst.What are the standard installation commands for GMP?
After entering the unpacked GMP directory, run./configure, then make, and finally sudo make install.How can you verify that GMP compiled correctly?
You can runmake check to test the compiled subroutines and confirm that the build was successful.What header file must be included to use GMP in C programs?
Include<gmp.h> in your C source files to access GMP functions and data types.Where is the GMP library typically linked from during compilation?
The book notes that the linker should findlibgmp.a in the system library directory, such as /usr/local/lib on the author’s system.What is PARI/gp, and how is it used in the book?
PARI is a mathematical library, and gp is its command-line interface. The book uses PARIlib and gp to verify results from C programs that use GMP, since PARI/gp serves as a trusted reference for finite-field and elliptic-curve calculations.How do you install PARI/gp from source on Linux?
Download and unpack the source archive withtar xf PARI_x.yy.z.tar.gz, change into the directory, run ./Configure to accept defaults, and then run sudo make install.What header and build setup are needed to use PARIlib in a C program?
Include<PARI/PARI.h> in your C file. Then copy the example makefile from PARI_x.yy.z/examples/Makefile, change the TARGET line to your program, and run make to link against the PARI libraries.
Elliptic Curve Cryptography for Developers ebook for free