Re: [edk2-devel] [PATCH v1] CryptoPkg: Add new hash algorithm ParallelHash256HashAll in BaseCryptLib.

2022-02-16 Thread Li, Zhihao
We try to make proper attribution for the code in  openssl_sha3 and in xkcp.
We separated their implementation into CryptSha3.c and CryptXkcp.c, 
Separated their declaration into sha3.h and xkcp.h.

With the comment, we plan to delete these header files and put the declaration 
and 
Structure define into CryptCshake256.c.

> -Original Message-
> From: Yao, Jiewen 
> Sent: Wednesday, February 16, 2022 3:52 PM
> To: Li, Zhihao ; devel@edk2.groups.io
> Cc: Wang, Jian J ; Lu, Xiaoyu1
> ; Jiang, Guomin ; Fu,
> Siyuan 
> Subject: RE: [PATCH v1] CryptoPkg: Add new hash algorithm
> ParallelHash256HashAll in BaseCryptLib.
> 
> But I don’t understand why we need sha3.h and xkcp.h at all.
> 
> 
> > -Original Message-
> > From: Li, Zhihao 
> > Sent: Wednesday, February 16, 2022 3:43 PM
> > To: Yao, Jiewen ; devel@edk2.groups.io
> > Cc: Wang, Jian J ; Lu, Xiaoyu1
> ;
> > Jiang, Guomin ; Fu, Siyuan
> 
> > Subject: RE: [PATCH v1] CryptoPkg: Add new hash algorithm
> > ParallelHash256HashAll in BaseCryptLib.
> >
> > With your comment, we plan do some modification for parallelhash.
> > 1. Plan to add  a parameter (BlockSize) on  ParallelHash256HashAll  function
> to
> > replace PcdParallelHashBlockNumber.
> > 2. Plan to move sha3.h and xkcp.h to CryptoPkg\Library\BaseCryptLib\Hash
> > folder.
> >
> >
> > > -Original Message-
> > > From: Yao, Jiewen 
> > > Sent: Tuesday, February 15, 2022 2:09 PM
> > > To: Li, Zhihao ; devel@edk2.groups.io
> > > Cc: Wang, Jian J ; Lu, Xiaoyu1
> > > ; Jiang, Guomin ; Fu,
> > > Siyuan 
> > > Subject: RE: [PATCH v1] CryptoPkg: Add new hash algorithm
> > > ParallelHash256HashAll in BaseCryptLib.
> > >
> > > Thanks for the update.
> > >
> > > Feedback below:
> > >
> > > 1) How block size is determined for below API?
> > >
> > > BOOLEAN
> > > EFIAPI
> > > ParallelHash256HashAll (
> > >   IN CONST VOID*Input,
> > >   IN   UINTN   InputByteLen,
> > >   OUT  VOID*Output,
> > >   IN   UINTN   OutputByteLen,
> > >   IN CONST VOID*Customization,
> > >   IN   UINTN   CustomByteLen
> > >   );
> > >
> > > Is that determined by PcdParallelHashBlockNumber ?
> > >
> > > I don’t think it is good idea to let a crypto library determine a platform
> PCD.
> > > For example, how do you support binary crypto module ?
> > Plan to add  a parameter (BlockSize) to replace
> PcdParallelHashBlockNumber.
> > >
> > > 2) Why we need "sha3.h" and "xkcp.h" ?
> > > These are openssl specific structure. It shall not be put to EDKII file
> header.
> > >
> > > CryptoPkg\Library\Include shall only contain generic dependency header.
> > Plan to move sha3.h and xkcp.h to CryptoPkg\Library\BaseCryptLib\Hash
> folder.
> > >
> > >
> > >
> > >
> > > Thank you
> > > Yao, Jiewen
> > >
> > > > -Original Message-
> > > > From: Li, Zhihao 
> > > > Sent: Friday, February 11, 2022 5:05 PM
> > > > To: devel@edk2.groups.io
> > > > Cc: Yao, Jiewen ; Wang, Jian J
> > > > ; Lu, Xiaoyu1 ; Jiang,
> > > > Guomin ; Fu, Siyuan 
> > > > Subject: [PATCH v1] CryptoPkg: Add new hash algorithm
> > > > ParallelHash256HashAll in BaseCryptLib.
> > > >
> > > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3596
> > > >
> > > > Parallel hash function ParallelHash256HashAll, as defined in NIST's
> > > > Special Publication 800-185, published December 2016. It utilizes
> > > > multi-process to calculate the digest.
> > > >
> > > > Cc: Jiewen Yao 
> > > > Cc: Jian J Wang 
> > > > Cc: Xiaoyu Lu 
> > > > Cc: Guomin Jiang 
> > > > Cc: Siyuan Fu 
> > > >
> > > > Signed-off-by: Zhihao Li 
> > > > ---
> > > >  CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c   
> > > > | 313
> > > > 
> > > >  CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
> > > > | 275
> > > > +
> > > >  CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c
> > > > | 102
> > > +++
> > > >  CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c
> > > > |  53
> 
> > > >  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests.c   
> > > > |
> > > 152
> > > > ++
> > > >  CryptoPkg/CryptoPkg.dec
> > > > |   9 +-
> > > >  CryptoPkg/Include/Library/BaseCryptLib.h   
> > > > |  29 +-
> > > >  CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf 
> > > > |  12 +-
> > > >  CryptoPkg/Library/Include/CrtLibSupport.h  
> > > > |   5 +-
> > > >  CryptoPkg/Library/Include/sha3.h   
> > > > |  32 ++
> > > >  CryptoPkg/Library/Include/xkcp.h   
> > > > |  23 ++
> > > >  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h
> |   3
> > > +-
> > > >
> CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf
> > > |   7 +
> > > >
> CryptoPkg/Test/UnitTest/Libra

