OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
BigNumLib.h File Reference
#include "CryptoInternal.h"

Go to the source code of this file.

Macros

#define OC_BN_WORD_SIZE   (sizeof (OC_BN_WORD))
 
#define OC_BN_WORD_NUM_BITS   ((OC_BN_NUM_BITS) (OC_BN_WORD_SIZE * OC_CHAR_BIT))
 
#define OC_BN_MAX_SIZE   ((OC_BN_SIZE) SIZE_64KB)
 
#define OC_BN_MAX_LEN   ((OC_BN_NUM_WORDS) (OC_BN_MAX_SIZE / OC_BN_WORD_SIZE))
 
#define OC_BN_SIZE(NumWords)
 
#define OC_BN_BITS(NumWords)
 
#define OC_BN_MONT_MAX_LEN   (OC_BN_MAX_LEN / 2U - 1U)
 
#define OC_BN_MONT_MAX_SIZE   (OC_BN_SIZE (OC_BN_MONT_MAX_LEN))
 
#define OC_BN_MONT_RSQR_LEN(NumWords)
 
#define OC_BN_MONT_RSQR_SIZE(NumWords)
 
#define BIG_NUM_MONT_PARAMS_SCRATCH_SIZE(NumWords)
 

Typedefs

typedef UINTN OC_BN_WORD
 
typedef UINT16 OC_BN_NUM_WORDS
 
typedef UINT32 OC_BN_SIZE
 
typedef UINT32 OC_BN_NUM_BITS
 

Functions

 STATIC_ASSERT (OC_BN_MAX_LEN<=MAX_UINTN/OC_BN_WORD_SIZE, "The definition of OC_BN_SIZE may cause an overflow")
 
 STATIC_ASSERT (OC_BN_BITS(OC_BN_MAX_LEN)<=MAX_UINTN/OC_CHAR_BIT, "The definition of OC_BN_BITS may cause an overflow")
 
VOID BigNumParseBuffer (IN OUT OC_BN_WORD *Result, IN OC_BN_NUM_WORDS NumWords, IN CONST UINT8 *Buffer, IN UINTN BufferSize)
 
OC_BN_WORD BigNumSwapWord (IN OC_BN_WORD Word)
 
 STATIC_ASSERT (OC_BN_MONT_RSQR_LEN(OC_BN_MONT_MAX_LEN)==OC_BN_MAX_LEN, "The definition of OC_BN_MONT_RSQR_LEN is faulty")
 
 STATIC_ASSERT (OC_BN_MONT_RSQR_SIZE(OC_BN_MONT_MAX_SIZE)<=MAX_UINTN/3, "The definition of BIG_NUM_MONT_PARAMS_SCRATCH_SIZE may cause an overflow")
 
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)
 
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)
 

Macro Definition Documentation

◆ BIG_NUM_MONT_PARAMS_SCRATCH_SIZE

#define BIG_NUM_MONT_PARAMS_SCRATCH_SIZE ( NumWords)
Value:
(OC_BN_MONT_RSQR_SIZE (NumWords) * 3U)
#define OC_BN_MONT_RSQR_SIZE(NumWords)
Definition BigNumLib.h:128

1 + 2 * NumWords for RSqr, and then twice more than that for Mod.

Parameters
[in]NumWordsThe number of Words of RSqrMod and N. Must be at most OC_BN_MONT_MAX_LEN.

Definition at line 136 of file BigNumLib.h.

◆ OC_BN_BITS

#define OC_BN_BITS ( NumWords)
Value:
#define OC_BN_SIZE(NumWords)
Definition BigNumLib.h:46
UINT32 OC_BN_NUM_BITS
Definition BigNumLib.h:37
#define OC_CHAR_BIT
Definition OcMiscLib.h:25

The size, in Bits, required to store a BigNum with NumWords words.

Parameters
[in]NumWordsThe number of Words. Must be at most OC_BN_MAX_LEN.

Definition at line 59 of file BigNumLib.h.

◆ OC_BN_MAX_LEN

#define OC_BN_MAX_LEN   ((OC_BN_NUM_WORDS) (OC_BN_MAX_SIZE / OC_BN_WORD_SIZE))

Definition at line 39 of file BigNumLib.h.

◆ OC_BN_MAX_SIZE

#define OC_BN_MAX_SIZE   ((OC_BN_SIZE) SIZE_64KB)

Definition at line 38 of file BigNumLib.h.

◆ OC_BN_MONT_MAX_LEN

#define OC_BN_MONT_MAX_LEN   (OC_BN_MAX_LEN / 2U - 1U)

Definition at line 106 of file BigNumLib.h.

◆ OC_BN_MONT_MAX_SIZE

#define OC_BN_MONT_MAX_SIZE   (OC_BN_SIZE (OC_BN_MONT_MAX_LEN))

Definition at line 107 of file BigNumLib.h.

◆ OC_BN_MONT_RSQR_LEN

#define OC_BN_MONT_RSQR_LEN ( NumWords)
Value:
((OC_BN_NUM_WORDS) (((NumWords) + 1U) * 2U))
UINT16 OC_BN_NUM_WORDS
Definition BigNumLib.h:35

The length, in BigNum words, of RSqr.

Parameters
[in]NumWordsThe number of Words of N. Must be at most OC_BN_MONT_MAX_LEN.

