1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** NetX Crypto Component                                                 */
16 /**                                                                       */
17 /**   CTR Mode                                                            */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /**************************************************************************/
24 /*                                                                        */
25 /*  APPLICATION INTERFACE DEFINITION                       RELEASE        */
26 /*                                                                        */
27 /*    nx_crypto_ctr.h                                     PORTABLE C      */
28 /*                                                           6.1          */
29 /*  AUTHOR                                                                */
30 /*                                                                        */
31 /*    Timothy Stapko, Microsoft Corporation                               */
32 /*                                                                        */
33 /*  DESCRIPTION                                                           */
34 /*                                                                        */
35 /*    This file defines the basic Application Interface (API) to the      */
36 /*    NetX Crypto CTR module.                                             */
37 /*                                                                        */
38 /*  RELEASE HISTORY                                                       */
39 /*                                                                        */
40 /*    DATE              NAME                      DESCRIPTION             */
41 /*                                                                        */
42 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
43 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
44 /*                                            resulting in version 6.1    */
45 /*                                                                        */
46 /**************************************************************************/
47 
48 #ifndef NX_CRYPTO_CTR_H
49 #define NX_CRYPTO_CTR_H
50 
51 /* Determine if a C++ compiler is being used.  If so, ensure that standard
52    C is used to process the API information.  */
53 #ifdef __cplusplus
54 
55 /* Yes, C++ compiler is present.  Use standard C.  */
56 extern   "C" {
57 
58 #endif
59 
60 /* Include the ThreadX and port-specific data type file.  */
61 
62 #include "nx_crypto.h"
63 
64 #define NX_CRYPTO_CTR_BLOCK_SIZE 16
65 
66 typedef struct NX_CRYPTO_CTR_STRUCT
67 {
68 
69     /* Counter block. */
70     UCHAR nx_crypto_ctr_counter_block[NX_CRYPTO_CTR_BLOCK_SIZE];
71 } NX_CRYPTO_CTR;
72 
73 /* The CTR mode is symmetric - encryption and decryption are the same operation. */
74 NX_CRYPTO_KEEP UINT _nx_crypto_ctr_encrypt(VOID *crypto_metadata, NX_CRYPTO_CTR *ctr_metadata,
75                                            UINT (*crypto_function)(VOID *, UCHAR *, UCHAR *, UINT),
76                                            UCHAR *input, UCHAR *output, UINT length, UINT block_size);
77 NX_CRYPTO_KEEP UINT _nx_crypto_ctr_encrypt_init(NX_CRYPTO_CTR *ctr_metadata, UCHAR *iv, UINT iv_len,
78                                                 UCHAR *nonce, UINT nonce_len);
79 #define _nx_crypto_ctr_decrypt   _nx_crypto_ctr_encrypt
80 
81 
82 #ifdef __cplusplus
83 }
84 #endif
85 
86 
87 #endif /* NX_CRYPTO_CTR_H */
88 
89