Re: [edk2-devel] [PATCH v1] CryptoPkg: Add new hash algorithm ParallelHash256HashAll in BaseCryptLib.

2022-02-16 Thread Li, Zhihao
In CT 46 review result, it require that the code in openssl_sha3 and in xkcp 
need to be made proper attribution.
We separated their implementation into CryptSha3.c and CryptXkcp.c, separated 
their header files into sha3.h and xkcp.h.

Now we plan to delete these header files and put the declaration and structure 
define into CryptCshake256.c if head file not within the scope of CT46 
suggestion.

> -Original Message-
> From: Yao, Jiewen 
> Sent: Wednesday, February 16, 2022 3:52 PM
> To: Li, Zhihao ; devel@edk2.groups.io
> Cc: Wang, Jian J ; Lu, Xiaoyu1
> ; Jiang, Guomin ; Fu,
> Siyuan 
> Subject: RE: [PATCH v1] CryptoPkg: Add new hash algorithm
> ParallelHash256HashAll in BaseCryptLib.
> 
> But I don’t understand why we need sha3.h and xkcp.h at all.
> 
> 
> > -Original Message-
> > From: Li, Zhihao 
> > Sent: Wednesday, February 16, 2022 3:43 PM
> > To: Yao, Jiewen ; devel@edk2.groups.io
> > Cc: Wang, Jian J ; Lu, Xiaoyu1
> ;
> > Jiang, Guomin ; Fu, Siyuan
> 
> > Subject: RE: [PATCH v1] CryptoPkg: Add new hash algorithm
> > ParallelHash256HashAll in BaseCryptLib.
> >
> > With your comment, we plan do some modification for parallelhash.
> > 1. Plan to add  a parameter (BlockSize) on  ParallelHash256HashAll  function
> to
> > replace PcdParallelHashBlockNumber.
> > 2. Plan to move sha3.h and xkcp.h to CryptoPkg\Library\BaseCryptLib\Hash
> > folder.
> >
> >
> > > -Original Message-
> > > From: Yao, Jiewen 
> > > Sent: Tuesday, February 15, 2022 2:09 PM
> > > To: Li, Zhihao ; devel@edk2.groups.io
> > > Cc: Wang, Jian J ; Lu, Xiaoyu1
> > > ; Jiang, Guomin ; Fu,
> > > Siyuan 
> > > Subject: RE: [PATCH v1] CryptoPkg: Add new hash algorithm
> > > ParallelHash256HashAll in BaseCryptLib.
> > >
> > > Thanks for the update.
> > >
> > > Feedback below:
> > >
> > > 1) How block size is determined for below API?
> > >
> > > BOOLEAN
> > > EFIAPI
> > > ParallelHash256HashAll (
> > >   IN CONST VOID*Input,
> > >   IN   UINTN   InputByteLen,
> > >   OUT  VOID*Output,
> > >   IN   UINTN   OutputByteLen,
> > >   IN CONST VOID*Customization,
> > >   IN   UINTN   CustomByteLen
> > >   );
> > >
> > > Is that determined by PcdParallelHashBlockNumber ?
> > >
> > > I don’t think it is good idea to let a crypto library determine a platform
> PCD.
> > > For example, how do you support binary crypto module ?
> > Plan to add  a parameter (BlockSize) to replace
> PcdParallelHashBlockNumber.
> > >
> > > 2) Why we need "sha3.h" and "xkcp.h" ?
> > > These are openssl specific structure. It shall not be put to EDKII file
> header.
> > >
> > > CryptoPkg\Library\Include shall only contain generic dependency header.
> > Plan to move sha3.h and xkcp.h to CryptoPkg\Library\BaseCryptLib\Hash
> folder.
> > >
> > >
> > >
> > >
> > > Thank you
> > > Yao, Jiewen
> > >
> > > > -Original Message-
> > > > From: Li, Zhihao 
> > > > Sent: Friday, February 11, 2022 5:05 PM
> > > > To: devel@edk2.groups.io
> > > > Cc: Yao, Jiewen ; Wang, Jian J
> > > > ; Lu, Xiaoyu1 ; Jiang,
> > > > Guomin ; Fu, Siyuan 
> > > > Subject: [PATCH v1] CryptoPkg: Add new hash algorithm
> > > > ParallelHash256HashAll in BaseCryptLib.
> > > >
> > > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3596
> > > >
> > > > Parallel hash function ParallelHash256HashAll, as defined in NIST's
> > > > Special Publication 800-185, published December 2016. It utilizes
> > > > multi-process to calculate the digest.
> > > >
> > > > Cc: Jiewen Yao 
> > > > Cc: Jian J Wang 
> > > > Cc: Xiaoyu Lu 
> > > > Cc: Guomin Jiang 
> > > > Cc: Siyuan Fu 
> > > >
> > > > Signed-off-by: Zhihao Li 
> > > > ---
> > > >  CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c   
> > > > | 313
> > > > 
> > > >  CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
> > > > | 275
> > > > +
> > > >  CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c
> > > > | 102
> > > +++
> > > >  CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c
> > > > |  53
> 
> > > >  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests.c   
> > > > |
> > > 152
> > > > ++
> > > >  CryptoPkg/CryptoPkg.dec
> > > > |   9 +-
> > > >  CryptoPkg/Include/Library/BaseCryptLib.h   
> > > > |  29 +-
> > > >  CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf 
> > > > |  12 +-
> > > >  CryptoPkg/Library/Include/CrtLibSupport.h  
> > > > |   5 +-
> > > >  CryptoPkg/Library/Include/sha3.h   
> > > > |  32 ++
> > > >  CryptoPkg/Library/Include/xkcp.h   
> > > > |  23 ++
> > > >  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h
> |   3
> > > +-
> > > >
> CryptoPkg/Test/UnitTest/Library/BaseCryptLib/T

