Files
slimbootloader/BootloaderCommonPkg/Library/IppCryptoLib/auth/pcphash.h
T
Mike Crowe 990e3e81e6 Use LF line endings in the repository
Convert the line endings stored for all text files in the repository to
LF. The majority previously used DOS-style CRLF line endings. Add a
.gitattributes file to enforce this and treat certain extensions as
never being text files.

Update PatchCheck.py to insist on LF line endings rather than CRLF.
However, its other checks fail on this commit due to lots of
pre-existing complaints that it only notices because the line endings
have changed.

Silicon/QemuSocPkg/FspBin/Patches/0001-Build-QEMU-FSP-2.0-binaries.patch
needs to be treated as binary since it contains a mixture of line
endings.

This change has implications depending on the client platform you are
using the repository from:

* Windows

The usual configuration for Git on Windows means that text files will
be checked out to the work tree with DOS-style CRLF line endings. If
that's not the case then you can configure Git to do so for the entire
machine with:

 git config --global core.autocrlf true

or for just the repository with:

 git config core.autocrlf true

Line endings will be normalised to LF when they are committed to the
repository. If you commit a text file with only LF line endings then it
will be converted to CRLF line endings in your work tree.

* Linux, MacOS and other Unices

The usual configuration for Git on such platforms is to check files out
of the repository with LF line endings. This is probably the right thing
for you. In the unlikely even that you are using Git on Unix but editing
or compiling on Windows for some reason then you may need to tweak your
configuration to force the use of CRLF line endings as described above.

* General

For more information see
https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings .

Fixes: https://github.com/slimbootloader/slimbootloader/issues/1400
Signed-off-by: Mike Crowe <mac@mcrowe.com>
2021-11-10 12:46:42 -08:00

230 lines
8.9 KiB
C

