MPI (Multiple Precision Integer Arithmetic) More...
Go to the source code of this file.
Data Structures | |
struct | Mpi |
Arbitrary precision integer. More... | |
Macros | |
#define | MPI_MAX_BITS 4096 |
#define | MPI_BITS_PER_WORD 32 |
#define | MPI_MAX_WORDS ((MPI_MAX_BITS + MPI_BITS_PER_WORD - 1) / MPI_BITS_PER_WORD) |
#define | MPI_BYTES_PER_WORD (MPI_BITS_PER_WORD / 8) |
#define | mpi_word_t uint32_t |
#define | mpi_sword_t int32_t |
#define | mpi_dword_t uint64_t |
#define | MPI_CHECK(f) if((error = f) != NO_ERROR) goto end |
#define | mpiIsEven(a) !mpiGetBitValue(a, 0) |
#define | mpiIsOdd(a) mpiGetBitValue(a, 0) |
Enumerations | |
enum | MpiFormat { MPI_FORMAT_LITTLE_ENDIAN = 0, MPI_FORMAT_BIG_ENDIAN = 1 } |
MPI import/export format. More... | |
Functions | |
void | mpiInit (Mpi *r) |
Initialize a multiple precision integer. More... | |
void | mpiFree (Mpi *r) |
Release a multiple precision integer. More... | |
error_t | mpiGrow (Mpi *r, uint_t size) |
Adjust the size of multiple precision integer. More... | |
uint_t | mpiGetLength (const Mpi *a) |
Get the actual length in words. More... | |
uint_t | mpiGetByteLength (const Mpi *a) |
Get the actual length in bytes. More... | |
uint_t | mpiGetBitLength (const Mpi *a) |
Get the actual length in bits. More... | |
error_t | mpiSetBitValue (Mpi *r, uint_t index, uint_t value) |
Set the bit value at the specified index. More... | |
uint_t | mpiGetBitValue (const Mpi *a, uint_t index) |
Get the bit value at the specified index. More... | |
int_t | mpiComp (const Mpi *a, const Mpi *b) |
Compare two multiple precision integers. More... | |
int_t | mpiCompInt (const Mpi *a, mpi_sword_t b) |
Compare a multiple precision integer with an integer. More... | |
int_t | mpiCompAbs (const Mpi *a, const Mpi *b) |
Compare the absolute value of two multiple precision integers. More... | |
error_t | mpiCopy (Mpi *r, const Mpi *a) |
Copy a multiple precision integer. More... | |
error_t | mpiSetValue (Mpi *r, mpi_sword_t a) |
Set the value of a multiple precision integer. More... | |
error_t | mpiRand (Mpi *r, uint_t length, const PrngAlgo *prngAlgo, void *prngContext) |
Generate a random value. More... | |
error_t | mpiRandRange (Mpi *r, const Mpi *p, const PrngAlgo *prngAlgo, void *prngContext) |
Generate a random value in the range 1 to p-1. More... | |
error_t | mpiCheckProbablePrime (const Mpi *a) |
Test whether a number is probable prime. More... | |
error_t | mpiImport (Mpi *r, const uint8_t *input, size_t length, MpiFormat format) |
Octet string to integer conversion. More... | |
error_t | mpiExport (const Mpi *a, uint8_t *output, size_t length, MpiFormat format) |
Integer to octet string conversion. More... | |
error_t | mpiAdd (Mpi *r, const Mpi *a, const Mpi *b) |
Multiple precision addition. More... | |
error_t | mpiAddInt (Mpi *r, const Mpi *a, mpi_sword_t b) |
Add an integer to a multiple precision integer. More... | |
error_t | mpiSub (Mpi *r, const Mpi *a, const Mpi *b) |
Multiple precision subtraction. More... | |
error_t | mpiSubInt (Mpi *r, const Mpi *a, mpi_sword_t b) |
Subtract an integer from a multiple precision integer. More... | |
error_t | mpiAddAbs (Mpi *r, const Mpi *a, const Mpi *b) |
Helper routine for multiple precision addition. More... | |
error_t | mpiSubAbs (Mpi *r, const Mpi *a, const Mpi *b) |
Helper routine for multiple precision subtraction. More... | |
error_t | mpiShiftLeft (Mpi *r, uint_t n) |
Left shift operation. More... | |
error_t | mpiShiftRight (Mpi *r, uint_t n) |
Right shift operation. More... | |
error_t | mpiMul (Mpi *r, const Mpi *a, const Mpi *b) |
Multiple precision multiplication. More... | |
error_t | mpiMulInt (Mpi *r, const Mpi *a, mpi_sword_t b) |
Multiply a multiple precision integer by an integer. More... | |
error_t | mpiDiv (Mpi *q, Mpi *r, const Mpi *a, const Mpi *b) |
Multiple precision division. More... | |
error_t | mpiDivInt (Mpi *q, Mpi *r, const Mpi *a, mpi_sword_t b) |
Divide a multiple precision integer by an integer. More... | |
error_t | mpiMod (Mpi *r, const Mpi *a, const Mpi *p) |
Modulo operation. More... | |
error_t | mpiAddMod (Mpi *r, const Mpi *a, const Mpi *b, const Mpi *p) |
Modular addition. More... | |
error_t | mpiSubMod (Mpi *r, const Mpi *a, const Mpi *b, const Mpi *p) |
Modular subtraction. More... | |
error_t | mpiMulMod (Mpi *r, const Mpi *a, const Mpi *b, const Mpi *p) |
Modular multiplication. More... | |
error_t | mpiInvMod (Mpi *r, const Mpi *a, const Mpi *p) |
Modular inverse. More... | |
error_t | mpiExpMod (Mpi *r, const Mpi *a, const Mpi *e, const Mpi *p) |
Modular exponentiation. More... | |
error_t | mpiExpModFast (Mpi *r, const Mpi *a, const Mpi *e, const Mpi *p) |
Modular exponentiation (fast calculation) More... | |
error_t | mpiExpModRegular (Mpi *r, const Mpi *a, const Mpi *e, const Mpi *p) |
Modular exponentiation (regular calculation) More... | |
error_t | mpiMontgomeryMul (Mpi *r, const Mpi *a, const Mpi *b, uint_t k, const Mpi *p, Mpi *t) |
Montgomery multiplication. More... | |
error_t | mpiMontgomeryRed (Mpi *r, const Mpi *a, uint_t k, const Mpi *p, Mpi *t) |
Montgomery reduction. More... | |
void | mpiMulAccCore (mpi_word_t *r, const mpi_word_t *a, int_t m, const mpi_word_t b) |
Multiply-accumulate operation. More... | |
void | mpiDump (FILE *stream, const char_t *prepend, const Mpi *a) |
Display the contents of a multiple precision integer. More... | |
Detailed Description
MPI (Multiple Precision Integer Arithmetic)
License
SPDX-License-Identifier: GPL-2.0-or-later
Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
This file is part of CycloneCRYPTO Open.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- Version
- 2.5.0
Definition in file mpi.h.
Macro Definition Documentation
◆ MPI_BITS_PER_WORD
◆ MPI_BYTES_PER_WORD
#define MPI_BYTES_PER_WORD (MPI_BITS_PER_WORD / 8) |
◆ MPI_CHECK
◆ mpi_dword_t
◆ MPI_MAX_BITS
◆ MPI_MAX_WORDS
#define MPI_MAX_WORDS ((MPI_MAX_BITS + MPI_BITS_PER_WORD - 1) / MPI_BITS_PER_WORD) |
◆ mpi_sword_t
◆ mpi_word_t
◆ mpiIsEven
#define mpiIsEven | ( | a | ) | !mpiGetBitValue(a, 0) |
◆ mpiIsOdd
#define mpiIsOdd | ( | a | ) | mpiGetBitValue(a, 0) |
Enumeration Type Documentation
◆ MpiFormat
enum MpiFormat |
Function Documentation
◆ mpiAdd()
◆ mpiAddAbs()
◆ mpiAddInt()
error_t mpiAddInt | ( | Mpi * | r, |
const Mpi * | a, | ||
mpi_sword_t | b | ||
) |
◆ mpiAddMod()
◆ mpiCheckProbablePrime()
Test whether a number is probable prime.
- Parameters
-
[in] a Pointer to a multiple precision integer
- Returns
- Error code
Definition at line 610 of file pic32cx_bz_crypto_pkc.c.
◆ mpiComp()
◆ mpiCompAbs()
◆ mpiCompInt()
int_t mpiCompInt | ( | const Mpi * | a, |
mpi_sword_t | b | ||
) |
◆ mpiCopy()
◆ mpiDiv()
◆ mpiDivInt()
error_t mpiDivInt | ( | Mpi * | q, |
Mpi * | r, | ||
const Mpi * | a, | ||
mpi_sword_t | b | ||
) |
◆ mpiDump()
◆ mpiExpMod()
Modular exponentiation.
- Parameters
-
[out] r Resulting integer R = A ^ E mod P [in] a Pointer to a multiple precision integer [in] e Exponent [in] p Modulus
- Returns
- Error code
Definition at line 204 of file esp32_crypto_pkc.c.
◆ mpiExpModFast()
Modular exponentiation (fast calculation)
- Parameters
-
[out] r Resulting integer R = A ^ E mod P [in] a Pointer to a multiple precision integer [in] e Exponent [in] p Modulus
- Returns
- Error code
Definition at line 142 of file m2354_crypto_pkc.c.
◆ mpiExpModRegular()
Modular exponentiation (regular calculation)
- Parameters
-
[out] r Resulting integer R = A ^ E mod P [in] a Pointer to a multiple precision integer [in] e Exponent [in] p Modulus
- Returns
- Error code
Definition at line 224 of file m2354_crypto_pkc.c.
◆ mpiExport()
Integer to octet string conversion.
Converts an integer to an octet string of a specified length
- Parameters
-
[in] a Non-negative integer to be converted [out] output Octet string resulting from the conversion [in] length Intended length of the resulting octet string [in] format Output format
- Returns
- Error code
◆ mpiFree()
void mpiFree | ( | Mpi * | r | ) |
◆ mpiGetBitLength()
◆ mpiGetBitValue()
◆ mpiGetByteLength()
◆ mpiGetLength()
◆ mpiGrow()
◆ mpiImport()
Octet string to integer conversion.
Converts an octet string to a non-negative integer
- Parameters
-
[out] r Non-negative integer resulting from the conversion [in] input Octet string to be converted [in] length Length of the octet string [in] format Input format
- Returns
- Error code
◆ mpiInit()
void mpiInit | ( | Mpi * | r | ) |
◆ mpiInvMod()
Modular inverse.
- Parameters
-
[out] r Resulting integer R = A^-1 mod P [in] a The multiple precision integer A [in] p The modulus P
- Returns
- Error code
Definition at line 385 of file pic32cx_bz_crypto_pkc.c.
◆ mpiMod()
◆ mpiMontgomeryMul()
error_t mpiMontgomeryMul | ( | Mpi * | r, |
const Mpi * | a, | ||
const Mpi * | b, | ||
uint_t | k, | ||
const Mpi * | p, | ||
Mpi * | t | ||
) |
Montgomery multiplication.
- Parameters
-
[out] r Resulting integer R = A * B / 2^k mod P [in] a An integer A such as 0 <= A < 2^k [in] b An integer B such as 0 <= B < 2^k [in] k An integer k such as P < 2^k [in] p Modulus P [in] t An preallocated integer T (for internal operation)
- Returns
- Error code
◆ mpiMontgomeryRed()
◆ mpiMul()
Multiple precision multiplication.
- Parameters
-
[out] r Resulting integer R = A * B [in] a First operand A [in] b Second operand B
- Returns
- Error code
Definition at line 77 of file esp32_crypto_pkc.c.
◆ mpiMulAccCore()
void mpiMulAccCore | ( | mpi_word_t * | r, |
const mpi_word_t * | a, | ||
int_t | m, | ||
const mpi_word_t | b | ||
) |
◆ mpiMulInt()
error_t mpiMulInt | ( | Mpi * | r, |
const Mpi * | a, | ||
mpi_sword_t | b | ||
) |
◆ mpiMulMod()
Modular multiplication.
- Parameters
-
[out] r Resulting integer R = A * B mod P [in] a The first operand A [in] b The second operand B [in] p The modulus P
- Returns
- Error code
Definition at line 63 of file mimxrt1160_crypto_pkc.c.
◆ mpiRand()
◆ mpiRandRange()
◆ mpiSetBitValue()
◆ mpiSetValue()
error_t mpiSetValue | ( | Mpi * | r, |
mpi_sword_t | a | ||
) |
◆ mpiShiftLeft()
◆ mpiShiftRight()
◆ mpiSub()
◆ mpiSubAbs()
◆ mpiSubInt()
error_t mpiSubInt | ( | Mpi * | r, |
const Mpi * | a, | ||
mpi_sword_t | b | ||
) |