OpenCore
1.0.4
OpenCore Bootloader
|
#include "BigNumLibInternal.h"
Go to the source code of this file.
Functions | |
STATIC OC_BN_WORD | BigNumMontInverse (IN CONST OC_BN_WORD *A) |
OC_BN_WORD | BigNumCalculateMontParams (IN OUT OC_BN_WORD *RSqrMod, IN OC_BN_NUM_WORDS NumWords, IN CONST OC_BN_WORD *N, IN OC_BN_WORD *Scratch) |
STATIC OC_BN_WORD | BigNumWordAddMul (OUT OC_BN_WORD *Hi, IN OC_BN_WORD C, IN OC_BN_WORD A, IN OC_BN_WORD B) |
STATIC OC_BN_WORD | BigNumWordAddMulCarry (OUT OC_BN_WORD *Hi, IN OC_BN_WORD C, IN OC_BN_WORD A, IN OC_BN_WORD B, IN OC_BN_WORD Carry) |
STATIC VOID | BigNumMontMulRow (IN OUT OC_BN_WORD *Result, IN OC_BN_NUM_WORDS NumWords, IN OC_BN_WORD AWord, IN CONST OC_BN_WORD *B, IN CONST OC_BN_WORD *N, IN OC_BN_WORD N0Inv) |
STATIC VOID | BigNumMontMul (IN OUT OC_BN_WORD *Result, IN OC_BN_NUM_WORDS NumWords, IN CONST OC_BN_WORD *A, IN CONST OC_BN_WORD *B, IN CONST OC_BN_WORD *N, IN OC_BN_WORD N0Inv) |
STATIC VOID | BigNumMontMulRow0 (IN OUT OC_BN_WORD *Result, IN OC_BN_NUM_WORDS NumWords, IN CONST OC_BN_WORD *N, IN OC_BN_WORD N0Inv) |
STATIC VOID | BigNumMontMul1 (IN OUT OC_BN_WORD *Result, IN OC_BN_NUM_WORDS NumWords, IN CONST OC_BN_WORD *A, IN CONST OC_BN_WORD *N, IN OC_BN_WORD N0Inv) |
BOOLEAN | BigNumPowMod (IN OUT OC_BN_WORD *Result, IN OC_BN_NUM_WORDS NumWords, IN CONST OC_BN_WORD *A, IN UINT32 B, IN CONST OC_BN_WORD *N, IN OC_BN_WORD N0Inv, IN CONST OC_BN_WORD *RSqrMod, IN OC_BN_WORD *ATmp) |
OC_BN_WORD BigNumCalculateMontParams | ( | IN OUT OC_BN_WORD * | RSqrMod, |
IN OC_BN_NUM_WORDS | NumWords, | ||
IN CONST OC_BN_WORD * | N, | ||
IN OC_BN_WORD * | Scratch ) |
Calculates the Montgomery Inverse and R^2 mod N.
[in,out] | RSqrMod | The buffer to return R^2 mod N into. |
[in] | NumWords | The number of Words of RSqrMod and N. Must be at most OC_BN_MONT_MAX_LEN. |
[in] | N | The Montgomery Modulus. |
[in] | Scratch | Scratch buffer BIG_NUM_MONT_PARAMS_SCRATCH_SIZE(NumWords). |
Definition at line 156 of file BigNumMontgomery.c.
STATIC OC_BN_WORD BigNumMontInverse | ( | IN CONST OC_BN_WORD * | A | ) |
This library performs arbitrary precision Montgomery operations. All results are returned into caller-provided buffers. The caller is responsible to ensure the buffers can hold the full result of the operation.
https://chromium.googlesource.com/chromiumos/platform/ec/+/master/common/rsa.c has served as a template for several algorithmic ideas.
This code is not to be considered general-purpose but solely to support cryptographic operations such as RSA encryption. As such, there are arbitrary limitations, such as requirement of equal precision, to limit the complexity of the operations to the bare minimum required to support such use caes.
SECURITY: Currently, no security measures have been taken. This code is vulnerable to both timing and side channel attacks for value leakage. However, its current purpose is the verification of public binaries with public certificates, for which this is perfectly acceptable, especially in regards to performance.
Copyright (C) 2019, Download-Fritz. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Calculates the Montgomery Inverse -1 / A mod 2^#Bits(Word). This algorithm is based on the Extended Euclidean Algorithm, which returns 1 / A mod 2^#Bits(Word).
[in] | A | The number to calculate the Montgomery Inverse of. |
0 | The Montgomery Inverse of A could not be computed. |
other | The Montgomery Inverse of A. |
Definition at line 47 of file BigNumMontgomery.c.
STATIC VOID BigNumMontMul | ( | IN OUT OC_BN_WORD * | Result, |
IN OC_BN_NUM_WORDS | NumWords, | ||
IN CONST OC_BN_WORD * | A, | ||
IN CONST OC_BN_WORD * | B, | ||
IN CONST OC_BN_WORD * | N, | ||
IN OC_BN_WORD | N0Inv ) |
Calculates the Montgomery product of A and B mod N.
[in,out] | Result | The result buffer. |
[in] | NumWords | The number of Words of Result, A, B and N. |
[in] | A | The multiplicant. |
[in] | B | The multiplier. |
[in] | N | The modulus. |
[in] | N0Inv | The Montgomery Inverse of N. |
Definition at line 400 of file BigNumMontgomery.c.
STATIC VOID BigNumMontMul1 | ( | IN OUT OC_BN_WORD * | Result, |
IN OC_BN_NUM_WORDS | NumWords, | ||
IN CONST OC_BN_WORD * | A, | ||
IN CONST OC_BN_WORD * | N, | ||
IN OC_BN_WORD | N0Inv ) |
This is an optimized version of the call BigNumMontMul (C, 1, A, N, N0Inv)
[in,out] | Result | The result buffer. |
[in] | NumWords | The number of Words of Result, A and N. |
[in] | A | The multiplicant. |
[in] | N | The modulus. |
[in] | N0Inv | The Montgomery Inverse of N. |
Definition at line 519 of file BigNumMontgomery.c.
STATIC VOID BigNumMontMulRow | ( | IN OUT OC_BN_WORD * | Result, |
IN OC_BN_NUM_WORDS | NumWords, | ||
IN OC_BN_WORD | AWord, | ||
IN CONST OC_BN_WORD * | B, | ||
IN CONST OC_BN_WORD * | N, | ||
IN OC_BN_WORD | N0Inv ) |
Calculates a row of the product of A and B mod N.
[in,out] | Result | The result buffer. |
[in] | NumWords | The number of Words of Result, B and N. |
[in] | AWord | The current row's Word of the multiplicant. |
[in] | B | The multiplier. |
[in] | N | The modulus. |
[in] | N0Inv | The Montgomery Inverse of N. |
Definition at line 292 of file BigNumMontgomery.c.
STATIC VOID BigNumMontMulRow0 | ( | IN OUT OC_BN_WORD * | Result, |
IN OC_BN_NUM_WORDS | NumWords, | ||
IN CONST OC_BN_WORD * | N, | ||
IN OC_BN_WORD | N0Inv ) |
This is an optimized version of the call BigNumMontMulRow (C, 0, A, N, N0Inv)
Calculates a row of the product of 0 and A mod N.
[in,out] | Result | The result buffer. |
[in] | NumWords | The number of Words of Result and N. |
[in] | N | The modulus. |
[in] | N0Inv | The Montgomery Inverse of N. |
Definition at line 449 of file BigNumMontgomery.c.
BOOLEAN BigNumPowMod | ( | IN OUT OC_BN_WORD * | Result, |
IN OC_BN_NUM_WORDS | NumWords, | ||
IN CONST OC_BN_WORD * | A, | ||
IN UINT32 | B, | ||
IN CONST OC_BN_WORD * | N, | ||
IN OC_BN_WORD | N0Inv, | ||
IN CONST OC_BN_WORD * | RSqrMod, | ||
IN OC_BN_WORD * | ATmp ) |
Caulculates the exponentiation of A with B mod N.
[in,out] | Result | The buffer to return the result into. |
[in] | NumWords | The number of Words of Result, A, N and RSqrMod. |
[in] | A | The base. |
[in] | B | The exponent. |
[in] | N | The modulus. |
[in] | N0Inv | The Montgomery Inverse of N. |
[in] | RSqrMod | Montgomery's R^2 mod N. |
[in] | ATmp | Scratch buffer of NumWords. |
Definition at line 555 of file BigNumMontgomery.c.
STATIC OC_BN_WORD BigNumWordAddMul | ( | OUT OC_BN_WORD * | Hi, |
IN OC_BN_WORD | C, | ||
IN OC_BN_WORD | A, | ||
IN OC_BN_WORD | B ) |
Calculates the sum of C and the product of A and B.
[out] | Hi | Buffer in which the high Word of the result is returned. |
[in] | C | The addend. |
[in] | A | The multiplicant. |
[in] | B | The multiplier. |
Definition at line 221 of file BigNumMontgomery.c.
STATIC OC_BN_WORD BigNumWordAddMulCarry | ( | OUT OC_BN_WORD * | Hi, |
IN OC_BN_WORD | C, | ||
IN OC_BN_WORD | A, | ||
IN OC_BN_WORD | B, | ||
IN OC_BN_WORD | Carry ) |
Calculates the sum of C, the product of A and B, and Carry.
[out] | Hi | Buffer in which the high Word of the result is returned. |
[in] | C | The addend. |
[in] | A | The multiplicant. |
[in] | B | The multiplier. |
[in] | Carry | The carry of the previous multiplication. |
Definition at line 256 of file BigNumMontgomery.c.