TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptBnNull.c File Reference

Go to the source code of this file.

Functions

VOID *EFIAPI BigNumInit (VOID)
 
VOID *EFIAPI BigNumFromBin (IN CONST UINT8 *Buf, IN UINTN Len)
 
INTN EFIAPI BigNumToBin (IN CONST VOID *Bn, OUT UINT8 *Buf)
 
VOID EFIAPI BigNumFree (IN VOID *Bn, IN BOOLEAN Clear)
 
BOOLEAN EFIAPI BigNumAdd (IN CONST VOID *BnA, IN CONST VOID *BnB, OUT VOID *BnRes)
 
BOOLEAN EFIAPI BigNumSub (IN CONST VOID *BnA, IN CONST VOID *BnB, OUT VOID *BnRes)
 
BOOLEAN EFIAPI BigNumMod (IN CONST VOID *BnA, IN CONST VOID *BnB, OUT VOID *BnRes)
 
BOOLEAN EFIAPI BigNumExpMod (IN CONST VOID *BnA, IN CONST VOID *BnP, IN CONST VOID *BnM, OUT VOID *BnRes)
 
BOOLEAN EFIAPI BigNumInverseMod (IN CONST VOID *BnA, IN CONST VOID *BnM, OUT VOID *BnRes)
 
BOOLEAN EFIAPI BigNumDiv (IN CONST VOID *BnA, IN CONST VOID *BnB, OUT VOID *BnRes)
 
BOOLEAN EFIAPI BigNumMulMod (IN CONST VOID *BnA, IN CONST VOID *BnB, IN CONST VOID *BnM, OUT VOID *BnRes)
 
INTN EFIAPI BigNumCmp (IN CONST VOID *BnA, IN CONST VOID *BnB)
 
UINTN EFIAPI BigNumBits (IN CONST VOID *Bn)
 
UINTN EFIAPI BigNumBytes (IN CONST VOID *Bn)
 
BOOLEAN EFIAPI BigNumIsWord (IN CONST VOID *Bn, IN UINTN Num)
 
BOOLEAN EFIAPI BigNumIsOdd (IN CONST VOID *Bn)
 
VOID *EFIAPI BigNumCopy (OUT VOID *BnDst, IN CONST VOID *BnSrc)
 
CONST VOID *EFIAPI BigNumValueOne (VOID)
 
BOOLEAN EFIAPI BigNumRShift (IN CONST VOID *Bn, IN UINTN N, OUT VOID *BnRes)
 
VOID EFIAPI BigNumConstTime (IN VOID *Bn)
 
BOOLEAN EFIAPI BigNumSqrMod (IN CONST VOID *BnA, IN CONST VOID *BnM, OUT VOID *BnRes)
 
VOID *EFIAPI BigNumNewContext (VOID)
 
VOID EFIAPI BigNumContextFree (IN VOID *BnCtx)
 
BOOLEAN EFIAPI BigNumSetUint (IN VOID *Bn, IN UINTN Val)
 
BOOLEAN EFIAPI BigNumAddMod (IN CONST VOID *BnA, IN CONST VOID *BnB, IN CONST VOID *BnM, OUT VOID *BnRes)
 

Detailed Description

Big number API implementation based on MbedTLS

Copyright (c) 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file CryptBnNull.c.

Function Documentation

◆ BigNumAdd()

BOOLEAN EFIAPI BigNumAdd ( IN CONST VOID *  BnA,
IN CONST VOID *  BnB,
OUT VOID *  BnRes 
)

Calculate the sum of two Big Numbers. Please note, all "out" Big number arguments should be properly initialized by calling to BigNumInit() or BigNumFromBin() functions.

Parameters
[in]BnABig number.
[in]BnBBig number.
[out]BnResThe result of BnA + BnB.
Return values
TRUEOn success.
FALSEOtherwise.

Definition at line 96 of file CryptBnNull.c.

◆ BigNumAddMod()

BOOLEAN EFIAPI BigNumAddMod ( IN CONST VOID *  BnA,
IN CONST VOID *  BnB,
IN CONST VOID *  BnM,
OUT VOID *  BnRes 
)

Add two Big Numbers modulo BnM.

Parameters
[in]BnABig number.
[in]BnBBig number.
[in]BnMBig number (modulo).
[out]BnResThe result, such that (BnA + BnB) % BnM.
Return values
TRUEOn success.
FALSEOtherwise.

Definition at line 511 of file CryptBnNull.c.

◆ BigNumBits()

UINTN EFIAPI BigNumBits ( IN CONST VOID *  Bn)

Get number of bits in Bn.

Parameters
[in]BnBig number.
Return values
Numberof bits.

Definition at line 284 of file CryptBnNull.c.

◆ BigNumBytes()

UINTN EFIAPI BigNumBytes ( IN CONST VOID *  Bn)

