TrustCore SDK NanoCrypto API reference  version 7.0
sha1.h
Go to the documentation of this file.
1 /*
2  * sha1.h
3  *
4  * SHA - Secure Hash Algorithm Header
5  *
6  * Copyright 2019-2024 DigiCert, Inc. All Rights Reserved.
7  * Proprietary and Confidential Material.
8  *
9  */
10 
22 /*------------------------------------------------------------------*/
23 
24 #ifndef __SHA1_HEADER__
25 #define __SHA1_HEADER__
26 
27 #include "../cap/capdecl.h"
28 
29 #ifdef __ENABLE_MOCANA_CRYPTO_INTERFACE__
30 #include "../crypto_interface/crypto_interface_sha1_priv.h"
31 #endif
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #define SHA_HASH_RESULT_SIZE (20)
38 #define SHA_HASH_BLOCK_SIZE (64)
39 /* conventions */
40 #define SHA1_RESULT_SIZE (20)
41 #define SHA1_BLOCK_SIZE (64)
42 
43 
44 /*------------------------------------------------------------------*/
45 
46 typedef struct SW_SHA1_CTX
47 {
48  MocSymCtx pMocSymCtx;
49  ubyte4 enabled;
50  ubyte4 hashId;
51 
52  ubyte4 hashBlocks[5];
53 
54  ubyte8 mesgLength;
55 
56  sbyte4 hashBufferIndex;
57  ubyte hashBuffer[SHA1_BLOCK_SIZE];
58 
59 #ifdef __ENABLE_MOCANA_MINIMUM_STACK__
60  ubyte4 W[80];
61 #endif
62 
63 } SW_SHA1_CTX;
64 
65 #ifndef __CUSTOM_SHA1_CONTEXT__
66 typedef struct SW_SHA1_CTX shaDescr, shaDescrHS, SHA1_CTX;
67 #endif
68 
69 
70 /*------------------------------------------------------------------*/
71 
120 MOC_EXTERN MSTATUS SHA1_allocDigest (MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx *pp_context);
121 
164 MOC_EXTERN MSTATUS SHA1_freeDigest (MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx *pp_context);
165 
216 MOC_EXTERN MSTATUS SHA1_initDigest (MOC_HASH(hwAccelDescr hwAccelCtx) shaDescr *p_shaContext);
217 
265 MOC_EXTERN MSTATUS SHA1_updateDigest (MOC_HASH(hwAccelDescr hwAccelCtx) shaDescr *p_shaContext, const ubyte *pData, ubyte4 dataLen);
266 
319 MOC_EXTERN MSTATUS SHA1_finalDigest (MOC_HASH(hwAccelDescr hwAccelCtx) shaDescr *p_shaContext, ubyte *pShaOutput);
320 
377 MOC_EXTERN MSTATUS SHA1_completeDigest(MOC_HASH(hwAccelDescr hwAccelCtx) const ubyte *pData, ubyte4 dataLen, ubyte *pShaOutput);
378 
391 MOC_EXTERN MSTATUS SHA1_cloneCtx(MOC_HASH(hwAccelDescr hwAccelCtx) shaDescr *pDest, shaDescr *pSrc);
392 
395 #if (!(defined(__DISABLE_MOCANA_RNG__)))
396 /* G function used for FIPS 186 RNG change notice section 1 */
397 MOC_EXTERN MSTATUS SHA1_G(ubyte *pData, ubyte *pShaOutput);
398 /* G function used for FIPS 186 RNG change notice section 2 */
399 MOC_EXTERN MSTATUS SHA1_GK(ubyte *pData, ubyte *pShaOutput);
400 #endif
401 
402 #ifdef __SHA1_HARDWARE_HASH__
403 MOC_EXTERN MSTATUS SHA1_initDigestHandShake (MOC_HASH(hwAccelDescr hwAccelCtx) shaDescrHS *p_shaContext);
404 MOC_EXTERN MSTATUS SHA1_updateDigestHandShake (MOC_HASH(hwAccelDescr hwAccelCtx) shaDescrHS*p_shaContext, const ubyte *pData, ubyte4 dataLen);
405 MOC_EXTERN MSTATUS SHA1_finalDigestHandShake (MOC_HASH(hwAccelDescr hwAccelCtx) shaDescrHS *p_shaContext, ubyte *pShaOutput);
406 
407 #else
408 #define SHA1_initDigestHandShake SHA1_initDigest
409 #define SHA1_updateDigestHandShake SHA1_updateDigest
410 #define SHA1_finalDigestHandShake SHA1_finalDigest
411 #endif
412 
415 #ifdef __cplusplus
416 }
417 #endif
418 
419 #endif /* __SHA1_HEADER__ */
MOC_EXTERN MSTATUS SHA1_updateDigest(MOC_HASH(hwAccelDescr hwAccelCtx) shaDescr *p_shaContext, const ubyte *pData, ubyte4 dataLen)
Calculate and update intermediate SHA1 digest value.
MOC_EXTERN MSTATUS SHA1_completeDigest(MOC_HASH(hwAccelDescr hwAccelCtx) const ubyte *pData, ubyte4 dataLen, ubyte *pShaOutput)
Calculate single item's SHA1 digest value (with a single function call).
MOC_EXTERN MSTATUS SHA1_initDigest(MOC_HASH(hwAccelDescr hwAccelCtx) shaDescr *p_shaContext)
Initialize SHA1 operation context data structure.
MOC_EXTERN MSTATUS SHA1_freeDigest(MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx *pp_context)
Free (delete) SHA1 operation context data structure.
MOC_EXTERN MSTATUS SHA1_finalDigest(MOC_HASH(hwAccelDescr hwAccelCtx) shaDescr *p_shaContext, ubyte *pShaOutput)
Calculate final SHA1 digest value.
MOC_EXTERN MSTATUS SHA1_allocDigest(MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx *pp_context)
Allocate SHA1 operation context data structure.
MOC_EXTERN MSTATUS SHA1_cloneCtx(MOC_HASH(hwAccelDescr hwAccelCtx) shaDescr *pDest, shaDescr *pSrc)
Makes a clone of a previously allocated SHA1_CTX.