Definition at line 115 of file BigNumLib.h.

◆ OC_BN_MONT_RSQR_SIZE

#define OC_BN_MONT_RSQR_SIZE ( NumWords)
Value:
#define OC_BN_MONT_RSQR_LEN(NumWords)
Definition BigNumLib.h:115

The size, in Bytes, of RSqr.

Parameters
[in]NumWordsThe number of Words of N. Must be at most OC_BN_MONT_MAX_LEN.

Definition at line 128 of file BigNumLib.h.

◆ OC_BN_SIZE

#define OC_BN_SIZE ( NumWords)
Value:
((OC_BN_SIZE) (NumWords) * OC_BN_WORD_SIZE)
#define OC_BN_WORD_SIZE
Definition BigNumLib.h:30

The size, in Bytes, required to store a BigNum with NumWords words.

Parameters
[in]NumWordsThe number of Words. Must be at most OC_BN_MAX_LEN.

Definition at line 46 of file BigNumLib.h.

◆ OC_BN_WORD_NUM_BITS

#define OC_BN_WORD_NUM_BITS   ((OC_BN_NUM_BITS) (OC_BN_WORD_SIZE * OC_CHAR_BIT))

Definition at line 31 of file BigNumLib.h.

◆ OC_BN_WORD_SIZE

#define OC_BN_WORD_SIZE   (sizeof (OC_BN_WORD))

Definition at line 30 of file BigNumLib.h.

Typedef Documentation

◆ OC_BN_NUM_BITS

typedef UINT32 OC_BN_NUM_BITS

Definition at line 37 of file BigNumLib.h.

◆ OC_BN_NUM_WORDS

typedef UINT16 OC_BN_NUM_WORDS

Definition at line 35 of file BigNumLib.h.

◆ OC_BN_SIZE

typedef UINT32 OC_BN_SIZE

Definition at line 36 of file BigNumLib.h.

◆ OC_BN_WORD

typedef UINTN OC_BN_WORD

This library performs arbitrary precision arithmetic operations. For more details, please refer to the source files and function headers.

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. A BIGNUM word. This is at best an integer of the platform's natural size to optimize memory accesses and arithmetic operation count.

Definition at line 26 of file BigNumLib.h.

Function Documentation

◆ BigNumCalculateMontParams()

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.

Parameters
[in,out]RSqrModThe buffer to return R^2 mod N into.
[in]NumWordsThe number of Words of RSqrMod and N. Must be at most OC_BN_MONT_MAX_LEN.
[in]NThe Montgomery Modulus.
[in]ScratchScratch buffer BIG_NUM_MONT_PARAMS_SCRATCH_SIZE(NumWords).
Returns
The Montgomery Inverse of N.

Definition at line 156 of file BigNumMontgomery.c.

◆ BigNumParseBuffer()

VOID BigNumParseBuffer ( IN OUT OC_BN_WORD * Result,
IN OC_BN_NUM_WORDS NumWords,
IN CONST UINT8 * Buffer,
IN UINTN BufferSize )

Parses a data array into a number. The buffer size must be a multiple of the Word size. The length of Result must precisely fit the required size.

Parameters
[in,out]ResultThe buffer to store the result in.
[in]NumWordsThe number of Words of Result.
[in]BufferThe buffer to parse.
[in]BufferSizeThe size, in bytes, of Buffer.

Definition at line 748 of file BigNumPrimitives.c.

◆ BigNumPowMod()

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.

Parameters
[in,out]ResultThe buffer to return the result into.
[in]NumWordsThe number of Words of Result, A, N and RSqrMod.
[in]AThe base.
[in]BThe exponent.
[in]NThe modulus.
[in]N0InvThe Montgomery Inverse of N.
[in]RSqrModMontgomery's R^2 mod N.
[in]ATmpScratch buffer of NumWords.
Returns
Whether the operation was completes successfully.

Definition at line 555 of file BigNumMontgomery.c.

◆ BigNumSwapWord()

OC_BN_WORD BigNumSwapWord ( IN OC_BN_WORD Word)

Swaps the byte order of Word.

Parameters
[in]WordThe Word to swap.
Returns
The byte-swapped value of Word.

Definition at line 44 of file BigNumPrimitives.c.

◆ STATIC_ASSERT() [1/4]

STATIC_ASSERT ( OC_BN_BITS(OC_BN_MAX_LEN)<=MAX_UINTN/ OC_CHAR_BIT,
"The definition of OC_BN_BITS may cause an overflow"  )

◆ STATIC_ASSERT() [2/4]

STATIC_ASSERT ( OC_BN_MAX_LEN<=MAX_UINTN/ OC_BN_WORD_SIZE,
"The definition of OC_BN_SIZE may cause an overflow"  )

◆ STATIC_ASSERT() [3/4]

STATIC_ASSERT ( OC_BN_MONT_RSQR_LEN(OC_BN_MONT_MAX_LEN) = =OC_BN_MAX_LEN,
"The definition of OC_BN_MONT_RSQR_LEN is faulty"  )

◆ STATIC_ASSERT() [4/4]

STATIC_ASSERT ( OC_BN_MONT_RSQR_SIZE(OC_BN_MONT_MAX_SIZE)<=MAX_UINTN/ 3,
"The definition of BIG_NUM_MONT_PARAMS_SCRATCH_SIZE may cause an overflow"  )