QSC Post Quantum Cryptographic Library 1.0.0.6c (A6)
A post quantum secure library written in Ansi C
 
Loading...
Searching...
No Matches
donna128.h File Reference

Donna128 128-bit Integer Arithmetic Functions. More...

#include "common.h"

Go to the source code of this file.

Data Structures

struct  uint128
 128-bit integer structure. More...
 

Functions

QSC_EXPORT_API uint128 qsc_donna128_shift_right (const uint128 *x, size_t shift)
 Right shift a 128-bit integer.
 
QSC_EXPORT_API uint128 qsc_donna128_shift_left (const uint128 *x, size_t shift)
 Left shift a 128-bit integer.
 
QSC_EXPORT_API uint64_t qsc_donna128_andl (const uint128 *x, uint64_t mask)
 Bitwise AND the low part of a 128-bit integer.
 
QSC_EXPORT_API uint64_t qsc_donna128_andh (const uint128 *x, uint64_t mask)
 Bitwise AND the high part of a 128-bit integer.
 
QSC_EXPORT_API uint128 qsc_donna128_add (const uint128 *x, const uint128 *y)
 Add two 128-bit integers.
 
QSC_EXPORT_API uint128 qsc_donna128_multiply (const uint128 *x, uint64_t y)
 Multiply a 128-bit integer by a 64-bit integer.
 
QSC_EXPORT_API uint128 qsc_donna128_or (const uint128 *x, const uint128 *y)
 Bitwise OR of two 128-bit integers.
 

Detailed Description

Donna128 128-bit Integer Arithmetic Functions.

This module provides a comprehensive set of operations for performing arithmetic on 128-bit integers using a software-based implementation. The Donna128 arithmetic functions include operations such as addition, subtraction, multiplication, and modular reduction of 128-bit integers. This implementation is optimized for use in cryptographic applications where high-precision arithmetic is required, particularly in environments where native hardware support for 128-bit integers may be limited.

The functions are designed to operate in constant-time to mitigate timing attacks in sensitive cryptographic computations. They are integral to cryptographic primitives such as digital signatures, key exchange protocols, and other schemes that depend on multiprecision arithmetic.

Example Usage:
#include "donna128.h"
// Initialize two 128-bit integers (of type donna128)
donna128 a, b, result;
// Assume that 'a' and 'b' have been assigned appropriate 128-bit values.
// Perform addition
donna128_add(&result, &a, &b);
// Perform multiplication
donna128_mul(&result, &a, &b);
// Perform modular reduction with a given modulus (if applicable)
donna128_mod(&result, &a, &modulus);
Donna128 128-bit Integer Arithmetic Functions.

Reference Links:

Function Documentation

◆ qsc_donna128_add()

QSC_EXPORT_API uint128 qsc_donna128_add ( const uint128 * x,
const uint128 * y )

Add two 128-bit integers.

Parameters
x[const uint128*] Pointer to the first integer.
y[const uint128*] Pointer to the second integer.
Returns
[uint128] The sum of the two 128-bit integers.

◆ qsc_donna128_andh()

QSC_EXPORT_API uint64_t qsc_donna128_andh ( const uint128 * x,
uint64_t mask )

Bitwise AND the high part of a 128-bit integer.

Parameters
x[const uint128*] Pointer to the input integer.
mask[uint64_t] The bitmask for the operation.
Returns
[uint64_t] The result of the AND operation on the high 64 bits.

◆ qsc_donna128_andl()

QSC_EXPORT_API uint64_t qsc_donna128_andl ( const uint128 * x,
uint64_t mask )

Bitwise AND the low part of a 128-bit integer.

Parameters
x[const uint128*] Pointer to the input integer.
mask[uint64_t] The bitmask for the operation.
Returns
[uint64_t] The result of the AND operation on the low 64 bits.

◆ qsc_donna128_multiply()

QSC_EXPORT_API uint128 qsc_donna128_multiply ( const uint128 * x,
uint64_t y )

Multiply a 128-bit integer by a 64-bit integer.

Parameters
x[const uint128*] Pointer to the first integer.
y[uint64_t] The second integer.
Returns
[uint128] The product of the multiplication.

◆ qsc_donna128_or()

QSC_EXPORT_API uint128 qsc_donna128_or ( const uint128 * x,
const uint128 * y )

Bitwise OR of two 128-bit integers.

Parameters
x[const uint128*] Pointer to the first integer.
y[const uint128*] Pointer to the second integer.
Returns
[uint128] The result of the OR operation.

◆ qsc_donna128_shift_left()

QSC_EXPORT_API uint128 qsc_donna128_shift_left ( const uint128 * x,
size_t shift )

Left shift a 128-bit integer.

Parameters
x[const uint128*] Pointer to the input integer.
shift[size_t] Number of bits to shift left.
Returns
[uint128] The shifted value.

◆ qsc_donna128_shift_right()

QSC_EXPORT_API uint128 qsc_donna128_shift_right ( const uint128 * x,
size_t shift )

Right shift a 128-bit integer.

Parameters
x[const uint128*] Pointer to the input integer.
shift[size_t] Number of bits to shift right.
Returns
[uint128] The shifted value.