TrustCore SDK NanoCrypto API reference  version 7.0
aes.h
Go to the documentation of this file.
1 /*
2  * aes.h
3  *
4  * AES Implementation
5  *
6  * Copyright 2019-2024 DigiCert, Inc. All Rights Reserved.
7  * Proprietary and Confidential Material.
8  *
9  */
22 /*------------------------------------------------------------------*/
23 
24 #ifndef __AES_HEADER__
25 #define __AES_HEADER__
26 
27 #include "../cap/capdecl.h"
28 
29 #if defined(__ENABLE_MOCANA_CRYPTO_INTERFACE__)
30 #include "../crypto_interface/crypto_interface_aes_priv.h"
31 #endif
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #define AES_MAXNR 14
38 #ifndef AES_BLOCK_SIZE
39 #define AES_BLOCK_SIZE (16)
40 #endif
41 
42 #define MOC_MAX_AES_KEY_SIZE 32
43 #define MOC_AES_256_KEY_LEN 32
44 #define MOC_AES_192_KEY_LEN 24
45 #define MOC_AES_128_KEY_LEN 16
46 
47 /* Generic Defines */
48 #define MODE_ECB 1 /* Are we ciphering in ECB mode? */
49 #define MODE_CBC 2 /* Are we ciphering in CBC mode? */
50 #define MODE_CFB1 3 /* Are we ciphering in 1-bit CFB mode? */
51 #define MODE_CFB128 4 /* Are we ciphering in 128-bit CFB mode? */
52 #define MODE_OFB 5 /* Are we ciphering in OFB mode? */
53 #define MODE_CTR 6 /* Are we ciphering in CTR mode? */
54 
55 /*------------------------------------------------------------------*/
56 
57 /*
58  The structure for key information
59 
60  IMPORTANT: if the size of this context is modified check that
61  MOC_RAND_CTX_WRAPPER_STORAGE_SIZE does not need to be increased
62  in random.h. That macro depends on the largest of two contexts,
63  a des3ctx, and of this context. Right now des3ctx is still larger.
64 */
65 typedef struct
66 {
67  sbyte4 encrypt; /* Key used for encrypting or decrypting? */
68  sbyte4 mode; /* MODE_ECB, MODE_CBC, MODE_CFB1 or MODE_OFB */
69  sbyte4 keyLen; /* Length of the key */
70  sbyte4 Nr; /* key-length-dependent number of rounds */
71  ubyte4 rk[4*(AES_MAXNR + 1)]; /* key schedule */
72 
73  MocSymCtx pMocSymCtx;
74  ubyte enabled;
75  ubyte initialized;
76 } aesCipherContext;
77 
78 
79 /*------------------------------------------------------------------*/
80 
81 /* internal prototypes */
82 
102 MOC_EXTERN MSTATUS AESALGO_makeAesKey(aesCipherContext *pAesContext, sbyte4 keyLen, const ubyte *keyMaterial, sbyte4 encrypt, sbyte4 mode);
103 
122 MOC_EXTERN MSTATUS AESALGO_blockEncrypt(aesCipherContext *pAesContext, ubyte* iv, ubyte *input, sbyte4 inputLen, ubyte *outBuffer, sbyte4 *pRetLength);
123 
142 MOC_EXTERN MSTATUS AESALGO_blockDecrypt(aesCipherContext *pAesContext, ubyte* iv, ubyte *input, sbyte4 inputLen, ubyte *outBuffer, sbyte4 *pRetLength);
143 
157 MOC_EXTERN MSTATUS AESALGO_clearKey(aesCipherContext *pAesContext);
158 
181 MOC_EXTERN MSTATUS AESALGO_makeAesKeyEx (
182  MOC_SYM(hwAccelDescr hwAccelCtx)
183  aesCipherContext *pAesContext,
184  sbyte4 keyLen,
185  const ubyte *keyMaterial,
186  sbyte4 encrypt,
187  sbyte4 mode
188  );
189 
211 MOC_EXTERN MSTATUS AESALGO_blockEncryptEx (
212  MOC_SYM(hwAccelDescr hwAccelCtx)
213  aesCipherContext *pAesContext,
214  ubyte* iv,
215  ubyte *input,
216  sbyte4 inputLen,
217  ubyte *outBuffer,
218  sbyte4 *pRetLength
219  );
220 
242 MOC_EXTERN MSTATUS AESALGO_blockDecryptEx (
243  MOC_SYM(hwAccelDescr hwAccelCtx)
244  aesCipherContext *pAesContext,
245  ubyte* iv,
246  ubyte *input,
247  sbyte4 inputLen,
248  ubyte *outBuffer,
249  sbyte4 *pRetLength
250  );
251 
252 /*------------------------------------------------------------------*/
253 
315 MOC_EXTERN BulkCtx CreateAESCtx(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte* keyMaterial, sbyte4 keyLength, sbyte4 encrypt);
316 
358 MOC_EXTERN MSTATUS DeleteAESCtx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ctx);
359 
363 MOC_EXTERN MSTATUS ResetAESCtx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ctx);
419 MOC_EXTERN MSTATUS DoAES (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte* data, sbyte4 dataLength, sbyte4 encrypt, ubyte* iv);
420 
483 MOC_EXTERN BulkCtx CreateAESCFBCtx(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte* keyMaterial, sbyte4 keyLength, sbyte4 encrypt);
484 
485 
504 MOC_EXTERN BulkCtx CreateAESCFB1Ctx(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte* keyMaterial, sbyte4 keyLength, sbyte4 encrypt);
505 
506 
568 MOC_EXTERN BulkCtx CreateAESOFBCtx(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte* keyMaterial, sbyte4 keyLength, sbyte4 encrypt);
569 
580 MOC_EXTERN MSTATUS CloneAESCtx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx);
581 
582 #ifdef __cplusplus
583 }
584 #endif
585 
586 #endif /* __AES_HEADER__ */
587 
MOC_EXTERN BulkCtx CreateAESOFBCtx(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *keyMaterial, sbyte4 keyLength, sbyte4 encrypt)
Get a new AES OFB-mode context data structure and prepare the key schedule.
MOC_EXTERN MSTATUS AESALGO_blockDecryptEx(MOC_SYM(hwAccelDescr hwAccelCtx) aesCipherContext *pAesContext, ubyte *iv, ubyte *input, sbyte4 inputLen, ubyte *outBuffer, sbyte4 *pRetLength)
MOC_EXTERN BulkCtx CreateAESCFB1Ctx(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *keyMaterial, sbyte4 keyLength, sbyte4 encrypt)
Create a new AES-CFB1 context.
MOC_EXTERN MSTATUS DeleteAESCtx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ctx)
Delete AES context data structure.
MOC_EXTERN MSTATUS CloneAESCtx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx)
Clone a AES context.
MOC_EXTERN MSTATUS DoAES(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *data, sbyte4 dataLength, sbyte4 encrypt, ubyte *iv)
AES-encrypt or AES-decrypt a data buffer.
MOC_EXTERN BulkCtx CreateAESCtx(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *keyMaterial, sbyte4 keyLength, sbyte4 encrypt)
Get a new AES CBC context data structure and prepare the key schedule.
MOC_EXTERN MSTATUS AESALGO_blockEncrypt(aesCipherContext *pAesContext, ubyte *iv, ubyte *input, sbyte4 inputLen, ubyte *outBuffer, sbyte4 *pRetLength)
MOC_EXTERN MSTATUS AESALGO_makeAesKey(aesCipherContext *pAesContext, sbyte4 keyLen, const ubyte *keyMaterial, sbyte4 encrypt, sbyte4 mode)
MOC_EXTERN MSTATUS AESALGO_blockEncryptEx(MOC_SYM(hwAccelDescr hwAccelCtx) aesCipherContext *pAesContext, ubyte *iv, ubyte *input, sbyte4 inputLen, ubyte *outBuffer, sbyte4 *pRetLength)
MOC_EXTERN BulkCtx CreateAESCFBCtx(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *keyMaterial, sbyte4 keyLength, sbyte4 encrypt)
This function's documentation was added since 5.3.1, and should be reviewed for accuracy and appropri...
MOC_EXTERN MSTATUS AESALGO_clearKey(aesCipherContext *pAesContext)
MOC_EXTERN MSTATUS AESALGO_makeAesKeyEx(MOC_SYM(hwAccelDescr hwAccelCtx) aesCipherContext *pAesContext, sbyte4 keyLen, const ubyte *keyMaterial, sbyte4 encrypt, sbyte4 mode)
MOC_EXTERN MSTATUS AESALGO_blockDecrypt(aesCipherContext *pAesContext, ubyte *iv, ubyte *input, sbyte4 inputLen, ubyte *outBuffer, sbyte4 *pRetLength)