[edk2-devel] [PATCH 2/2] CryptoPkg: Add BigNum NullLib

yi1 li yi1.li at intel.com
Tue Feb 8 08:30:39 UTC 2022


Hi
I have created Bugzilla to describe why we need to add  this feature: https://bugzilla.tianocore.org/show_bug.cgi?id=3828.
We will provide related information by comments such Bin size difference and more.

Thanks!
-----Original Message-----
From: Yao, Jiewen <jiewen.yao at intel.com> 
Sent: Monday, January 31, 2022 9:10 AM
To: Li, Yi1 <yi1.li at intel.com>
Cc: devel at edk2.groups.io; Wang, Jian J <jian.j.wang at intel.com>; Xiaoyu Lu <xiaoyux.lu at intel.com>; Jiang, Guomin <guomin.jiang at intel.com>
Subject: Re: [PATCH 2/2] CryptoPkg: Add BigNum NullLib

Hi
Then I don’t understand why we need this feature. Please submit a bugzilla to describe the problem statement. (Not the solution)

Also please provide the size difference in pei and smm before and after your patch.
Not only the crypto bin but also the individual driver using crypto lib, such as var auth driver. We 

thank you!
Yao, Jiewen


> 在 2022年1月31日,上午1:08,Li, Yi1 <yi1.li at intel.com> 写道:
> 
> Hi Jiewen
> With build cmd 'build -p .\Edk2\CryptoPkg\CryptoPkg.dsc -t VS2019 -a X64 -D CRYPTO_SERVICES=ALL':
> CryptDxe.efi will be 813,504 bytes without CryptBn; will be 815,040 
> bytes with CryptBnNull; will be 815,360 bytes with CryptBn; This patch 
> has little effect on binary size since the dependent Openssl library is already enabled in EDK2.
> And CryptBnNull can also be used in drivers(such pei,smm) which do not need Bn instance.
> 
> Thanks.
> -----Original Message-----
> From: Yao, Jiewen <jiewen.yao at intel.com>
> Sent: Sunday, January 30, 2022 8:04 AM
> To: Li, Yi1 <yi1.li at intel.com>
> Cc: devel at edk2.groups.io; Wang, Jian J <jian.j.wang at intel.com>; Xiaoyu 
> Lu <xiaoyux.lu at intel.com>; Jiang, Guomin <guomin.jiang at intel.com>
> Subject: Re: [PATCH 2/2] CryptoPkg: Add BigNum NullLib
> 
> thank you
> since you are talking about size optimization, would you please share the result?
> 
> thank you!
> Yao, Jiewen
> 
> 
>> 在 2022年1月30日,上午6:10,Li, Yi1 <yi1.li at intel.com> 写道:
>> 
>> This patch is used to add CryptBnNull library, which is used to 
>> optimize code size.
>> 
>> Signed-off-by: yi1 li <yi1.li at intel.com>
>> 
>> Cc: Jiewen Yao <jiewen.yao at intel.com>
>> Cc: Jian J Wang <jian.j.wang at intel.com>
>> Cc: Xiaoyu Lu <xiaoyux.lu at intel.com>
>> Cc: Guomin Jiang <guomin.jiang at intel.com>
>> ---
>> .../Library/BaseCryptLib/Bn/CryptBnNull.c     | 525 ++++++++++++++++++
>> .../Library/BaseCryptLib/PeiCryptLib.inf      |   2 +-
>> .../Library/BaseCryptLib/SmmCryptLib.inf      |   2 +-
>> .../BaseCryptLibNull/BaseCryptLibNull.inf     |   1 +
>> .../Library/BaseCryptLibNull/Bn/CryptBnNull.c | 525 
>> ++++++++++++++++++
>> 5 files changed, 1053 insertions(+), 2 deletions(-) create mode 
>> 100644 CryptoPkg/Library/BaseCryptLib/Bn/CryptBnNull.c
>> create mode 100644 
>> CryptoPkg/Library/BaseCryptLibNull/Bn/CryptBnNull.c
>> 
>> diff --git a/CryptoPkg/Library/BaseCryptLib/Bn/CryptBnNull.c
>> b/CryptoPkg/Library/BaseCryptLib/Bn/CryptBnNull.c
>> new file mode 100644
>> index 000000000000..9f220ba41058
>> --- /dev/null
>> +++ b/CryptoPkg/Library/BaseCryptLib/Bn/CryptBnNull.c
>> @@ -0,0 +1,525 @@
>> +/** @file
>> +  Big number API implementation based on OpenSSL
>> +
>> +  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>> +
>> +**/
>> +
>> +#include <Library/BaseCryptLib.h>
>> +#include <Library/DebugLib.h>
>> +
>> +/**
>> +  Allocate new Big Number.
>> +
>> +  @retval New BigNum opaque structure or NULL on failure.
>> +**/
>> +VOID *
>> +EFIAPI
>> +BigNumInit (
>> +  VOID
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return NULL;
>> +}
>> +
>> +/**
>> +  Allocate new Big Number and assign the provided value to it.
>> +
>> +  @param[in]   Buf    Big endian encoded buffer.
>> +  @param[in]   Len    Buffer length.
>> +
>> +  @retval New BigNum opaque structure or NULL on failure.
>> +**/
>> +VOID *
>> +EFIAPI
>> +BigNumFromBin (
>> +  IN CONST UINT8  *Buf,
>> +  IN UINTN        Len
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return NULL;
>> +}
>> +
>> +/**
>> +  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.
>> +
>> +  @param[in]   Bn     Big number to convert.
>> +  @param[out]  Buf    Output buffer.
>> +
>> +  @retval The length of the big-endian number placed at Buf or -1 on error.
>> +**/
>> +INTN
>> +EFIAPI
>> +BigNumToBin (
>> +  IN VOID    *Bn,
>> +  OUT UINT8  *Buf
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return -1;
>> +}
>> +
>> +/**
>> +  Free the Big Number.
>> +
>> +  @param[in]   Bn      Big number to free.
>> +  @param[in]   Clear   TRUE if the buffer should be cleared.
>> +**/
>> +VOID
>> +EFIAPI
>> +BigNumFree (
>> +  IN VOID     *Bn,
>> +  IN BOOLEAN  Clear
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +}
>> +
>> +/**
>> +  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.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnB     Big number.
>> +  @param[out]  BnRes   The result of BnA + BnB.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumAdd (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnB,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Subtract two Big Numbers.
>> +  Please note, all "out" Big number arguments should be properly 
>> +initialized
>> +  by calling to BigNumInit() or BigNumFromBin() functions.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnB     Big number.
>> +  @param[out]  BnRes   The result of BnA - BnB.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumSub (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnB,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Calculate remainder: BnRes = BnA % BnB.
>> +  Please note, all "out" Big number arguments should be properly 
>> +initialized
>> +  by calling to BigNumInit() or BigNumFromBin() functions.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnB     Big number.
>> +  @param[out]  BnRes   The result of BnA % BnB.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumMod (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnB,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  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.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnP     Big number (power).
>> +  @param[in]   BnM     Big number (modulo).
>> +  @param[out]  BnRes   The result of (BnA ^ BnP) % BnM.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumExpMod (
>> +  IN VOID   *BnA,
>> +  IN VOID   *BnP,
>> +  IN VOID   *BnM,
>> +  OUT VOID  *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Compute BnA inverse modulo BnM.
>> +  Please note, all "out" Big number arguments should be properly 
>> +initialized
>> +  by calling to BigNumInit() or BigNumFromBin() functions.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnM     Big number (modulo).
>> +  @param[out]  BnRes   The result, such that (BnA * BnRes) % BnM == 1.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumInverseMod (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnM,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Divide two Big Numbers.
>> +  Please note, all "out" Big number arguments should be properly 
>> +initialized
>> +  by calling to BigNumInit() or BigNumFromBin() functions.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnM     Big number (modulo).
>> +  @param[out]  BnRes   The result, such that BnA / BnB.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumDiv (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnM,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Multiply two Big Numbers modulo BnM.
>> +  Please note, all "out" Big number arguments should be properly 
>> +initialized
>> +  by calling to BigNumInit() or BigNumFromBin() functions.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnB     Big number.
>> +  @param[in]   BnM     Big number (modulo).
>> +  @param[out]  BnRes   The result, such that (BnA * BnB) % BnM.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumMulMod (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnB,
>> +  IN CONST VOID  *BnM,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Compare two Big Numbers.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnB     Big number.
>> +
>> +  @retval 0          BnA == BnB.
>> +  @retval 1          BnA > BnB.
>> +  @retval -1         BnA < BnB.
>> +**/
>> +INTN
>> +EFIAPI
>> +BigNumCmp (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnB
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return 0;
>> +}
>> +
>> +/**
>> +  Get number of bits in Bn.
>> +
>> +  @param[in]   Bn     Big number.
>> +
>> +  @retval Number of bits.
>> +**/
>> +UINTN
>> +EFIAPI
>> +BigNumBits (
>> +  IN CONST VOID  *Bn
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return 0;
>> +}
>> +
>> +/**
>> +  Get number of bytes in Bn.
>> +
>> +  @param[in]   Bn     Big number.
>> +
>> +  @retval Number of bytes.
>> +**/
>> +UINTN
>> +EFIAPI
>> +BigNumBytes (
>> +  IN CONST VOID  *Bn
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return 0;
>> +}
>> +
>> +/**
>> +  Checks if Big Number equals to the given Num.
>> +
>> +  @param[in]   Bn     Big number.
>> +  @param[in]   Num    Number.
>> +
>> +  @retval TRUE   iff Bn == Num.
>> +  @retval FALSE  otherwise.
>> +**/
>> +BOOLEAN
>> +EFIAPI
>> +BigNumIsWord (
>> +  IN CONST VOID  *Bn,
>> +  IN UINTN       Num
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return FALSE;
>> +}
>> +
>> +/**
>> +  Checks if Big Number is odd.
>> +
>> +  @param[in]   Bn     Big number.
>> +
>> +  @retval TRUE   Bn is odd (Bn % 2 == 1).
>> +  @retval FALSE  otherwise.
>> +**/
>> +BOOLEAN
>> +EFIAPI
>> +BigNumIsOdd (
>> +  IN CONST VOID  *Bn
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return FALSE;
>> +}
>> +
>> +/**
>> +  Copy Big number.
>> +
>> +  @param[out]  BnDst     Destination.
>> +  @param[in]   BnSrc     Source.
>> +
>> +  @retval BnDst on success.
>> +  @retval NULL otherwise.
>> +**/
>> +VOID *
>> +EFIAPI
>> +BigNumCopy (
>> +  OUT VOID       *BnDst,
>> +  IN CONST VOID  *BnSrc
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return NULL;
>> +}
>> +
>> +/**
>> +  Get constant Big number with value of "1".
>> +  This may be used to save expensive allocations.
>> +
>> +  @retval Big Number with value of 1.
>> +**/
>> +CONST VOID *
>> +EFIAPI
>> +BigNumValueOne (
>> +  VOID
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return NULL;
>> +}
>> +
>> +/**
>> +  Shift right Big Number.
>> +  Please note, all "out" Big number arguments should be properly 
>> +initialized
>> +  by calling to BigNumInit() or BigNumFromBin() functions.
>> +
>> +  @param[in]   Bn      Big number.
>> +  @param[in]   n       Number of bits to shift.
>> +  @param[out]  BnRes   The result.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumRShift (
>> +  IN CONST VOID  *Bn,
>> +  IN UINTN       n,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Mark Big Number for constant time computations.
>> +  This function should be called before any constant time 
>> +computations are
>> +  performed on the given Big number.
>> +
>> +  @param[in]   Bn     Big number.
>> +**/
>> +VOID
>> +EFIAPI
>> +BigNumConsttime (
>> +  IN VOID  *Bn
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +}
>> +
>> +/**
>> +  Calculate square modulo.
>> +  Please note, all "out" Big number arguments should be properly 
>> +initialized
>> +  by calling to BigNumInit() or BigNumFromBin() functions.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnM     Big number (modulo).
>> +  @param[out]  BnRes   The result, such that (BnA ^ 2) % BnM.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumSqrMod (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnM,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  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.
>> +
>> +  @retval Big Number context struct or NULL on failure.
>> +**/
>> +VOID *
>> +EFIAPI
>> +BigNumNewContext (
>> +  VOID
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return NULL;
>> +}
>> +
>> +/**
>> +  Free Big Number context that was allocated with BigNumNewContext().
>> +
>> +  @param[in]   BnCtx     Big number context to free.
>> +**/
>> +VOID
>> +EFIAPI
>> +BigNumContextFree (
>> +  IN VOID  *BnCtx
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +}
>> +
>> +/**
>> +  Set Big Number to a given value.
>> +
>> +  @param[in]   Bn     Big number to set.
>> +  @param[in]   Val    Value to set.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumSetUint (
>> +  IN VOID   *Bn,
>> +  IN UINTN  Val
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Add two Big Numbers modulo BnM.
>> +
>> +  @param[in]   BnA       Big number.
>> +  @param[in]   BnB       Big number.
>> +  @param[in]   BnM       Big number (modulo).
>> +  @param[out]  BnRes     The result, such that (BnA + BnB) % BnM.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumAddMod (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnB,
>> +  IN CONST VOID  *BnM,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> diff --git a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
>> b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
>> index 75d87afbdc03..d080e665c218 100644
>> --- a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
>> +++ b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
>> @@ -59,7 +59,7 @@
>>  Pk/CryptRsaPssSignNull.c
>>  Pem/CryptPemNull.c
>>  Rand/CryptRandNull.c
>> -  Bn/CryptBn.c
>> +  Bn/CryptBnNull.c
>> 
>>  SysCall/CrtWrapper.c
>>  SysCall/ConstantTimeClock.c
>> diff --git a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
>> b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
>> index 420cef88efb1..8a3fec9b076c 100644
>> --- a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
>> +++ b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
>> @@ -56,7 +56,7 @@
>>  Pk/CryptRsaPss.c
>>  Pk/CryptRsaPssSignNull.c
>>  Pem/CryptPem.c
>> -  Bn/CryptBn.c
>> +  Bn/CryptBnNull.c
>>  SysCall/CrtWrapper.c
>>  SysCall/ConstantTimeClock.c
>>  SysCall/BaseMemAllocation.c
>> diff --git a/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf
>> b/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf
>> index faf959827b90..1fb4d5c54d4f 100644
>> --- a/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf
>> +++ b/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf
>> @@ -52,6 +52,7 @@
>>  Rand/CryptRandNull.c
>>  Pk/CryptRsaPssNull.c
>>  Pk/CryptRsaPssSignNull.c
>> +  Bn/CryptBnNull.c
>> 
>> [Packages]
>>  MdePkg/MdePkg.dec
>> diff --git a/CryptoPkg/Library/BaseCryptLibNull/Bn/CryptBnNull.c
>> b/CryptoPkg/Library/BaseCryptLibNull/Bn/CryptBnNull.c
>> new file mode 100644
>> index 000000000000..9f220ba41058
>> --- /dev/null
>> +++ b/CryptoPkg/Library/BaseCryptLibNull/Bn/CryptBnNull.c
>> @@ -0,0 +1,525 @@
>> +/** @file
>> +  Big number API implementation based on OpenSSL
>> +
>> +  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>> +
>> +**/
>> +
>> +#include <Library/BaseCryptLib.h>
>> +#include <Library/DebugLib.h>
>> +
>> +/**
>> +  Allocate new Big Number.
>> +
>> +  @retval New BigNum opaque structure or NULL on failure.
>> +**/
>> +VOID *
>> +EFIAPI
>> +BigNumInit (
>> +  VOID
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return NULL;
>> +}
>> +
>> +/**
>> +  Allocate new Big Number and assign the provided value to it.
>> +
>> +  @param[in]   Buf    Big endian encoded buffer.
>> +  @param[in]   Len    Buffer length.
>> +
>> +  @retval New BigNum opaque structure or NULL on failure.
>> +**/
>> +VOID *
>> +EFIAPI
>> +BigNumFromBin (
>> +  IN CONST UINT8  *Buf,
>> +  IN UINTN        Len
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return NULL;
>> +}
>> +
>> +/**
>> +  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.
>> +
>> +  @param[in]   Bn     Big number to convert.
>> +  @param[out]  Buf    Output buffer.
>> +
>> +  @retval The length of the big-endian number placed at Buf or -1 on error.
>> +**/
>> +INTN
>> +EFIAPI
>> +BigNumToBin (
>> +  IN VOID    *Bn,
>> +  OUT UINT8  *Buf
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return -1;
>> +}
>> +
>> +/**
>> +  Free the Big Number.
>> +
>> +  @param[in]   Bn      Big number to free.
>> +  @param[in]   Clear   TRUE if the buffer should be cleared.
>> +**/
>> +VOID
>> +EFIAPI
>> +BigNumFree (
>> +  IN VOID     *Bn,
>> +  IN BOOLEAN  Clear
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +}
>> +
>> +/**
>> +  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.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnB     Big number.
>> +  @param[out]  BnRes   The result of BnA + BnB.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumAdd (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnB,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Subtract two Big Numbers.
>> +  Please note, all "out" Big number arguments should be properly 
>> +initialized
>> +  by calling to BigNumInit() or BigNumFromBin() functions.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnB     Big number.
>> +  @param[out]  BnRes   The result of BnA - BnB.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumSub (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnB,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Calculate remainder: BnRes = BnA % BnB.
>> +  Please note, all "out" Big number arguments should be properly 
>> +initialized
>> +  by calling to BigNumInit() or BigNumFromBin() functions.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnB     Big number.
>> +  @param[out]  BnRes   The result of BnA % BnB.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumMod (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnB,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  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.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnP     Big number (power).
>> +  @param[in]   BnM     Big number (modulo).
>> +  @param[out]  BnRes   The result of (BnA ^ BnP) % BnM.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumExpMod (
>> +  IN VOID   *BnA,
>> +  IN VOID   *BnP,
>> +  IN VOID   *BnM,
>> +  OUT VOID  *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Compute BnA inverse modulo BnM.
>> +  Please note, all "out" Big number arguments should be properly 
>> +initialized
>> +  by calling to BigNumInit() or BigNumFromBin() functions.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnM     Big number (modulo).
>> +  @param[out]  BnRes   The result, such that (BnA * BnRes) % BnM == 1.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumInverseMod (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnM,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Divide two Big Numbers.
>> +  Please note, all "out" Big number arguments should be properly 
>> +initialized
>> +  by calling to BigNumInit() or BigNumFromBin() functions.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnM     Big number (modulo).
>> +  @param[out]  BnRes   The result, such that BnA / BnB.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumDiv (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnM,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Multiply two Big Numbers modulo BnM.
>> +  Please note, all "out" Big number arguments should be properly 
>> +initialized
>> +  by calling to BigNumInit() or BigNumFromBin() functions.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnB     Big number.
>> +  @param[in]   BnM     Big number (modulo).
>> +  @param[out]  BnRes   The result, such that (BnA * BnB) % BnM.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumMulMod (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnB,
>> +  IN CONST VOID  *BnM,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Compare two Big Numbers.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnB     Big number.
>> +
>> +  @retval 0          BnA == BnB.
>> +  @retval 1          BnA > BnB.
>> +  @retval -1         BnA < BnB.
>> +**/
>> +INTN
>> +EFIAPI
>> +BigNumCmp (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnB
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return 0;
>> +}
>> +
>> +/**
>> +  Get number of bits in Bn.
>> +
>> +  @param[in]   Bn     Big number.
>> +
>> +  @retval Number of bits.
>> +**/
>> +UINTN
>> +EFIAPI
>> +BigNumBits (
>> +  IN CONST VOID  *Bn
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return 0;
>> +}
>> +
>> +/**
>> +  Get number of bytes in Bn.
>> +
>> +  @param[in]   Bn     Big number.
>> +
>> +  @retval Number of bytes.
>> +**/
>> +UINTN
>> +EFIAPI
>> +BigNumBytes (
>> +  IN CONST VOID  *Bn
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return 0;
>> +}
>> +
>> +/**
>> +  Checks if Big Number equals to the given Num.
>> +
>> +  @param[in]   Bn     Big number.
>> +  @param[in]   Num    Number.
>> +
>> +  @retval TRUE   iff Bn == Num.
>> +  @retval FALSE  otherwise.
>> +**/
>> +BOOLEAN
>> +EFIAPI
>> +BigNumIsWord (
>> +  IN CONST VOID  *Bn,
>> +  IN UINTN       Num
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return FALSE;
>> +}
>> +
>> +/**
>> +  Checks if Big Number is odd.
>> +
>> +  @param[in]   Bn     Big number.
>> +
>> +  @retval TRUE   Bn is odd (Bn % 2 == 1).
>> +  @retval FALSE  otherwise.
>> +**/
>> +BOOLEAN
>> +EFIAPI
>> +BigNumIsOdd (
>> +  IN CONST VOID  *Bn
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return FALSE;
>> +}
>> +
>> +/**
>> +  Copy Big number.
>> +
>> +  @param[out]  BnDst     Destination.
>> +  @param[in]   BnSrc     Source.
>> +
>> +  @retval BnDst on success.
>> +  @retval NULL otherwise.
>> +**/
>> +VOID *
>> +EFIAPI
>> +BigNumCopy (
>> +  OUT VOID       *BnDst,
>> +  IN CONST VOID  *BnSrc
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return NULL;
>> +}
>> +
>> +/**
>> +  Get constant Big number with value of "1".
>> +  This may be used to save expensive allocations.
>> +
>> +  @retval Big Number with value of 1.
>> +**/
>> +CONST VOID *
>> +EFIAPI
>> +BigNumValueOne (
>> +  VOID
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return NULL;
>> +}
>> +
>> +/**
>> +  Shift right Big Number.
>> +  Please note, all "out" Big number arguments should be properly 
>> +initialized
>> +  by calling to BigNumInit() or BigNumFromBin() functions.
>> +
>> +  @param[in]   Bn      Big number.
>> +  @param[in]   n       Number of bits to shift.
>> +  @param[out]  BnRes   The result.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumRShift (
>> +  IN CONST VOID  *Bn,
>> +  IN UINTN       n,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Mark Big Number for constant time computations.
>> +  This function should be called before any constant time 
>> +computations are
>> +  performed on the given Big number.
>> +
>> +  @param[in]   Bn     Big number.
>> +**/
>> +VOID
>> +EFIAPI
>> +BigNumConsttime (
>> +  IN VOID  *Bn
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +}
>> +
>> +/**
>> +  Calculate square modulo.
>> +  Please note, all "out" Big number arguments should be properly 
>> +initialized
>> +  by calling to BigNumInit() or BigNumFromBin() functions.
>> +
>> +  @param[in]   BnA     Big number.
>> +  @param[in]   BnM     Big number (modulo).
>> +  @param[out]  BnRes   The result, such that (BnA ^ 2) % BnM.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumSqrMod (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnM,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  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.
>> +
>> +  @retval Big Number context struct or NULL on failure.
>> +**/
>> +VOID *
>> +EFIAPI
>> +BigNumNewContext (
>> +  VOID
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return NULL;
>> +}
>> +
>> +/**
>> +  Free Big Number context that was allocated with BigNumNewContext().
>> +
>> +  @param[in]   BnCtx     Big number context to free.
>> +**/
>> +VOID
>> +EFIAPI
>> +BigNumContextFree (
>> +  IN VOID  *BnCtx
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +}
>> +
>> +/**
>> +  Set Big Number to a given value.
>> +
>> +  @param[in]   Bn     Big number to set.
>> +  @param[in]   Val    Value to set.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumSetUint (
>> +  IN VOID   *Bn,
>> +  IN UINTN  Val
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +/**
>> +  Add two Big Numbers modulo BnM.
>> +
>> +  @param[in]   BnA       Big number.
>> +  @param[in]   BnB       Big number.
>> +  @param[in]   BnM       Big number (modulo).
>> +  @param[out]  BnRes     The result, such that (BnA + BnB) % BnM.
>> +
>> +  @retval EFI_SUCCESS          On success.
>> +  @retval EFI_OUT_OF_RESOURCES In case of internal allocation failures.
>> +  @retval EFI_PROTOCOL_ERROR   Otherwise.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +BigNumAddMod (
>> +  IN CONST VOID  *BnA,
>> +  IN CONST VOID  *BnB,
>> +  IN CONST VOID  *BnM,
>> +  OUT VOID       *BnRes
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> --
>> 2.33.0.windows.2
>> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#86446): https://edk2.groups.io/g/devel/message/86446
Mute This Topic: https://groups.io/mt/88776239/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-






More information about the edk2-devel-archive mailing list