Hypercomplex: abstract & fast header-only C++ template library for lattice-based cryptosystems in high-dimensional algebras

The following work presents a C++ library that is dedicated to performing arbitrary-precise calculations on hypercomplex numbers from the Cayley-Dickson algebras (

• As a header-only C++ template code, its greatest advantage is the combination of speed, generic programming, and convenience for the end user.An open source license together with a template specialisation mechanism allows contributors to add support for custom objects, define specific functions, and extend the scope of the library.• The most important specialisation, already included in the library itself, is the introduction of operations in hypercomplex algebras over truncated polynomial rings.These allow for many cryptographic applications as described in a dedicated section below.• A template class specialisation introduces support for arbitrary high precision of calculations via the GNU MPFR library (Fousse et al., 2005), for which the operators have been overloaded such that all the instructions are carried out on specific data structures.• State of the art technology for software engineering: -CI/CD mechanism set up with GitHub Actions: automatic tests for library installation, source code inclusion, compilation, and execution, -extensive unit testing with the Catch2 framework (Hořeňovský, 2020) alongside code coverage measurement uploaded to Codecov; current coverage: 100%, -source code linting with cpplint (Google Inc., n.d.) -Google code style enforced, and automatic documentation generation and hosting on GitHub Pages: building via Doxygen (van Heesch, 2021), publishing via GitHub Actions.

Cryptographic applications
In the following section we shall describe the mathematical foundations for the previously mentioned family of cyptosystems.Consider a polynomial convolution ring ℛ = ℤ[]/(  − 1) with  > 2 being prime.Let ℛ  and ℛ  denote derived modular structures with coefficients from ℤ/ℤ and ℤ/ℤ, respectively.Every element of ℛ, ℛ  , ℛ  may be writted down as: where the addition operation + refers to a regular element-wise addition of coefficients (modular for ℛ  and ℛ  ).Multiplication ⋆ within this structure is defined as: with a final reduction modulo  or  in the modular quotient rings.
Based on the above, let us pick an integer  ≥ 0 and define three corresponding algebras, generated by the Cayley-Dickson process: where the addition operation + refers to ring addition defined above.
Multiplication × is defined recursively based on the conjugation operation * as below: which as well holds for the modular algebras, given a final reduction modulus  or .
Based on the above, let us define a general scheme for hypercomplex-based cyptosystems.Having agreed on ( , , ), Bob selects  ,  ∈   ∶ ∃ −1  ∈    ∧ ∃ −1  ∈    .A procedure to generate the public key  ∈    is then given by: Alice encrypts her message  ∈    into  ∈    with the use of a blinding element Φ ∈    according to: The following decryption consist of three steps: If the decryption was successfull, Bob receives  3 =  (up to coefficients' centered lift in    ).Please remember that the lattice-based cryptography is always burdened with a chance of decryption failure due to an incorrect recovery of polynomial's coefficients.Also, for  ≥ 4 note that   is neither alternative nor associative; thus successful decryption relies on a careful initial choice of  (e.g. ∶ ∃! ∈ {0, … , 2  − 1} ∶   ≠ 0).For a more detailed coverage of similar cryptosystems please see publications presenting QTRU (Malekian et al., 2009) and OTRU (Malekian & Zakerolhosseini, 2010).
Three examples of matrix encryption-decryption are presented in the Figure 1.All of the data and code required to reproduce these results is available in the code repository.

State of the field
When it comes to a general hypercomplex framework, the well-known boost C++ libraries deserve the most notable mention here (Koranne, 2011).Unfortunately their scope is limited as they only implement classes for quaterions and octonions (however, as an upside, all the operations are well optimised).Moreover, these libraries do not support operations on MPFR types natively.It may also be worth mentioning the existence of smaller projects like those by Girard (2007) and Hoppe (n.d.), but, unlike our work, they often lack proper test suites, code coverage reports, and documentation, and are also significantly restricted in functionality, which is a major drawback.
However, (most importantly) to our best knowledge, there is currently no high-quality opensource library that natively supports cryptosystems based on truncated polynomial rings.Previous research described distinct versions of NTRU (Hoffstein et al., 1998), among others: 4-dimensional QTRU (Malekian et al., 2009), 8-dimensional OTRU (Malekian & Zakerolhosseini, 2010); and a proposed 16-dimenisional STRU (Singh et al., 2021), the correctness of which has not yet been verified.Despite these efforts, no generalization has been provided yet.Our work is the first to present that these procedures are vaild in arbitrarily high-dimensional Cayley-Dickson algebras (provided a careful choice of parameters of the system) and to provide reproducible examples of a successful encryption/decryption procedures.Finally, it has not escaped our notice that the specific polynomial-based hypercomplex multiplication scheme we presented immediately suggests a possible hashing mechanism for string messages.