Get number of bytes in Bn.

Parameters
[in]BnBig number.
Return values
Numberof bytes.

Definition at line 301 of file CryptBnNull.c.

◆ BigNumCmp()

INTN EFIAPI BigNumCmp ( IN CONST VOID *  BnA,
IN CONST VOID *  BnB 
)

Compare two Big Numbers.

Parameters
[in]BnABig number.
[in]BnBBig number.
Return values
0BnA == BnB.
1BnA > BnB.
-1BnA < BnB.

Definition at line 266 of file CryptBnNull.c.

◆ BigNumConstTime()

VOID EFIAPI BigNumConstTime ( IN VOID *  Bn)

Mark Big Number for constant time computations. This function should be called before any constant time computations are performed on the given Big number.

Parameters
[in]BnBig number

Definition at line 416 of file CryptBnNull.c.

◆ BigNumContextFree()

VOID EFIAPI BigNumContextFree ( IN VOID *  BnCtx)

Free Big Number context that was allocated with BigNumNewContext().

Parameters
[in]BnCtxBig number context to free.

Definition at line 471 of file CryptBnNull.c.

◆ BigNumCopy()

VOID *EFIAPI BigNumCopy ( OUT VOID *  BnDst,
IN CONST VOID *  BnSrc 
)

Copy Big number.

Parameters
[out]BnDstDestination.
[in]BnSrcSource.
Return values
BnDston success.
NULLotherwise.

Definition at line 358 of file CryptBnNull.c.

◆ BigNumDiv()

BOOLEAN EFIAPI BigNumDiv ( IN CONST VOID *  BnA,
IN CONST VOID *  BnB,
OUT VOID *  BnRes 
)

Divide two Big Numbers. Please note, all "out" Big number arguments should be properly initialized by calling to BigNumInit() or BigNumFromBin() functions.

Parameters
[in]BnABig number.
[in]BnBBig number.
[out]BnResThe result, such that BnA / BnB.
Return values
TRUEOn success.
FALSEOtherwise.

Definition at line 218 of file CryptBnNull.c.

◆ BigNumExpMod()

BOOLEAN EFIAPI BigNumExpMod ( IN CONST VOID *  BnA,
IN CONST VOID *  BnP,
IN CONST VOID *  BnM,
OUT VOID *  BnRes 
)

Compute BnA to the BnP-th power modulo BnM. Please note, all "out" Big number arguments should be properly initialized by calling to BigNumInit() or BigNumFromBin() functions.

Parameters
[in]BnABig number.
[in]BnPBig number (power).
[in]BnMBig number (modulo).
[out]BnResThe result of (BnA ^ BnP) % BnM.
Return values
TRUEOn success.
FALSEOtherwise.

Definition at line 169 of file CryptBnNull.c.

◆ BigNumFree()

VOID EFIAPI BigNumFree ( IN VOID *  Bn,
IN BOOLEAN  Clear 
)

Free the Big Number.

Parameters
[in]BnBig number to free.
[in]ClearTRUE if the buffer should be cleared.

Definition at line 74 of file CryptBnNull.c.

◆ BigNumFromBin()

VOID *EFIAPI BigNumFromBin ( IN CONST UINT8 *  Buf,
IN UINTN  Len 
)

Allocate new Big Number and assign the provided value to it.

Parameters
[in]BufBig endian encoded buffer.
[in]LenBuffer length.
Return values
NewBigNum opaque structure or NULL on failure.

Definition at line 37 of file CryptBnNull.c.

◆ BigNumInit()

VOID *EFIAPI BigNumInit ( VOID  )

Allocate new Big Number.

Return values
NewBigNum opaque structure or NULL on failure.

Definition at line 19 of file CryptBnNull.c.

◆ BigNumInverseMod()

BOOLEAN EFIAPI BigNumInverseMod ( IN CONST VOID *  BnA,
IN CONST VOID *  BnM,
OUT VOID *  BnRes 
)

Compute BnA inverse modulo BnM. Please note, all "out" Big number arguments should be properly initialized by calling to BigNumInit() or BigNumFromBin() functions.

Parameters
[in]BnABig number.
[in]BnMBig number (modulo).
[out]BnResThe result, such that (BnA * BnRes) % BnM == 1.
Return values
TRUEOn success.
FALSEOtherwise.

Definition at line 194 of file CryptBnNull.c.

◆ BigNumIsOdd()

BOOLEAN EFIAPI BigNumIsOdd ( IN CONST VOID *  Bn)

Checks if Big Number is odd.

Parameters
[in]BnBig number.
Return values
TRUEBn is odd (Bn % 2 == 1).
FALSEotherwise.

Definition at line 339 of file CryptBnNull.c.

◆ BigNumIsWord()

