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 Secure Component                                                 */
17 /**                                                                       */
18 /**    Transport Layer Security (TLS)                                     */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define NX_SECURE_SOURCE_CODE
24 
25 #include "nx_secure_tls.h"
26 
27 /**************************************************************************/
28 /*                                                                        */
29 /*  FUNCTION                                               RELEASE        */
30 /*                                                                        */
31 /*    _nx_secure_tls_session_create                       PORTABLE C      */
32 /*                                                           6.1          */
33 /*  AUTHOR                                                                */
34 /*                                                                        */
35 /*    Timothy Stapko, Microsoft Corporation                               */
36 /*                                                                        */
37 /*  DESCRIPTION                                                           */
38 /*                                                                        */
39 /*    This function initializes a TLS session control block for later     */
40 /*    use in establishing a secure TLS session over a TCP socket or       */
41 /*    other lower-level networking protocol.                              */
42 /*                                                                        */
43 /*    To calculate the necessary metadata size, the API                   */
44 /*    nx_secure_tls_metadata_size_calculate may be used.                  */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    session_ptr                           TLS session control block     */
49 /*    crypto_table                          crypto method table           */
50 /*    metadata_buffer                       Encryption metadata area      */
51 /*    metadata_size                         Encryption metadata size      */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    status                                Completion status             */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _nx_secure_tls_session_reset          Clear out the session         */
60 /*    tx_mutex_get                          Get protection mutex          */
61 /*    tx_mutex_put                          Put protection mutex          */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    Application Code                                                    */
66 /*    _nx_secure_dtls_session_create        Create DTLS session           */
67 /*                                                                        */
68 /*  RELEASE HISTORY                                                       */
69 /*                                                                        */
70 /*    DATE              NAME                      DESCRIPTION             */
71 /*                                                                        */
72 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
73 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
74 /*                                            resulting in version 6.1    */
75 /*                                                                        */
76 /**************************************************************************/
_nx_secure_tls_session_create(NX_SECURE_TLS_SESSION * session_ptr,const NX_SECURE_TLS_CRYPTO * crypto_table,VOID * metadata_buffer,ULONG metadata_size)77 UINT _nx_secure_tls_session_create(NX_SECURE_TLS_SESSION *session_ptr,
78                                    const NX_SECURE_TLS_CRYPTO *crypto_table,
79                                    VOID *metadata_buffer,
80                                    ULONG metadata_size)
81 {
82     UINT                            status;
83 
84     NX_SECURE_MEMSET(session_ptr, 0, sizeof(NX_SECURE_TLS_SESSION));
85 
86     /* Assign the table to the session. */
87     /* Cast away "const" for new API. */
88     session_ptr -> nx_secure_tls_crypto_table = (NX_SECURE_TLS_CRYPTO *)(crypto_table);
89 
90     status = _nx_secure_tls_session_create_ext(session_ptr, NX_NULL, 0, NX_NULL, 0, metadata_buffer, metadata_size);
91 
92     return(status);
93 }
94 
95