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 /** GCM Mode */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 24 /**************************************************************************/ 25 /* */ 26 /* APPLICATION INTERFACE DEFINITION RELEASE */ 27 /* */ 28 /* nx_crypto_gcm.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 GCM 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_GCM_H 50 #define NX_CRYPTO_GCM_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 66 #define NX_CRYPTO_GCM_BLOCK_SIZE 16 67 #define NX_CRYPTO_GCM_BLOCK_SIZE_BITS 128 68 #define NX_CRYPTO_GCM_BLOCK_SIZE_INT 4 69 #define NX_CRYPTO_GCM_BLOCK_SIZE_SHIFT 4 70 71 typedef struct NX_CRYPTO_GCM_STRUCT 72 { 73 74 /* Total length of input. */ 75 ULONG nx_crypto_gcm_input_total_length; 76 77 /* Internal context of GCM mode. */ 78 UCHAR nx_crypto_gcm_hkey[NX_CRYPTO_GCM_BLOCK_SIZE]; 79 UCHAR nx_crypto_gcm_j0[NX_CRYPTO_GCM_BLOCK_SIZE]; 80 UCHAR nx_crypto_gcm_s[NX_CRYPTO_GCM_BLOCK_SIZE]; 81 UCHAR nx_crypto_gcm_counter[NX_CRYPTO_GCM_BLOCK_SIZE]; 82 83 /* Pointer of additional data. */ 84 VOID *nx_crypto_gcm_additional_data; 85 86 /* Length of additional data. */ 87 UINT nx_crypto_gcm_additional_data_len; 88 } NX_CRYPTO_GCM; 89 90 NX_CRYPTO_KEEP UINT _nx_crypto_gcm_encrypt_init(VOID *crypto_metadata, NX_CRYPTO_GCM *gcm_metadata, 91 UINT (*crypto_function)(VOID *, UCHAR *, UCHAR *, UINT), 92 VOID *additional_data, UINT additional_len, 93 UCHAR *iv, UINT block_size); 94 95 NX_CRYPTO_KEEP UINT _nx_crypto_gcm_encrypt_update(VOID *crypto_metadata, NX_CRYPTO_GCM *gcm_metadata, 96 UINT (*crypto_function)(VOID *, UCHAR *, UCHAR *, UINT), 97 UCHAR *input, UCHAR *output, UINT length, 98 UINT block_size); 99 100 NX_CRYPTO_KEEP UINT _nx_crypto_gcm_encrypt_calculate(VOID *crypto_metadata, NX_CRYPTO_GCM *gcm_metadata, 101 UINT (*crypto_function)(VOID *, UCHAR *, UCHAR *, UINT), 102 UCHAR *output, UINT icv_len, UINT block_size); 103 104 NX_CRYPTO_KEEP UINT _nx_crypto_gcm_decrypt_update(VOID *crypto_metadata, NX_CRYPTO_GCM *gcm_metadata, 105 UINT (*crypto_function)(VOID *, UCHAR *, UCHAR *, UINT), 106 UCHAR *input, UCHAR *output, UINT length, 107 UINT block_size); 108 109 NX_CRYPTO_KEEP UINT _nx_crypto_gcm_decrypt_calculate(VOID *crypto_metadata, NX_CRYPTO_GCM *gcm_metadata, 110 UINT (*crypto_function)(VOID *, UCHAR *, UCHAR *, UINT), 111 UCHAR *input, UINT icv_len, UINT block_size); 112 113 #define _nx_crypto_gcm_decrypt_init _nx_crypto_gcm_encrypt_init 114 115 #ifdef __cplusplus 116 } 117 #endif 118 119 120 #endif /* NX_CRYPTO_GCM_H */ 121 122