1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** NetX Crypto Component                                                 */
17 /**                                                                       */
18 /**   CCM Mode                                                            */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 /**************************************************************************/
25 /*                                                                        */
26 /*  APPLICATION INTERFACE DEFINITION                       RELEASE        */
27 /*                                                                        */
28 /*    nx_crypto_ccm.h                                     PORTABLE C      */
29 /*                                                           6.1          */
30 /*  AUTHOR                                                                */
31 /*                                                                        */
32 /*    Timothy Stapko, Microsoft Corporation                               */
33 /*                                                                        */
34 /*  DESCRIPTION                                                           */
35 /*                                                                        */
36 /*    This file defines the basic Application Interface (API) to the      */
37 /*    NetX Crypto CCM module.                                             */
38 /*                                                                        */
39 /*  RELEASE HISTORY                                                       */
40 /*                                                                        */
41 /*    DATE              NAME                      DESCRIPTION             */
42 /*                                                                        */
43 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
44 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
45 /*                                            resulting in version 6.1    */
46 /*                                                                        */
47 /**************************************************************************/
48 
49 #ifndef NX_CRYPTO_CCM_H
50 #define NX_CRYPTO_CCM_H
51 
52 /* Determine if a C++ compiler is being used.  If so, ensure that standard
53    C is used to process the API information.  */
54 #ifdef __cplusplus
55 
56 /* Yes, C++ compiler is present.  Use standard C.  */
57 extern   "C" {
58 
59 #endif
60 
61 /* Include the ThreadX and port-specific data type file.  */
62 
63 #include "nx_crypto.h"
64 
65 #define NX_CRYPTO_CCM_BLOCK_SIZE 16
66 
67 typedef struct NX_CRYPTO_CCM_STRUCT
68 {
69 
70     /* Internal context of CCM mode. */
71     USHORT nx_crypto_ccm_icv_length;
72     UCHAR nx_crypto_ccm_reserved[2];
73     UCHAR nx_crypto_ccm_A[NX_CRYPTO_CCM_BLOCK_SIZE];
74     UCHAR nx_crypto_ccm_X[NX_CRYPTO_CCM_BLOCK_SIZE];
75 
76     /* Pointer of additional data. */
77     VOID *nx_crypto_ccm_additional_data;
78 
79     /* Length of additional data. */
80     UINT nx_crypto_ccm_additional_data_len;
81 } NX_CRYPTO_CCM;
82 
83 NX_CRYPTO_KEEP UINT _nx_crypto_ccm_encrypt_init(VOID *crypto_metadata, NX_CRYPTO_CCM *ccm_metadata,
84                                                 UINT (*crypto_function)(VOID *, UCHAR *, UCHAR *, UINT),
85                                                 VOID *additional_data, UINT additional_len,
86                                                 UINT length, UCHAR *iv, USHORT icv_len, USHORT block_size);
87 
88 NX_CRYPTO_KEEP UINT _nx_crypto_ccm_encrypt_update(UINT op, VOID *crypto_metadata, NX_CRYPTO_CCM *ccm_metadata,
89                                                   UINT (*crypto_function)(VOID *, UCHAR *, UCHAR *, UINT),
90                                                   UCHAR *input, UCHAR *output, UINT length, UINT block_size);
91 
92 NX_CRYPTO_KEEP UINT _nx_crypto_ccm_encrypt_calculate(VOID *crypto_metadata, NX_CRYPTO_CCM *ccm_metadata,
93                                                      UINT (*crypto_function)(VOID *, UCHAR *, UCHAR *, UINT),
94                                                      UCHAR *icv, UINT block_size);
95 NX_CRYPTO_KEEP UINT _nx_crypto_ccm_decrypt_calculate(VOID *crypto_metadata, NX_CRYPTO_CCM *ccm_metadata,
96                                                      UINT (*crypto_function)(VOID *, UCHAR *, UCHAR *, UINT),
97                                                      UCHAR *icv, UINT block_size);
98 
99 #define _nx_crypto_ccm_decrypt_init         _nx_crypto_ccm_encrypt_init
100 #define _nx_crypto_ccm_decrypt_update       _nx_crypto_ccm_encrypt_update
101 
102 
103 #ifdef __cplusplus
104 }
105 #endif
106 
107 
108 #endif /* NX_CRYPTO_CCM_H */
109 
110