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 Secure Component                                                 */
16 /**                                                                       */
17 /**    Datagram Transport Layer Security (DTLS)                           */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define NX_SECURE_SOURCE_CODE
23 
24 #include "nx_secure_dtls.h"
25 
26 /**************************************************************************/
27 /*                                                                        */
28 /*  FUNCTION                                               RELEASE        */
29 /*                                                                        */
30 /*    _nxe_secure_dtls_server_psk_add                     PORTABLE C      */
31 /*                                                           6.1          */
32 /*  AUTHOR                                                                */
33 /*                                                                        */
34 /*    Timothy Stapko, Microsoft Corporation                               */
35 /*                                                                        */
36 /*  DESCRIPTION                                                           */
37 /*                                                                        */
38 /*    This function checks for errors when adding a Pre-Shared Key (PSK)  */
39 /*    to a DTLS server instance.                                          */
40 /*                                                                        */
41 /*  INPUT                                                                 */
42 /*                                                                        */
43 /*    server_ptr                            DTLS server control block     */
44 /*    pre_shared_key                        Pointer to PSK data           */
45 /*    psk_length                            Length of PSK data            */
46 /*    psk_identity                          PSK id data                   */
47 /*    identity_length                       Length of PSK id data         */
48 /*    hint                                  PSK hint data                 */
49 /*    hint_length                           Length of PSK hint data       */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    status                                Completion status             */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    _nx_secure_dtls_server_psk_add        Actual function call          */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    Application Code                                                    */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
68 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
69 /*                                            resulting in version 6.1    */
70 /*                                                                        */
71 /**************************************************************************/
72 #if defined(NX_SECURE_ENABLE_PSK_CIPHERSUITES) || defined(NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE)
_nxe_secure_dtls_server_psk_add(NX_SECURE_DTLS_SERVER * server_ptr,UCHAR * pre_shared_key,UINT psk_length,UCHAR * psk_identity,UINT identity_length,UCHAR * hint,UINT hint_length)73 UINT _nxe_secure_dtls_server_psk_add(NX_SECURE_DTLS_SERVER *server_ptr, UCHAR *pre_shared_key,
74                                     UINT psk_length, UCHAR *psk_identity, UINT identity_length, UCHAR *hint,
75                                     UINT hint_length)
76 {
77 #ifdef NX_SECURE_ENABLE_DTLS
78 UINT status;
79 
80     if(server_ptr == NX_NULL)
81     {
82         return(NX_PTR_ERROR);
83     }
84 
85     /* Call actual function. */
86     status = _nx_secure_dtls_server_psk_add(server_ptr, pre_shared_key, psk_length, psk_identity, identity_length, hint, hint_length);
87 
88     return(status);
89 #else
90     NX_PARAMETER_NOT_USED(server_ptr);
91     NX_PARAMETER_NOT_USED(pre_shared_key);
92     NX_PARAMETER_NOT_USED(psk_length);
93     NX_PARAMETER_NOT_USED(psk_identity);
94     NX_PARAMETER_NOT_USED(identity_length);
95     NX_PARAMETER_NOT_USED(hint);
96     NX_PARAMETER_NOT_USED(hint_length);
97 
98     return(NX_NOT_SUPPORTED);
99 #endif /* NX_SECURE_ENABLE_DTLS */
100 }
101 #endif
102