Botan 3.14.1
Crypto and TLS for C&
mp_mulx.h
Go to the documentation of this file.
1/*
2* (C) 2026 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_MP_MULX_H_
8#define BOTAN_MP_MULX_H_
9
10#include <botan/types.h>
11#include <botan/internal/cpuid.h>
12
13namespace Botan {
14
15/*
16* Multiplication and squaring using MULX and ADX, see gen_mp_mulx.py
17*
18* The output z must not overlap x or y
19*/
20void bigint_mulx_mul4(word z[8], const word x[4], const word y[4]);
21void bigint_mulx_mul6(word z[12], const word x[6], const word y[6]);
22void bigint_mulx_mul8(word z[16], const word x[8], const word y[8]);
23void bigint_mulx_mul9(word z[18], const word x[9], const word y[9]);
24
25void bigint_mulx_sqr4(word z[8], const word x[4]);
26void bigint_mulx_sqr6(word z[12], const word x[6]);
27void bigint_mulx_sqr8(word z[16], const word x[8]);
28void bigint_mulx_sqr9(word z[18], const word x[9]);
29
30// Below this many words, the dedicated fixed size reductions are faster
31constexpr size_t MulxMontyMinWords = 9;
32
33inline bool use_mulx_monty(size_t p_size) {
35}
36
37/**
38* Fused Montgomery multiplication
39*
40* Computes z[0..N) = x*y*2^(-64*N) mod p for x, y < p. z may alias x or y.
41* ws must hold at least N + 3 words.
42*/
43void bigint_mulx_monty_mul(word z[], const word x[], const word y[], const word p[], size_t N, word p_dash, word ws[]);
44
45/**
46* Montgomery squaring
47*
48* Computes z[0..N) = x*x*2^(-64*N) mod p for x < p. z may alias x.
49* ws must hold at least 2N + 1 words.
50*/
51void bigint_mulx_monty_sqr(word z[], const word x[], const word p[], size_t N, word p_dash, word ws[]);
52
53/**
54* Squaring for any size: z[0..2N) = x^2, with z[2N] cleared
55*
56* The output z must not overlap x and must have 2N+1 words
57*/
58void bigint_mulx_sqr(word z[], const word x[], size_t N);
59
60/**
61* Montgomery reduction of a 2N word value z, which is destroyed
62*
63* Computes r[0..N) = z*2^(-64*N) mod p for z < p*2^(64*N). The buffer z must
64* have 2N+1 words.
65*/
66void bigint_mulx_monty_redc(word r[], word z[], const word p[], size_t N, word p_dash);
67
68} // namespace Botan
69
70#endif
static bool has(CPUID::Feature feat)
Definition cpuid.h:93
void bigint_mulx_monty_mul(word z[], const word x[], const word y[], const word p[], size_t N, word p_dash, word ws[])
void bigint_mulx_mul6(word z[12], const word x[6], const word y[6])
Definition mp_mulx.cpp:371
void bigint_mulx_monty_redc(word r[], word z[], const word p[], size_t N, word p_dash)
void bigint_mulx_mul9(word z[18], const word x[9], const word y[9])
Definition mp_mulx.cpp:1315
void bigint_mulx_sqr(word z[], const word x[], size_t N)
void bigint_mulx_mul8(word z[16], const word x[8], const word y[8])
Definition mp_mulx.cpp:772
void bigint_mulx_sqr6(word z[12], const word x[6])
Definition mp_mulx.cpp:213
void bigint_mulx_sqr9(word z[18], const word x[9])
Definition mp_mulx.cpp:1039
void bigint_mulx_monty_sqr(word z[], const word x[], const word p[], size_t N, word p_dash, word ws[])
void bigint_mulx_sqr4(word z[8], const word x[4])
Definition mp_mulx.cpp:28
bool use_mulx_monty(size_t p_size)
Definition mp_mulx.h:33
void bigint_mulx_mul4(word z[8], const word x[4], const word y[4])
Definition mp_mulx.cpp:122
std::conditional_t< HasNative64BitRegisters, std::uint64_t, uint32_t > word
The native machine word, used as the limb type for multiprecision integers.
Definition types.h:131
void bigint_mulx_sqr8(word z[16], const word x[8])
Definition mp_mulx.cpp:538
constexpr size_t MulxMontyMinWords
Definition mp_mulx.h:31