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 /**   Transport Layer Security (TLS)                                      */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 /* Determine if a C++ compiler is being used.  If so, ensure that standard
24    C is used to process the API information.  */
25 #ifdef __cplusplus
26 
27 /* Yes, C++ compiler is present.  Use standard C.  */
28 extern   "C" {
29 
30 #endif
31 
32 #include "nx_crypto_phash.h"
33 #include "nx_crypto_hmac_sha1.h"
34 #include "nx_crypto_hmac_md5.h"
35 
36 /**************************************************************************/
37 /*                                                                        */
38 /*  COMPONENT DEFINITION                                   RELEASE        */
39 /*                                                                        */
40 /*    nx_crypto_tls_prf_1.h                               PORTABLE C      */
41 /*                                                           6.1          */
42 /*  AUTHOR                                                                */
43 /*                                                                        */
44 /*    Timothy Stapko, Microsoft Corporation                               */
45 /*                                                                        */
46 /*  DESCRIPTION                                                           */
47 /*                                                                        */
48 /*    This file defines the TLS Pseudo-Random Function (PRF) as described */
49 /*    in RFCs 2246 and 4346. This PRF is used for all key generation in   */
50 /*    TLS versions 1.0 and 1.1.                                           */
51 /*                                                                        */
52 /*  RELEASE HISTORY                                                       */
53 /*                                                                        */
54 /*    DATE              NAME                      DESCRIPTION             */
55 /*                                                                        */
56 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
57 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
58 /*                                            resulting in version 6.1    */
59 /*                                                                        */
60 /**************************************************************************/
61 
62 /* Define the control block structure for backward compatibility. */
63 #define NX_SECURE_TLS_PRF_1                     NX_CRYPTO_TLS_PRF_1
64 
65 typedef struct NX_CRYPTO_TLS_PRF_1_STRUCT
66 {
67     NX_CRYPTO_PHASH nx_secure_tls_prf_phash_info;
68     UCHAR nx_secure_tls_prf_label_seed_buffer[80]; /* phash_seed = label(13 bytes) || prf_seed(64 bytes) */
69     UCHAR nx_secure_tls_prf_temp_A_buffer[100]; /* The temp_A buffer needs to be large enough to holdthe lable(13 bytes) || prf_seed(64 bytes) || hash_size(20 bytes for SHA1/MD5) */
70     UCHAR nx_secure_tls_prf_temp_hmac_output_buffer[20]; /* The temp buffer for the output buffer of hmac(secret, A(i) + seed) */
71     UCHAR nx_secure_tls_prf_hmac_metadata_area[sizeof(NX_CRYPTO_SHA1_HMAC) + sizeof(NX_CRYPTO_MD5_HMAC)]; /* metadata buffer for the hmac function */
72 } NX_CRYPTO_TLS_PRF_1;
73 
74 UINT _nx_crypto_method_prf_1_init(struct NX_CRYPTO_METHOD_STRUCT *method,
75                                   UCHAR *key, NX_CRYPTO_KEY_SIZE key_size_in_bits,
76                                   VOID **handle,
77                                   VOID *crypto_metadata,
78                                   ULONG crypto_metadata_size);
79 
80 UINT _nx_crypto_method_prf_1_cleanup(VOID *crypto_metadata);
81 
82 UINT _nx_crypto_method_prf_1_operation(UINT op,      /* Encrypt, Decrypt, Authenticate */
83                                        VOID *handle, /* Crypto handler */
84                                        struct NX_CRYPTO_METHOD_STRUCT *method,
85                                        UCHAR *key, NX_CRYPTO_KEY_SIZE key_size_in_bits,
86                                        UCHAR *input, ULONG input_length_in_byte,
87                                        UCHAR *iv_ptr,
88                                        UCHAR *output, ULONG output_length_in_byte,
89                                        VOID *crypto_metadata, ULONG crypto_metadata_size,
90                                        VOID *packet_ptr,
91                                        VOID (*nx_crypto_hw_process_callback)(VOID *packet_ptr, UINT status));
92 
93 #ifdef __cplusplus
94 }
95 #endif
96