Re: [edk2-devel] [PATCH v1] CryptoPkg: Add new hash algorithm ParallelHash256HashAll in BaseCryptLib.

2022-02-15 Thread Yao, Jiewen
But I don’t understand why we need sha3.h and xkcp.h at all.


> -Original Message-
> From: Li, Zhihao 
> Sent: Wednesday, February 16, 2022 3:43 PM
> To: Yao, Jiewen ; devel@edk2.groups.io
> Cc: Wang, Jian J ; Lu, Xiaoyu1 ;
> Jiang, Guomin ; Fu, Siyuan 
> Subject: RE: [PATCH v1] CryptoPkg: Add new hash algorithm
> ParallelHash256HashAll in BaseCryptLib.
> 
> With your comment, we plan do some modification for parallelhash.
> 1. Plan to add  a parameter (BlockSize) on  ParallelHash256HashAll  function 
> to
> replace PcdParallelHashBlockNumber.
> 2. Plan to move sha3.h and xkcp.h to CryptoPkg\Library\BaseCryptLib\Hash
> folder.
> 
> 
> > -Original Message-
> > From: Yao, Jiewen 
> > Sent: Tuesday, February 15, 2022 2:09 PM
> > To: Li, Zhihao ; devel@edk2.groups.io
> > Cc: Wang, Jian J ; Lu, Xiaoyu1
> > ; Jiang, Guomin ; Fu,
> > Siyuan 
> > Subject: RE: [PATCH v1] CryptoPkg: Add new hash algorithm
> > ParallelHash256HashAll in BaseCryptLib.
> >
> > Thanks for the update.
> >
> > Feedback below:
> >
> > 1) How block size is determined for below API?
> >
> > BOOLEAN
> > EFIAPI
> > ParallelHash256HashAll (
> >   IN CONST VOID*Input,
> >   IN   UINTN   InputByteLen,
> >   OUT  VOID*Output,
> >   IN   UINTN   OutputByteLen,
> >   IN CONST VOID*Customization,
> >   IN   UINTN   CustomByteLen
> >   );
> >
> > Is that determined by PcdParallelHashBlockNumber ?
> >
> > I don’t think it is good idea to let a crypto library determine a platform 
> > PCD.
> > For example, how do you support binary crypto module ?
> Plan to add  a parameter (BlockSize) to replace PcdParallelHashBlockNumber.
> >
> > 2) Why we need "sha3.h" and "xkcp.h" ?
> > These are openssl specific structure. It shall not be put to EDKII file 
> > header.
> >
> > CryptoPkg\Library\Include shall only contain generic dependency header.
> Plan to move sha3.h and xkcp.h to CryptoPkg\Library\BaseCryptLib\Hash folder.
> >
> >
> >
> >
> > Thank you
> > Yao, Jiewen
> >
> > > -Original Message-
> > > From: Li, Zhihao 
> > > Sent: Friday, February 11, 2022 5:05 PM
> > > To: devel@edk2.groups.io
> > > Cc: Yao, Jiewen ; Wang, Jian J
> > > ; Lu, Xiaoyu1 ; Jiang,
> > > Guomin ; Fu, Siyuan 
> > > Subject: [PATCH v1] CryptoPkg: Add new hash algorithm
> > > ParallelHash256HashAll in BaseCryptLib.
> > >
> > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3596
> > >
> > > Parallel hash function ParallelHash256HashAll, as defined in NIST's
> > > Special Publication 800-185, published December 2016. It utilizes
> > > multi-process to calculate the digest.
> > >
> > > Cc: Jiewen Yao 
> > > Cc: Jian J Wang 
> > > Cc: Xiaoyu Lu 
> > > Cc: Guomin Jiang 
> > > Cc: Siyuan Fu 
> > >
> > > Signed-off-by: Zhihao Li 
> > > ---
> > >  CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c   | 
> > > 313
> > > 
> > >  CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c| 
> > > 275
> > > +
> > >  CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c| 
> > > 102
> > +++
> > >  CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c| 
> > >  53 
> > >  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests.c   |
> > 152
> > > ++
> > >  CryptoPkg/CryptoPkg.dec| 
> > >   9 +-
> > >  CryptoPkg/Include/Library/BaseCryptLib.h   | 
> > >  29 +-
> > >  CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf | 
> > >  12 +-
> > >  CryptoPkg/Library/Include/CrtLibSupport.h  | 
> > >   5 +-
> > >  CryptoPkg/Library/Include/sha3.h   | 
> > >  32 ++
> > >  CryptoPkg/Library/Include/xkcp.h   | 
> > >  23 ++
> > >  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h| 
> > >   3
> > +-
> > >  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf
> > |   7 +
> > >  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf |
> > 6 +
> > >  14 files changed, 1016 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c
> > > b/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c
> > > new file mode 100644
> > > index 00..5efced3f46
> > > --- /dev/null
> > > +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c
> > > @@ -0,0 +1,313 @@
> > > +/** @file
> > >
> > > +  cSHAKE-256 Digest Wrapper Implementations.
> > >
> > > +
> > >
> > > +Copyright (c) 2022, Intel Corporation. All rights reserved.
> > >
> > > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >
> > > +
> > >
> > > +**/
> > >
> > > +
> > >
> > > +#include "InternalCryptLib.h"
> > >
> > > +#include "sha3.h"
> > >
> > > +#include "xkcp.h"
> > >
> > > +
> > >
> > > +#define  CSHAKE256_SECURITY_STRENGTH256
> > >

