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 /* _nx_secure_dtls_psk_add PORTABLE C */
31 /* 6.1 */
32 /* AUTHOR */
33 /* */
34 /* Timothy Stapko, Microsoft Corporation */
35 /* */
36 /* DESCRIPTION */
37 /* */
38 /* This function adds a pre-shared key (PSK) to a DTLS session for use */
39 /* with a PSK ciphersuite. The second parameter is the PSK identity */
40 /* used during the DTLS handshake to select the proper key. */
41 /* */
42 /* INPUT */
43 /* */
44 /* dtls_session Pointer to DTLS Session */
45 /* pre_shared_key Pointer to PSK data */
46 /* psk_length Length of PSK data */
47 /* psk_identity PSK identity data */
48 /* identity_length Length of identity data */
49 /* hint PSK hint data */
50 /* hint_length Length of hint data */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* status Completion status */
55 /* */
56 /* CALLS */
57 /* */
58 /* _nx_secure_tls_psk_add Add PSK data to TLS */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* Application Code */
63 /* */
64 /* RELEASE HISTORY */
65 /* */
66 /* DATE NAME DESCRIPTION */
67 /* */
68 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
69 /* 09-30-2020 Timothy Stapko Modified comment(s), */
70 /* resulting in version 6.1 */
71 /* */
72 /**************************************************************************/
73 #if defined(NX_SECURE_ENABLE_PSK_CIPHERSUITES) || defined(NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE)
_nx_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)74 UINT _nx_secure_dtls_psk_add(NX_SECURE_DTLS_SESSION *dtls_session, UCHAR *pre_shared_key,
75 UINT psk_length, UCHAR *psk_identity, UINT identity_length, UCHAR *hint,
76 UINT hint_length)
77 {
78 #ifdef NX_SECURE_ENABLE_DTLS
79 UINT status;
80 NX_SECURE_TLS_SESSION *tls_session;
81
82 /* Get the internal TLS session instance. */
83 tls_session = &(dtls_session -> nx_secure_dtls_tls_session);
84
85 /* Call TLS API. */
86 status = _nx_secure_tls_psk_add(tls_session, pre_shared_key, psk_length, psk_identity, identity_length, hint, hint_length);
87
88 return(status);
89 #else
90 NX_PARAMETER_NOT_USED(dtls_session);
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
103