BOOLEAN EFIAPI BigNumIsWord ( IN CONST VOID *  Bn,
IN UINTN  Num 
)

Checks if Big Number equals to the given Num.

Parameters
[in]BnBig number.
[in]NumNumber.
Return values
TRUEiff Bn == Num.
FALSEotherwise.

Definition at line 320 of file CryptBnNull.c.

◆ BigNumMod()

BOOLEAN EFIAPI BigNumMod ( IN CONST VOID *  BnA,
IN CONST VOID *  BnB,
OUT VOID *  BnRes 
)

Calculate remainder: BnRes = BnA % BnB. Please note, all "out" Big number arguments should be properly initialized by calling to BigNumInit() or BigNumFromBin() functions.

Parameters
[in]BnABig number.
[in]BnBBig number.
[out]BnResThe result of BnA % BnB.
Return values
TRUEOn success.
FALSEOtherwise.

Definition at line 144 of file CryptBnNull.c.

◆ BigNumMulMod()

BOOLEAN EFIAPI BigNumMulMod ( IN CONST VOID *  BnA,
IN CONST VOID *  BnB,
IN CONST VOID *  BnM,
OUT VOID *  BnRes 
)

Multiply two Big Numbers modulo BnM. Please note, all "out" Big number arguments should be properly initialized by calling to BigNumInit() or BigNumFromBin() functions.

Parameters
[in]BnABig number.
[in]BnBBig number.
[in]BnMBig number (modulo).
[out]BnResThe result, such that (BnA * BnB) % BnM.
Return values
TRUEOn success.
FALSEOtherwise.

Definition at line 243 of file CryptBnNull.c.

◆ BigNumNewContext()

VOID *EFIAPI BigNumNewContext ( VOID  )

Create new Big Number computation context. This is an opaque structure which should be passed to any function that requires it. The BN context is needed to optimize calculations and expensive allocations.

Return values
BigNumber context struct or NULL on failure.

Definition at line 456 of file CryptBnNull.c.

◆ BigNumRShift()

BOOLEAN EFIAPI BigNumRShift ( IN CONST VOID *  Bn,
IN UINTN  N,
OUT VOID *  BnRes 
)

Shift right Big Number. Please note, all "out" Big number arguments should be properly initialized by calling to BigNumInit() or BigNumFromBin() functions.

Parameters
[in]BnBig number.
[in]NNumber of bits to shift.
[out]BnResThe result.
Return values
TRUEOn success.
FALSEOtherwise.

Definition at line 397 of file CryptBnNull.c.

◆ BigNumSetUint()

BOOLEAN EFIAPI BigNumSetUint ( IN VOID *  Bn,
IN UINTN  Val 
)

Set Big Number to a given value.

Parameters
[in]BnBig number to set.
[in]ValValue to set.
Return values
TRUEOn success.
FALSEOtherwise.

Definition at line 489 of file CryptBnNull.c.

◆ BigNumSqrMod()

BOOLEAN EFIAPI BigNumSqrMod ( IN CONST VOID *  BnA,
IN CONST VOID *  BnM,
OUT VOID *  BnRes 
)

Calculate square modulo. Please note, all "out" Big number arguments should be properly initialized by calling to BigNumInit() or BigNumFromBin() functions.

Parameters
[in]BnABig number.
[in]BnMBig number (modulo).
[out]BnResThe result, such that (BnA ^ 2) % BnM.
Return values
TRUEOn success.
FALSEOtherwise.

Definition at line 437 of file CryptBnNull.c.

◆ BigNumSub()

BOOLEAN EFIAPI BigNumSub ( IN CONST VOID *  BnA,
IN CONST VOID *  BnB,
OUT VOID *  BnRes 
)

Subtract two Big Numbers. Please note, all "out" Big number arguments should be properly initialized by calling to BigNumInit() or BigNumFromBin() functions.

Parameters
[in]BnABig number.
[in]BnBBig number.
[out]BnResThe result of BnA - BnB.
Return values
TRUEOn success.
FALSEOtherwise.

Definition at line 120 of file CryptBnNull.c.

◆ BigNumToBin()

INTN EFIAPI BigNumToBin ( IN CONST VOID *  Bn,
OUT UINT8 *  Buf 
)

Convert the absolute value of Bn into big-endian form and store it at Buf. The Buf array should have at least BigNumBytes() in it.

Parameters
[in]BnBig number to convert.
[out]BufOutput buffer.
Return values
Thelength of the big-endian number placed at Buf or -1 on error.

Definition at line 57 of file CryptBnNull.c.

◆ BigNumValueOne()

CONST VOID *EFIAPI BigNumValueOne ( VOID  )

Get constant Big number with value of "1". This may be used to save expensive allocations.

Return values
BigNumber with value of 1.

Definition at line 375 of file CryptBnNull.c.