Re: [edk2-devel] [PATCH v1] CryptoPkg: Add new hash algorithm ParallelHash256HashAll in BaseCryptLib.

2022-02-15 Thread Li, Zhihao
With your comment, we plan do some modification for parallelhash.
1. Plan to add  a parameter (BlockSize) on  ParallelHash256HashAll  function to 
replace PcdParallelHashBlockNumber.
2. Plan to move sha3.h and xkcp.h to CryptoPkg\Library\BaseCryptLib\Hash folder.


> -Original Message-
> From: Yao, Jiewen 
> Sent: Tuesday, February 15, 2022 2:09 PM
> To: Li, Zhihao ; devel@edk2.groups.io
> Cc: Wang, Jian J ; Lu, Xiaoyu1
> ; Jiang, Guomin ; Fu,
> Siyuan 
> Subject: RE: [PATCH v1] CryptoPkg: Add new hash algorithm
> ParallelHash256HashAll in BaseCryptLib.
> 
> Thanks for the update.
> 
> Feedback below:
> 
> 1) How block size is determined for below API?
> 
> BOOLEAN
> EFIAPI
> ParallelHash256HashAll (
>   IN CONST VOID*Input,
>   IN   UINTN   InputByteLen,
>   OUT  VOID*Output,
>   IN   UINTN   OutputByteLen,
>   IN CONST VOID*Customization,
>   IN   UINTN   CustomByteLen
>   );
> 
> Is that determined by PcdParallelHashBlockNumber ?
> 
> I don’t think it is good idea to let a crypto library determine a platform 
> PCD.
> For example, how do you support binary crypto module ?
Plan to add  a parameter (BlockSize) to replace PcdParallelHashBlockNumber.
> 
> 2) Why we need "sha3.h" and "xkcp.h" ?
> These are openssl specific structure. It shall not be put to EDKII file 
> header.
> 
> CryptoPkg\Library\Include shall only contain generic dependency header.
Plan to move sha3.h and xkcp.h to CryptoPkg\Library\BaseCryptLib\Hash folder.
> 
> 
> 
> 
> Thank you
> Yao, Jiewen
> 
> > -Original Message-
> > From: Li, Zhihao 
> > Sent: Friday, February 11, 2022 5:05 PM
> > To: devel@edk2.groups.io
> > Cc: Yao, Jiewen ; Wang, Jian J
> > ; Lu, Xiaoyu1 ; Jiang,
> > Guomin ; Fu, Siyuan 
> > Subject: [PATCH v1] CryptoPkg: Add new hash algorithm
> > ParallelHash256HashAll in BaseCryptLib.
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3596
> >
> > Parallel hash function ParallelHash256HashAll, as defined in NIST's
> > Special Publication 800-185, published December 2016. It utilizes
> > multi-process to calculate the digest.
> >
> > Cc: Jiewen Yao 
> > Cc: Jian J Wang 
> > Cc: Xiaoyu Lu 
> > Cc: Guomin Jiang 
> > Cc: Siyuan Fu 
> >
> > Signed-off-by: Zhihao Li 
> > ---
> >  CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c   | 
> > 313
> > 
> >  CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c| 
> > 275
> > +
> >  CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c| 
> > 102
> +++
> >  CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c|  
> > 53 
> >  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests.c   |
> 152
> > ++
> >  CryptoPkg/CryptoPkg.dec|   
> > 9 +-
> >  CryptoPkg/Include/Library/BaseCryptLib.h   |  
> > 29 +-
> >  CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf |  
> > 12 +-
> >  CryptoPkg/Library/Include/CrtLibSupport.h  |   
> > 5 +-
> >  CryptoPkg/Library/Include/sha3.h   |  
> > 32 ++
> >  CryptoPkg/Library/Include/xkcp.h   |  
> > 23 ++
> >  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h|   
> > 3
> +-
> >  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf
> |   7 +
> >  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf |
> 6 +
> >  14 files changed, 1016 insertions(+), 5 deletions(-)
> >
> > diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c
> > b/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c
> > new file mode 100644
> > index 00..5efced3f46
> > --- /dev/null
> > +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c
> > @@ -0,0 +1,313 @@
> > +/** @file
> >
> > +  cSHAKE-256 Digest Wrapper Implementations.
> >
> > +
> >
> > +Copyright (c) 2022, Intel Corporation. All rights reserved.
> >
> > +SPDX-License-Identifier: BSD-2-Clause-Patent
> >
> > +
> >
> > +**/
> >
> > +
> >
> > +#include "InternalCryptLib.h"
> >
> > +#include "sha3.h"
> >
> > +#include "xkcp.h"
> >
> > +
> >
> > +#define  CSHAKE256_SECURITY_STRENGTH256
> >
> > +#define  CSHAKE256_RATE_IN_BYTES136
> >
> > +
> >
> > +const CHAR8 mZeroPadding[CSHAKE256_RATE_IN_BYTES] = {0};
> >
> > +
> >
> > +UINTN
> >
> > +EFIAPI
> >
> > +LeftEncode (
> >
> > +  OUT UINT8 *Encbuf,
> >
> > +  IN  UINTN Value
> >
> > +  )
> >
> > +{
> >
> > +  return left_encode (Encbuf, Value);
> >
> > +}
> >
> > +
> >
> > +UINTN
> >
> > +EFIAPI
> >
> > +RightEncode (
> >
> > +  OUT UINT8 *Encbuf,
> >
> > +  IN  UINTN Value
> >
> > +  )
> >
> > +{
> >
> > +  return right_encode (Encbuf, Value);
> >
> > +}
> >
> > +
> >
> > +/**
> >
> > +  Retrieves the size, in bytes, of the context buffer required for
> >

Re: [edk2-devel] [PATCH v1] CryptoPkg: Add new hash algorithm ParallelHash256HashAll in BaseCryptLib.

2022-02-14 Thread Yao, Jiewen
Thanks for the update.

Feedback below:

1) How block size is determined for below API?

BOOLEAN
EFIAPI
ParallelHash256HashAll (
  IN CONST VOID*Input,
  IN   UINTN   InputByteLen,
  OUT  VOID*Output,
  IN   UINTN   OutputByteLen,
  IN CONST VOID*Customization,
  IN   UINTN   CustomByteLen
  );

Is that determined by PcdParallelHashBlockNumber ?

I don’t think it is good idea to let a crypto library determine a platform PCD.
For example, how do you support binary crypto module ?

2) Why we need "sha3.h" and "xkcp.h" ?
These are openssl specific structure. It shall not be put to EDKII file header.

CryptoPkg\Library\Include shall only contain generic dependency header.




Thank you
Yao, Jiewen

> -Original Message-
> From: Li, Zhihao 
> Sent: Friday, February 11, 2022 5:05 PM
> To: devel@edk2.groups.io
> Cc: Yao, Jiewen ; Wang, Jian J ;
> Lu, Xiaoyu1 ; Jiang, Guomin ;
> Fu, Siyuan 
> Subject: [PATCH v1] CryptoPkg: Add new hash algorithm ParallelHash256HashAll
> in BaseCryptLib.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3596
> 
> Parallel hash function ParallelHash256HashAll, as defined in NIST's
> Special Publication 800-185, published December 2016. It utilizes
> multi-process to calculate the digest.
> 
> Cc: Jiewen Yao 
> Cc: Jian J Wang 
> Cc: Xiaoyu Lu 
> Cc: Guomin Jiang 
> Cc: Siyuan Fu 
> 
> Signed-off-by: Zhihao Li 
> ---
>  CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c   | 313
> 
>  CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c| 275
> +
>  CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c| 102 
> +++
>  CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c|  53 
> 
>  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests.c   | 152
> ++
>  CryptoPkg/CryptoPkg.dec|   9 
> +-
>  CryptoPkg/Include/Library/BaseCryptLib.h   |  29 
> +-
>  CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf |  12 
> +-
>  CryptoPkg/Library/Include/CrtLibSupport.h  |   5 
> +-
>  CryptoPkg/Library/Include/sha3.h   |  32 
> ++
>  CryptoPkg/Library/Include/xkcp.h   |  23 
> ++
>  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h|   3 
> +-
>  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf  |   7 
> +
>  CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf |   6 
> +
>  14 files changed, 1016 insertions(+), 5 deletions(-)
> 
> diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c
> b/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c
> new file mode 100644
> index 00..5efced3f46
> --- /dev/null
> +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c
> @@ -0,0 +1,313 @@
> +/** @file
> 
> +  cSHAKE-256 Digest Wrapper Implementations.
> 
> +
> 
> +Copyright (c) 2022, Intel Corporation. All rights reserved.
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include "InternalCryptLib.h"
> 
> +#include "sha3.h"
> 
> +#include "xkcp.h"
> 
> +
> 
> +#define  CSHAKE256_SECURITY_STRENGTH256
> 
> +#define  CSHAKE256_RATE_IN_BYTES136
> 
> +
> 
> +const CHAR8 mZeroPadding[CSHAKE256_RATE_IN_BYTES] = {0};
> 
> +
> 
> +UINTN
> 
> +EFIAPI
> 
> +LeftEncode (
> 
> +  OUT UINT8 *Encbuf,
> 
> +  IN  UINTN Value
> 
> +  )
> 
> +{
> 
> +  return left_encode (Encbuf, Value);
> 
> +}
> 
> +
> 
> +UINTN
> 
> +EFIAPI
> 
> +RightEncode (
> 
> +  OUT UINT8 *Encbuf,
> 
> +  IN  UINTN Value
> 
> +  )
> 
> +{
> 
> +  return right_encode (Encbuf, Value);
> 
> +}
> 
> +
> 
> +/**
> 
> +  Retrieves the size, in bytes, of the context buffer required for cSHAKE-256
> hash operations.
> 
> +
> 
> +  @return  The size, in bytes, of the context buffer required for cSHAKE-256
> hash operations.
> 
> +
> 
> +**/
> 
> +UINTN
> 
> +EFIAPI
> 
> +CShake256GetContextSize (
> 
> +  VOID
> 
> +  )
> 
> +{
> 
> +  return (UINTN) (sizeof (KECCAK1600_CTX));
> 
> +}
> 
> +
> 
> +/**
> 
> +  Initializes user-supplied memory pointed by CShake256Context as cSHAKE-256
> hash context for
> 
> +  subsequent use.
> 
> +
> 
> +  @param[out] CShake256Context   Pointer to cSHAKE-256 context being
> initialized.
> 
> +  @param[in]  OutputLen  The desired number of output length in 
> bytes.
> 
> +  @param[in]  Name   Pointer to the function name string.
> 
> +  @param[in]  NameLenThe length of the function name in bytes.
> 
> +  @param[in]  Customization  Pointer to the customization string.
> 
> +  @param[in]  CustomizationLen   The length of the customization string in
> bytes.
> 
> +
> 
> +  @retval TRUE   cSHAKE-256 context initialization succeeded.
> 
> +  @ret