TrustCore SDK NanoCrypto API reference  version 7.0
three_des.h
Go to the documentation of this file.
1 /*
2  * three_des.h
3  *
4  * 3DES Header
5  *
6  * Copyright 2019-2024 DigiCert, Inc. All Rights Reserved.
7  * Proprietary and Confidential Material.
8  *
9  */
10 
19 /*------------------------------------------------------------------*/
20 
21 #ifndef __3DES_HEADER__
22 #define __3DES_HEADER__
23 
24 #include "../cap/capdecl.h"
25 
26 #ifdef __ENABLE_MOCANA_CRYPTO_INTERFACE__
27 #include "../crypto_interface/crypto_interface_tdes_priv.h"
28 #endif
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #define THREE_DES_BLOCK_SIZE (8)
35 #define THREE_DES_KEY_LENGTH (24)
36 
37 
38 /*------------------------------------------------------------------*/
39 
40 /* IMPORTANT: if the size of ctx3des is modified be sure to modify
41  MOC_RAND_CTX_WRAPPER_STORAGE_SIZE appropriately in random.h
42  */
43 
44 typedef struct
45 {
46  des_ctx firstKey;
47  des_ctx secondKey;
48  des_ctx thirdKey;
49  MocSymCtx pMocSymCtx;
50  ubyte4 enabled;
51 } ctx3des;
52 
53 typedef struct
54 {
55  ctx3des encryptKey;
56  ctx3des decryptKey;
57  MocSymCtx pMocSymCtx;
58  ubyte4 initialized;
59  ubyte4 enabled;
60 } DES3Ctx;
61 
62 
63 /*------------------------------------------------------------------*/
64 
69 /* for white box testing */
70 MOC_EXTERN MSTATUS THREE_DES_initKey(ctx3des *p_3desContext, const ubyte *pKey, sbyte4 keyLen);
71 MOC_EXTERN MSTATUS THREE_DES_encipher(ctx3des *p_3desContext, ubyte *pSrc, ubyte *pDest, ubyte4 numBytes);
72 MOC_EXTERN MSTATUS THREE_DES_decipher(ctx3des *p_3desContext, ubyte *pSrc, ubyte *pDest, ubyte4 numBytes);
73 MOC_EXTERN MSTATUS THREE_DES_clearKey(ctx3des *p_3desContext);
74 
79 /* actual APIs */
80 #ifndef __DISABLE_3DES_CIPHERS__
81 
143 MOC_EXTERN BulkCtx Create3DESCtx(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte* keyMaterial, sbyte4 keyLength, sbyte4 encrypt);
144 
201 MOC_EXTERN BulkCtx Create2Key3DESCtx(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte* keyMaterial, sbyte4 keyLength, sbyte4 encrypt);
202 
206 MOC_EXTERN MSTATUS Reset3DESCtx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ctx);
253 MOC_EXTERN MSTATUS Delete3DESCtx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ctx);
254 
303 MOC_EXTERN MSTATUS Do3DES(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte* data, sbyte4 dataLength, sbyte4 encrypt, ubyte* iv);
304 
315 MOC_EXTERN MSTATUS Clone3DESCtx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx);
316 
366 MOC_EXTERN MSTATUS Do3DesCbcWithPkcs5Pad (
367  MOC_SYM(hwAccelDescr hwAccelCtx)
368  BulkCtx ctx,
369  ubyte *pDataToProcess,
370  ubyte4 dataLength,
371  ubyte *pProcessedData,
372  ubyte4 bufferSize,
373  ubyte4 *pProcessedDataLen,
374  sbyte4 encryptFlag,
375  ubyte *pInitVector
376  );
377 #endif
378 
379 #ifdef __cplusplus
380 }
381 #endif
382 
383 #endif /* __3DES_HEADER__ */
MOC_EXTERN MSTATUS Do3DesCbcWithPkcs5Pad(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *pDataToProcess, ubyte4 dataLength, ubyte *pProcessedData, ubyte4 bufferSize, ubyte4 *pProcessedDataLen, sbyte4 encryptFlag, ubyte *pInitVector)
MOC_EXTERN BulkCtx Create3DESCtx(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *keyMaterial, sbyte4 keyLength, sbyte4 encrypt)
Get a new 3DES context data structure (for operations using three DES keys) and prepare the key sched...
MOC_EXTERN BulkCtx Create2Key3DESCtx(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *keyMaterial, sbyte4 keyLength, sbyte4 encrypt)
Get a new 3DES context data structure (for operations using two DES keys) and prepare the key schedul...
MOC_EXTERN MSTATUS Do3DES(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *data, sbyte4 dataLength, sbyte4 encrypt, ubyte *iv)
3DES-encrypt or 3DES-decrypt a data buffer.
MOC_EXTERN MSTATUS Clone3DESCtx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx)
Clone a TDES context previously created with Create3DESCtx.
MOC_EXTERN MSTATUS Delete3DESCtx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ctx)
Delete 3DES context data structure.