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_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 in DTLS PSK key add call. */
39 /* */
40 /* INPUT */
41 /* */
42 /* dtls_session Pointer to DTLS Session */
43 /* pre_shared_key Pointer to PSK data */
44 /* psk_length Length of PSK data */
45 /* psk_identity PSK identity data */
46 /* identity_length Length of identity data */
47 /* hint PSK hint data */
48 /* hint_length Length of hint data */
49 /* */
50 /* OUTPUT */
51 /* */
52 /* status Completion status */
53 /* */
54 /* CALLS */
55 /* */
56 /* _nx_secure_dtls_psk_add The actual DTLS PSK add call. */
57 /* */
58 /* CALLED BY */
59 /* */
60 /* Application Code */
61 /* */
62 /* RELEASE HISTORY */
63 /* */
64 /* DATE NAME DESCRIPTION */
65 /* */
66 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
67 /* 09-30-2020 Timothy Stapko Modified comment(s), */
68 /* resulting in version 6.1 */
69 /* */
70 /**************************************************************************/
71 #if defined(NX_SECURE_ENABLE_PSK_CIPHERSUITES) || defined(NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE)
_nxe_secure_dtls_psk_add(NX_SECURE_DTLS_SESSION * dtls_session,UCHAR * pre_shared_key,UINT psk_length,UCHAR * psk_identity,UINT identity_length,UCHAR * hint,UINT hint_length)72 UINT _nxe_secure_dtls_psk_add(NX_SECURE_DTLS_SESSION *dtls_session, UCHAR *pre_shared_key,
73 UINT psk_length, UCHAR *psk_identity, UINT identity_length, UCHAR *hint,
74 UINT hint_length)
75 {
76 #ifdef NX_SECURE_ENABLE_DTLS
77 UINT status;
78
79 if(dtls_session == NX_NULL)
80 {
81 return(NX_PTR_ERROR);
82 }
83
84 /* Make sure the session is initialized. */
85 if(dtls_session->nx_secure_dtls_tls_session.nx_secure_tls_id != NX_SECURE_TLS_ID)
86 {
87 return(NX_SECURE_TLS_SESSION_UNINITIALIZED);
88 }
89
90 /* Call actual function. */
91 status = _nx_secure_dtls_psk_add(dtls_session, pre_shared_key, psk_length, psk_identity, identity_length, hint, hint_length);
92
93 return(status);
94 #else
95 NX_PARAMETER_NOT_USED(dtls_session);
96 NX_PARAMETER_NOT_USED(pre_shared_key);
97 NX_PARAMETER_NOT_USED(psk_length);
98 NX_PARAMETER_NOT_USED(psk_identity);
99 NX_PARAMETER_NOT_USED(identity_length);
100 NX_PARAMETER_NOT_USED(hint);
101 NX_PARAMETER_NOT_USED(hint_length);
102
103 return(NX_NOT_SUPPORTED);
104 #endif /* NX_SECURE_ENABLE_DTLS */
105 }
106 #endif
107
108