/*******************************************************************************
* Copyright 2014-2020 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
/*
//
// Purpose:
// Cryptography Primitive.
// Security Hash Standard
// Internal Definitions and Internal Functions Prototypes
//
//
*/
#if !defined(_PCP_HASH_H)
#define _PCP_HASH_H
/* messge block size */
#define MBS_SHA1 (64) /* SHA1 message block size (bytes) */
#define MBS_SHA256 (64) /* SHA256 and SHA224 */
#define MBS_SHA224 (64) /* SHA224 */
#define MBS_SHA512 (128) /* SHA512 and SHA384 */
#define MBS_SHA384 (128) /* SHA384 */
#define MBS_MD5 (64) /* MD5 */
#define MBS_SM3 (64) /* SM3 */
#define MBS_HASH_MAX (MBS_SHA512) /* max message block size (bytes) */
#define MAX_HASH_SIZE (IPP_SHA512_DIGEST_BITSIZE/8) /* hash of the max len (bytes) */
/* size of processed message length representation (bytes) */
#define MLR_SHA1 (sizeof(Ipp64u))
#define MLR_SHA256 (sizeof(Ipp64u))
#define MLR_SHA224 (sizeof(Ipp64u))
#define MLR_SHA512 (sizeof(Ipp64u)*2)
#define MLR_SHA384 (sizeof(Ipp64u)*2)
#define MLR_MD5 (sizeof(Ipp64u))
#define MLR_SM3 (sizeof(Ipp64u))
/* hold some old definition for a purpose */
typedef Ipp32u DigestSHA1[5]; /* SHA1 digest */
typedef Ipp32u DigestSHA224[7]; /* SHA224 digest */
typedef Ipp32u DigestSHA256[8]; /* SHA256 digest */
typedef Ipp64u DigestSHA384[6]; /* SHA384 digest */
typedef Ipp64u DigestSHA512[8]; /* SHA512 digest */
typedef Ipp32u DigestMD5[4]; /* MD5 digest */
typedef Ipp32u DigestSM3[8]; /* SM3 digest */
#define HASH_ALIGNMENT ((int)(sizeof(void*)))
#define SHA1_ALIGNMENT HASH_ALIGNMENT
#define SHA224_ALIGNMENT HASH_ALIGNMENT
#define SHA256_ALIGNMENT HASH_ALIGNMENT
#define SHA384_ALIGNMENT HASH_ALIGNMENT
#define SHA512_ALIGNMENT HASH_ALIGNMENT
#define MD5_ALIGNMENT HASH_ALIGNMENT
#define SM3_ALIGNMENT HASH_ALIGNMENT
struct _cpSHA1 {
IppCtxId idCtx; /* SHA1 identifier */
int msgBuffIdx; /* buffer entry */
Ipp64u msgLenLo; /* message length (bytes) */
Ipp8u msgBuffer[MBS_SHA1]; /* buffer */
DigestSHA1 msgHash; /* intermediate hash */
};
struct _cpSHA256 {
IppCtxId idCtx; /* SHA224 identifier */
int msgBuffIdx; /* buffer entry */
Ipp64u msgLenLo; /* message length */
Ipp8u msgBuffer[MBS_SHA256]; /* buffer */
DigestSHA256 msgHash; /* intermediate hash */
};
struct _cpSHA512 {
IppCtxId idCtx; /* SHA384 identifier */
int msgBuffIdx; /* buffer entry */
Ipp64u msgLenLo; /* message length */
Ipp64u msgLenHi; /* message length */
Ipp8u msgBuffer[MBS_SHA512]; /* buffer */
DigestSHA512 msgHash; /* intermediate hash */
};
struct _cpMD5 {
IppCtxId idCtx; /* MD5 identifier */
int msgBuffIdx; /* buffer entry */
Ipp64u msgLenLo; /* message length */
Ipp8u msgBuffer[MBS_MD5]; /* buffer */
DigestMD5 msgHash; /* intermediate hash */
};
struct _cpSM3 {
IppCtxId idCtx; /* SM3 identifier */
int msgBuffIdx; /* buffer entry */
Ipp64u msgLenLo; /* message length */
Ipp8u msgBuffer[MBS_SM3]; /* buffer */
DigestSM3 msgHash; /* intermediate hash */
};
/* hash alg attributes */
typedef struct _cpHashAttr {
int ivSize; /* attr: length (bytes) of initial value cpHashIV */
int hashSize; /* attr: length (bytes) of hash */
int msgBlkSize; /* attr: length (bytes) of message block */
int msgLenRepSize; /* attr: length (bytes) in representation of processed message length */
Ipp64u msgLenMax[2]; /* attr: max message length (bytes) (low high) */
} cpHashAttr;
/* hash value */
typedef Ipp64u cpHash[IPP_SHA512_DIGEST_BITSIZE/BITSIZE(Ipp64u)]; /* hash value */
/* hash update function */
typedef void (*cpHashProc)(void* pHash, const Ipp8u* pMsg, int msgLen, const void* pParam);
/* generalized hash context */
struct _cpHashCtx {
IppCtxId idCtx; /* hash identifier */
IppHashAlgId algID; /* hash algorithm ID */
Ipp64u msgLenLo; /* processed message:*/
Ipp64u msgLenHi; /* length */
cpHashProc hashProc; /* hash update func */
const void* pParam; /* hashProc's params */
cpHash msgHash; /* intermadiate hash */
int msgBuffIdx; /* buffer entry */
Ipp8u msgBuffer[MBS_HASH_MAX]; /* buffer */
};
/* accessors */
#define HASH_CTX_ID(stt) ((stt)->idCtx)
#define HASH_ALG_ID(stt) ((stt)->algID)
#define HASH_LENLO(stt) ((stt)->msgLenLo)
#define HASH_LENHI(stt) ((stt)->msgLenHi)
#define HASH_FUNC(stt) ((stt)->hashProc)
#define HASH_FUNC_PAR(stt) ((stt)->pParam)
#define HASH_VALUE(stt) ((stt)->msgHash)
#define HAHS_BUFFIDX(stt) ((stt)->msgBuffIdx)
#define HASH_BUFF(stt) ((stt)->msgBuffer)
#define HASH_VALID_ID(pCtx) (HASH_CTX_ID((pCtx))==idCtxHash)
/* initial hash values */
extern const Ipp32u SHA1_IV[];
extern const Ipp32u SHA256_IV[];
extern const Ipp32u SHA224_IV[];
extern const Ipp64u SHA512_IV[];
extern const Ipp64u SHA384_IV[];
extern const Ipp32u MD5_IV[];
extern const Ipp32u SM3_IV[];
extern const Ipp64u SHA512_224_IV[];
extern const Ipp64u SHA512_256_IV[];
/* hash alg additive constants */
extern __ALIGN16 const Ipp32u SHA1_cnt[];
extern __ALIGN16 const Ipp32u SHA256_cnt[];
extern __ALIGN16 const Ipp64u SHA512_cnt[];
extern __ALIGN16 const Ipp32u MD5_cnt[];
extern __ALIGN16 const Ipp32u SM3_cnt[];
/* hash alg opt argument */
extern const void* cpHashProcFuncOpt[];
/* enabled hash alg */
extern const IppHashAlgId cpEnabledHashAlgID[];
/* hash alg IV (init value) */
extern const Ipp8u* cpHashIV[];
/* hash alg attribute DB */
extern const cpHashAttr cpHashAlgAttr[];
/* IV size helper */
__INLINE int cpHashIvSize(IppHashAlgId algID)
{ return cpHashAlgAttr[algID].ivSize; }
/* hash size helper */
__INLINE int cpHashSize(IppHashAlgId algID)
{ return cpHashAlgAttr[algID].hashSize; }
/* message block size helper */
__INLINE int cpHashMBS(IppHashAlgId algID)
{ return cpHashAlgAttr[algID].msgBlkSize; }
/* maps algID into enabled IppHashAlgId value */
__INLINE IppHashAlgId cpValidHashAlg(IppHashAlgId algID)
{
/* maps algID into the valid range */
algID = (((int)ippHashAlg_Unknown < (int)algID) && ((int)algID < (int)ippHashAlg_MaxNo))? algID : ippHashAlg_Unknown;
return cpEnabledHashAlgID[algID];
}
/* common functions */
#define cpComputeDigest OWNAPI(cpComputeDigest)
void cpComputeDigest(Ipp8u* pHashTag, int hashTagLen, const IppsHashState* pCtx);
/* processing functions */
void UpdateSHA1 (void* pHash, const Ipp8u* mblk, int mlen, const void* pParam);
#define UpdateSHA256 OWNAPI(UpdateSHA256)
void UpdateSHA256(void* pHash, const Ipp8u* mblk, int mlen, const void* pParam);
void EFIAPI UpdateSHA256V8(void* pHash, const Ipp8u* mblk, int mlen, const void* pParam);
void EFIAPI UpdateSHA256Ni(void* pHash, const Ipp8u* mblk, int mlen, const void* pParam);
void UpdateSHA512(void* pHash, const Ipp8u* mblk, int mlen, const void* pParam);
void EFIAPI UpdateSHA512W7 (void* uniHash, const Ipp8u* mblk, int mlen, const void* uniPraram);
void EFIAPI UpdateSHA512G9 (void* uniHash, const Ipp8u* mblk, int mlen, const void* uniPraram);
void UpdateMD5 (void* pHash, const Ipp8u* mblk, int mlen, const void* pParam);
void UpdateSM3 (void* pHash, const Ipp8u* mblk, int mlen, const void* pParam);
#if (_SHA_NI_ENABLING_ == _FEATURE_TICKTOCK_) || (_SHA_NI_ENABLING_ == _FEATURE_ON_)
void UpdateSHA1ni (void* pHash, const Ipp8u* mblk, int mlen, const void* pParam);
extern void __cdecl UpdateSHA256ni(void* pHash, const Ipp8u* mblk, int mlen, const void* pParam);
#endif
/* general methods */
//void cpHashUpdate(const Ipp8u* pSrc, int len, IppsHashState* pCtx, cpHashProc hashFunc, const void* pParam, int mbs);
int cpReInitHash(IppsHashState* pCtx, IppHashAlgId algID);
#endif /* _PCP_HASH_H */