TrustCore SDK NanoCrypto API reference  version 7.0
aes_ctr.h
Go to the documentation of this file.
1 /*
2  * aes_ctr.h
3  *
4  * AES-CTR Implementation
5  *
6  * Copyright 2019-2024 DigiCert, Inc. All Rights Reserved.
7  * Proprietary and Confidential Material.
8  *
9  */
18 /*------------------------------------------------------------------*/
19 
20 #ifndef __AES_CTR_HEADER__
21 #define __AES_CTR_HEADER__
22 
23 #include "../cap/capdecl.h"
24 
25 #if defined(__ENABLE_MOCANA_CRYPTO_INTERFACE__)
26 #include "../crypto_interface/crypto_interface_aes_ctr_priv.h"
27 #endif
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 
34 /*------------------------------------------------------------------*/
35 
36 /* The structure for key information */
37 typedef struct aesCTRCipherContext
38 {
39  aesCipherContext *pCtx;
40  union
41  {
42  ubyte counterBlock[AES_BLOCK_SIZE]; /* counter block */
43  ubyte4 ctr[4];
44  } u;
45  ubyte encBlock[AES_BLOCK_SIZE]; /* encrypted counter block */
46  ubyte offset; /* offset of unused byte in the encBlock */
47  MocSymCtx pMocSymCtx;
48  ubyte enabled;
49 } aesCTRCipherContext, AES_CTR_Ctx;
50 
51 
52 
53 /*------------------------------------------------------------------*/
54 
55 /* Function prototypes */
56 /* for AES CTR, the keyMaterial is key + block --- iv is NOT used in DoAESCTR */
57 /* for RFC3686, construct the block and do not pass the IV as the iv argument */
58 /* the block is incremented by 1 for each encryption so as to be compatible with RFC 3686
59 and the EAX mode -- */
60 
125 #ifdef __UCOS_DIRECT_RTOS__
126 
129 MOC_EXTERN BulkCtx CreateAESCTRCtx(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte* keyMaterial, sbyte4 keyLength, sbyte4 encrypt);
133 #else
134 MOC_EXTERN BulkCtx CreateAESCTRCtx(MOC_SYM(hwAccelDescr hwAccelCtx) const ubyte* keyMaterial, sbyte4 keyLength, sbyte4 encrypt);
135 #endif /* __UCOS_DIRECT_RTOS__ */
136 
178 MOC_EXTERN MSTATUS DeleteAESCTRCtx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ctx);
179 
233 MOC_EXTERN MSTATUS DoAESCTR(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte* data, sbyte4 dataLength, sbyte4 encrypt, ubyte* iv);
234 
235 /* this might be easier to use in some cases */
236 
269 MOC_EXTERN MSTATUS AESCTRInit(MOC_SYM(hwAccelDescr hwAccelCtx) AES_CTR_Ctx* aesCtrCtx, const ubyte* keyMaterial, sbyte4 keyLength, const ubyte initCounter[AES_BLOCK_SIZE]);
270 
326 MOC_EXTERN MSTATUS DoAESCTREx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte* data, sbyte4 dataLength, sbyte4 encrypt, ubyte* iv, sbyte4 limit);
327 
354 MOC_EXTERN MSTATUS GetCounterBlockAESCTR(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte pCounterBuffer[AES_BLOCK_SIZE]);
355 
366 MOC_EXTERN MSTATUS CloneAESCTRCtx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx);
367 
368 #ifdef __ENABLE_MOCANA_IPSEC_SERVICE__
369 
434 MOC_EXTERN BulkCtx CreateAesCtrCtx(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte* keyMaterial,
435  sbyte4 keyLength, sbyte4 encrypt);
436 
488 MOC_EXTERN MSTATUS DoAesCtr(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte* data,
489  sbyte4 dataLength, sbyte4 encrypt, ubyte* iv);
490 
542 MOC_EXTERN MSTATUS DoAesCtrEx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte* data,
543  sbyte4 dataLength, sbyte4 encrypt, ubyte* iv);
544 #endif
545 
546 
547 #ifdef __cplusplus
548 }
549 #endif
550 
551 #endif /* __AES_CTR_HEADER__ */
552 
MOC_EXTERN MSTATUS AESCTRInit(MOC_SYM(hwAccelDescr hwAccelCtx) AES_CTR_Ctx *aesCtrCtx, const ubyte *keyMaterial, sbyte4 keyLength, const ubyte initCounter[AES_BLOCK_SIZE])
Prepare the key schedule for an existing AES-CTR context.
MOC_EXTERN MSTATUS CloneAESCTRCtx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx)
Clone a AES-CTR context.
MOC_EXTERN MSTATUS DoAesCtrEx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *data, sbyte4 dataLength, sbyte4 encrypt, ubyte *iv)
AES-CTR encrypt or decrypt a data buffer.
MOC_EXTERN MSTATUS DoAESCTR(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *data, sbyte4 dataLength, sbyte4 encrypt, ubyte *iv)
AES-CTR encrypt or decrypt a data buffer.
MOC_EXTERN MSTATUS DeleteAESCTRCtx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ctx)
Delete AES-CTR context data structure.
MOC_EXTERN BulkCtx CreateAESCTRCtx(MOC_SYM(hwAccelDescr hwAccelCtx) const ubyte *keyMaterial, sbyte4 keyLength, sbyte4 encrypt)
Create a new AES-CTR context data structure and prepare the key schedule.
MOC_EXTERN BulkCtx CreateAesCtrCtx(MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *keyMaterial, sbyte4 keyLength, sbyte4 encrypt)
Create a new AES-CTR context data structure and prepare the key schedule for using with IPsec Encapsu...
MOC_EXTERN MSTATUS DoAESCTREx(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *data, sbyte4 dataLength, sbyte4 encrypt, ubyte *iv, sbyte4 limit)
AES-CTR encrypt or decrypt a data buffer.
MOC_EXTERN MSTATUS GetCounterBlockAESCTR(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte pCounterBuffer[AES_BLOCK_SIZE])
AES-CTR get current counter block used in given context.
MOC_EXTERN MSTATUS DoAesCtr(MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *data, sbyte4 dataLength, sbyte4 encrypt, ubyte *iv)
AES-CTR encrypt or decrypt a data buffer.