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 /** DES Encryption Standard (DES) */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 24 /**************************************************************************/ 25 /* */ 26 /* COMPONENT DEFINITION RELEASE */ 27 /* */ 28 /* nx_crypto_des.h PORTABLE C */ 29 /* 6.1 */ 30 /* AUTHOR */ 31 /* */ 32 /* Timothy Stapko, Microsoft Corporation */ 33 /* */ 34 /* DESCRIPTION */ 35 /* */ 36 /* This file defines the NetX DES encryption algorithm, derived */ 37 /* principally from FIPS-46. From an 8 bytes of raw input, the DES */ 38 /* encryption routine produces an 8-byte encryption of the input. */ 39 /* Conversely, from an 8-byte encryption, the decryption routine */ 40 /* produces the original 8 bytes of input. Note that the caller must */ 41 /* ensure 8 bytes of input and output are provided. */ 42 /* */ 43 /* It is assumed that nx_api.h and nx_port.h have already been */ 44 /* included. */ 45 /* */ 46 /* RELEASE HISTORY */ 47 /* */ 48 /* DATE NAME DESCRIPTION */ 49 /* */ 50 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ 51 /* 09-30-2020 Timothy Stapko Modified comment(s), */ 52 /* resulting in version 6.1 */ 53 /* */ 54 /**************************************************************************/ 55 56 #ifndef _NX_CRYPTO_DES_H_ 57 #define _NX_CRYPTO_DES_H_ 58 59 /* Determine if a C++ compiler is being used. If so, ensure that standard 60 C is used to process the API information. */ 61 #ifdef __cplusplus 62 63 /* Yes, C++ compiler is present. Use standard C. */ 64 extern "C" { 65 66 #endif 67 68 #include "nx_crypto.h" 69 #include "nx_crypto_cbc.h" 70 71 72 #define NX_CRYPTO_DES_KEY_LEN_IN_BITS 64 73 #define NX_CRYPTO_DES_BLOCK_SIZE_IN_BITS 64 74 #define NX_CRYPTO_DES_IV_LEN_IN_BITS 64 75 76 UINT _nx_crypto_method_des_init(struct NX_CRYPTO_METHOD_STRUCT *method, 77 UCHAR *key, NX_CRYPTO_KEY_SIZE key_size_in_bits, 78 VOID **handle, 79 VOID *crypto_metadata, 80 ULONG crypto_metadata_size); 81 82 UINT _nx_crypto_method_des_cleanup(VOID *crypto_metadata); 83 84 UINT _nx_crypto_method_des_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ 85 VOID *handle, /* Crypto handler */ 86 struct NX_CRYPTO_METHOD_STRUCT *method, 87 UCHAR *key, 88 NX_CRYPTO_KEY_SIZE key_size_in_bits, 89 UCHAR *input, 90 ULONG input_length_in_byte, 91 UCHAR *iv_ptr, 92 UCHAR *output, 93 ULONG output_length_in_byte, 94 VOID *crypto_metadata, 95 ULONG crypto_metadata_size, 96 VOID *packet_ptr, 97 VOID (*nx_crypto_hw_process_callback)(VOID *packet_ptr, UINT status)); 98 99 /* Define the DES context structure. */ 100 101 typedef struct NX_CRYPTO_DES_STRUCT 102 { 103 104 ULONG nx_des_encryption_keys[32]; /* Contains the encryption keys */ 105 ULONG nx_des_decryption_keys[32]; /* Contains the decryption keys */ 106 NX_CRYPTO_CBC nx_crypto_cbc_context; /* CBC metadata */ 107 } NX_CRYPTO_DES; 108 109 110 /* Define the function prototypes for DES. */ 111 112 UINT _nx_crypto_des_key_set(NX_CRYPTO_DES * context, UCHAR key[8]); 113 UINT _nx_crypto_des_encrypt(NX_CRYPTO_DES * context, UCHAR source[8], UCHAR destination[8], UINT length); 114 UINT _nx_crypto_des_decrypt(NX_CRYPTO_DES * context, UCHAR source[8], UCHAR destination[8], UINT length); 115 VOID _nx_crypto_des_process_block(UCHAR source[8], UCHAR destination[8], ULONG keys[32]); 116 117 #ifdef __cplusplus 118 } 119 #endif 120 121 #endif 122 123