TrustCore SDK NanoCert API reference  version 7.0
crypto.h
Go to the documentation of this file.
1 /*
2  * crypto.h
3  *
4  * General Crypto Definitions & Types Header
5  *
6  * Copyright 2019-2024 DigiCert, Inc. All Rights Reserved.
7  * Proprietary and Confidential Material.
8  *
9  */
10 
21 /*------------------------------------------------------------------*/
22 
23 #ifndef __CRYPTO_HEADER__
24 #define __CRYPTO_HEADER__
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #define CERT_MAXDIGESTSIZE (64) /*(SHA512_RESULT_SIZE)*/
31 #define MAX_IV_LENGTH (16) /* AES */
32 #define MAX_ENC_KEY_LENGTH (32) /* AES-256 */
33 
34 /*------------------------------------------------------------------*/
35 
36 
37 /* bulk encryption algorithms descriptions */
38 typedef BulkCtx (*CreateBulkCtxFunc)(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte* keyMaterial, sbyte4 keyLength, sbyte4 encrypt);
39 typedef MSTATUS (*DeleteBulkCtxFunc)(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ctx);
40 typedef MSTATUS (*CipherFunc) (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte* data, sbyte4 dataLength, sbyte4 encrypt, ubyte* iv);
41 typedef MSTATUS (*CloneFunc) (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx);
42 
48 typedef struct BulkEncryptionAlgo
49 {
50  ubyte4 blockSize;
51  CreateBulkCtxFunc createFunc;
52  DeleteBulkCtxFunc deleteFunc;
53  CipherFunc cipherFunc;
54  CloneFunc cloneFunc;
56 
57 /* predefined BulkEncryptionAlgos */
58 #ifndef __DISABLE_3DES_CIPHERS__
59 MOC_EXTERN const BulkEncryptionAlgo CRYPTO_TripleDESSuite;
60 #endif
61 
62 #ifndef __DISABLE_3DES_CIPHERS__
63 MOC_EXTERN const BulkEncryptionAlgo CRYPTO_TwoKeyTripleDESSuite;
64 #endif
65 
66 #ifdef __ENABLE_DES_CIPHER__
67 MOC_EXTERN const BulkEncryptionAlgo CRYPTO_DESSuite;
68 #endif
69 
70 #ifndef __DISABLE_ARC4_CIPHERS__
71 MOC_EXTERN const BulkEncryptionAlgo CRYPTO_RC4Suite;
72 #endif
73 
74 #ifdef __ENABLE_ARC2_CIPHERS__
75 MOC_EXTERN const BulkEncryptionAlgo CRYPTO_RC2Suite;
76 MOC_EXTERN const BulkEncryptionAlgo CRYPTO_RC2EffectiveBitsSuite;
77 #endif
78 
79 #ifdef __ENABLE_BLOWFISH_CIPHERS__
80 MOC_EXTERN const BulkEncryptionAlgo CRYPTO_BlowfishSuite;
81 #endif
82 
83 #ifndef __DISABLE_AES_CIPHERS__
84 MOC_EXTERN const BulkEncryptionAlgo CRYPTO_AESSuite;
85 MOC_EXTERN const BulkEncryptionAlgo CRYPTO_AESCtrSuite;
86 #endif
87 
88 #ifdef __ENABLE_NIL_CIPHER__
89 MOC_EXTERN const BulkEncryptionAlgo CRYPTO_NilSuite;
90 #endif
91 
114 MOC_EXTERN MSTATUS CRYPTO_Process( MOC_SYM(hwAccelDescr hwAccelCtx) const BulkEncryptionAlgo* pAlgo,
115  ubyte* keyMaterial, sbyte4 keyLength,
116  ubyte* iv, ubyte* data, sbyte4 dataLength, sbyte4 encrypt);
117 
118 /* bulk hash algorithms descriptions */
119 typedef MSTATUS (*BulkCtxAllocFunc) (MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx *pCtx);
120 typedef MSTATUS (*BulkCtxFreeFunc) (MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx *pCtx);
121 typedef MSTATUS (*BulkCtxInitFunc) (MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx ctx);
122 typedef MSTATUS (*BulkCtxUpdateFunc)(MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx ctx, const ubyte *pData, ubyte4 datalength);
123 typedef MSTATUS (*BulkCtxFinalFunc) (MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *pResult);
124 typedef MSTATUS (*BulkCtxFinalXOFFunc) (MOC_HASH(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *pResult, ubyte4 resultLen);
125 typedef MSTATUS (*BulkCtxDigestFunc) (MOC_HASH(hwAccelDescr hwAccelCtx) ubyte *pData, ubyte4 dataLen, ubyte *pResult);
126 typedef MSTATUS (*BulkCtxDigestXOFFunc) (MOC_HASH(hwAccelDescr hwAccelCtx) ubyte *pData, ubyte4 dataLen, ubyte *pResult, ubyte4 resultLen);
127 
133 typedef struct BulkHashAlgo
134 {
135  ubyte4 digestSize;
136  ubyte4 blockSize; /* used for HMAC */
137  BulkCtxAllocFunc allocFunc;
138  BulkCtxFreeFunc freeFunc;
139  BulkCtxInitFunc initFunc;
140  BulkCtxUpdateFunc updateFunc;
141  BulkCtxFinalFunc finalFunc;
142  BulkCtxFinalXOFFunc finalXOFFunc;
143  BulkCtxDigestFunc digestFunc;
144  BulkCtxDigestXOFFunc digestXOFFunc;
145  ubyte hashId;
146 } BulkHashAlgo;
147 
154 enum {
155  rsaEncryption = 1,
156  pkcs1Mgf = 8,
157  rsaSsaPss = 10,
158  md2withRSAEncryption = 2,
159  md4withRSAEncryption = 3,
160  md5withRSAEncryption = 4,
161  sha1withRSAEncryption = 5,
162  sha256withRSAEncryption = 11,
163  sha384withRSAEncryption = 12,
164  sha512withRSAEncryption = 13,
165  sha224withRSAEncryption = 14,
166  /* duplicate definition = hash_type */
167  ht_none = 0,
168  ht_md2 = 2,
169  ht_md4 = 3,
170  ht_md5 = 4,
171  ht_sha1 = 5,
172  ht_sha3_224 = 7,
173  ht_sha3_256 = 8,
174  ht_sha3_384 = 9,
175  ht_sha3_512 = 10,
176  ht_shake128 = 111, /* last byte of oid is 11 but that is a duplicate, use 111 */
177  ht_shake256 = 112, /* last byte of oid is 12 but that is a duplicate, use 112 */
178  ht_sha256 = 11,
179  ht_sha384 = 12,
180  ht_sha512 = 13,
181  ht_sha224 = 14,
182  ht_blake2b = 15,
183  ht_blake2s = 16,
184 
185  /* For use with cert requests, don't sign the request with an asymmetric
186  * algorithm, just place the digest in the signature location.
187  */
188  sha1_with_no_sig = 31
189 };
190 
205 MOC_EXTERN MSTATUS CRYPTO_getRSAHashAlgo( ubyte rsaAlgoId, const BulkHashAlgo **ppBulkHashAlgo);
206 
221 MOC_EXTERN MSTATUS CRYPTO_getECCHashAlgo( ubyte eccAlgoId, BulkHashAlgo **ppBulkHashAlgo);
222 
239 MOC_EXTERN MSTATUS CRYPTO_computeBufferHash(MOC_HASH(hwAccelDescr hwAccelCtx)
240  const ubyte* buffer,
241  ubyte4 bytesToHash,
242  ubyte hash[/*CERT_MAXDIGESTSIZE*/],
243  sbyte4 *hashSize,
244  ubyte4 rsaAlgoId);
245 
246 /* bulk encryption algorithms descriptions */
247 typedef BulkCtx (*CreateAeadCtxFunc)(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte* keyMaterial, sbyte4 keyLength, sbyte4 encrypt);
248 typedef MSTATUS (*DeleteAeadCtxFunc)(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ctx);
249 typedef MSTATUS (*AeadCipherFunc) (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte* nonce, ubyte4 nlen, ubyte* adata, ubyte4 alen, ubyte* data, ubyte4 dataLength, ubyte4 verifyLen, sbyte4 encrypt);
250 typedef MSTATUS (*AeadCloneFunc) ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx);
251 
252 typedef struct AeadAlgo
253 {
254  ubyte4 implicitNonceSize;
255  ubyte4 explicitNonceSize;
256  ubyte4 tagSize;
257  CreateAeadCtxFunc createFunc;
258  DeleteAeadCtxFunc deleteFunc;
259  AeadCipherFunc cipherFunc;
260  AeadCloneFunc cloneFunc;
261 
262 } AeadAlgo;
263 
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 
269 
270 #endif /* __CRYPTO_HEADER__ */
Structure to hold function pointers to hashing or extenable output methods.
Definition: crypto.h:133
MOC_EXTERN MSTATUS CRYPTO_getECCHashAlgo(ubyte eccAlgoId, BulkHashAlgo **ppBulkHashAlgo)
Gets a hash suite of function pointers, appropriate for ECC, given a hash identifier.
MOC_EXTERN MSTATUS CRYPTO_Process(MOC_SYM(hwAccelDescr hwAccelCtx) const BulkEncryptionAlgo *pAlgo, ubyte *keyMaterial, sbyte4 keyLength, ubyte *iv, ubyte *data, sbyte4 dataLength, sbyte4 encrypt)
Performs a symmetric key cipher algorithm on a buffer of data.
MOC_EXTERN MSTATUS CRYPTO_getRSAHashAlgo(ubyte rsaAlgoId, const BulkHashAlgo **ppBulkHashAlgo)
Gets a hash suite of function pointers, appropriate for RSA, given a hash identifier.
MOC_EXTERN MSTATUS CRYPTO_computeBufferHash(MOC_HASH(hwAccelDescr hwAccelCtx) const ubyte *buffer, ubyte4 bytesToHash, ubyte hash[], sbyte4 *hashSize, ubyte4 rsaAlgoId)
Computes a hash of a buffer of data given a hash identifier.
Structure to hold function pointers to symmetric key cipher methods.
Definition: crypto.h:48