Multiprecision Arithmetic for Cryptology in C++ - Compile-Time Computations and Beating the Performance of Hand-Optimized Assembly at Run-Time

Niek J. Bouman
4/19/2018
cs.CRcs.MS

Official code: niekbouman/ctbignum (123 stars, C++, Apache-2.0, last commit 2026-08-07).

Abstract

We describe a new C++ library for multiprecision arithmetic for numbers in the order of 100--500 bits, i.e., representable with just a few limbs. The library is written in "optimizing-compiler-friendly" C++, with an emphasis on the use of fixed-size arrays and particular function-argument-passing styles (including the avoidance of naked pointers) to allow the limbs to be allocated on the stack or even in registers.

Show full abstract

Depending on the particular functionality, we get close to, or significantly beat the performance of existing libraries for multiprecision arithmetic that employ hand-optimized assembly code. Most functions in the library are constant-time, which is a necessity for secure implementations of cryptographic protocols. Beyond the favorable runtime performance, our library is, to the best of the author's knowledge, the first library that offers big-integer computations during compile-time. For example, when implementing finite-field arithmetic with a fixed modulus, this feature enables the automatic precomputation (at compile time) of the special modulus-dependent constants required for Barrett and Montgomery reduction. Another application is to parse (at compile-time) a base-10-encoded big-integer literal.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

Library for Multiprecision Compile-Time and Run-Time Arithmetic (including Modular Arithmetic)

12312C++, CMakeNov 28, 20173 months agoApache-2.0
barrett-reductionbig-intconstexprcpp17cryptography+4 more

Similar Papers

Cite this paper

@article{bouman2018multiprecision,
  title  = {Multiprecision Arithmetic for Cryptology in C++ - Compile-Time Computations and Beating the Performance of Hand-Optimized Assembly at Run-Time},
  author = {Niek J. Bouman},
  year   = {2018},
  eprint = {1804.07236},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/1804.07236}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/1804.07236.svg)](https://codeofpaper.com/paper/1804.07236)

Discussion