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 /** 3DES Encryption Standard (Triple DES) */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 23 /**************************************************************************/ 24 /* */ 25 /* COMPONENT DEFINITION RELEASE */ 26 /* */ 27 /* nx_crypto_3des.h PORTABLE C */ 28 /* 6.1 */ 29 /* AUTHOR */ 30 /* */ 31 /* Timothy Stapko, Microsoft Corporation */ 32 /* */ 33 /* DESCRIPTION */ 34 /* */ 35 /* This file defines the NetX 3DES encryption algorithm. */ 36 /* It is assumed that nx_api.h and nx_port.h have already been */ 37 /* included. */ 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_3DES_H_ 50 #define _NX_CRYPTO_3DES_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 "nx_crypto.h" 62 #include "nx_crypto_des.h" 63 #include "nx_crypto_cbc.h" 64 65 66 #define NX_CRYPTO_3DES_KEY_LEN_IN_BITS 192 67 #define NX_CRYPTO_3DES_BLOCK_SIZE_IN_BITS 64 68 #define NX_CRYPTO_3DES_IV_LEN_IN_BITS 64 69 70 UINT _nx_crypto_method_3des_init(struct NX_CRYPTO_METHOD_STRUCT *method, 71 UCHAR *key, NX_CRYPTO_KEY_SIZE key_size_in_bits, 72 VOID **handle, 73 VOID *crypto_metadata, 74 ULONG crypto_metadata_size); 75 76 UINT _nx_crypto_method_3des_cleanup(VOID *crypto_metadata); 77 78 UINT _nx_crypto_method_3des_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ 79 VOID *handle, /* Crypto handler */ 80 struct NX_CRYPTO_METHOD_STRUCT *method, 81 UCHAR *key, 82 NX_CRYPTO_KEY_SIZE key_size_in_bits, 83 UCHAR *input, 84 ULONG input_length_in_byte, 85 UCHAR *iv_ptr, 86 UCHAR *output, 87 ULONG output_length_in_byte, 88 VOID *crypto_metadata, 89 ULONG crypto_metadata_size, 90 VOID *packet_ptr, 91 VOID (*nx_crypto_hw_process_callback)(VOID *packet_ptr, UINT status)); 92 93 94 /* Define the 3DES context structure. */ 95 96 typedef struct NX_CRYPTO_3DES_STRUCT 97 { 98 99 NX_CRYPTO_DES des_1; 100 NX_CRYPTO_DES des_2; 101 NX_CRYPTO_DES des_3; 102 NX_CRYPTO_CBC nx_crypto_cbc_context; 103 } NX_CRYPTO_3DES; 104 105 106 /* Define the function prototypes for DES. */ 107 108 UINT _nx_crypto_3des_key_set(NX_CRYPTO_3DES * context, UCHAR key[24]); 109 UINT _nx_crypto_3des_encrypt(NX_CRYPTO_3DES * context, UCHAR source[8], UCHAR destination[8], UINT length); 110 UINT _nx_crypto_3des_decrypt(NX_CRYPTO_3DES * context, UCHAR source[8], UCHAR destination[8], UINT length); 111 112 113 #ifdef __cplusplus 114 } 115 #endif 116 117 #endif 118 119