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 /** Transport Layer Security (TLS) */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define NX_SECURE_SOURCE_CODE
23
24 #include "nx_secure_tls.h"
25
26 /**************************************************************************/
27 /* */
28 /* FUNCTION RELEASE */
29 /* */
30 /* _nx_secure_tls_ciphersuite_lookup PORTABLE C */
31 /* 6.1 */
32 /* AUTHOR */
33 /* */
34 /* Timothy Stapko, Microsoft Corporation */
35 /* */
36 /* DESCRIPTION */
37 /* */
38 /* This function returns data about a selected ciphersuite for use */
39 /* in various TLS internal functions, such as the ciphers used and */
40 /* associated key sizes. */
41 /* */
42 /* INPUT */
43 /* */
44 /* tls_session TLS session control block */
45 /* ciphersuite Ciphersuite value */
46 /* info Pointer to ciphersuite info */
47 /* structure (output) */
48 /* priority Priority index of ciphersuite */
49 /* in the ciphersuite table */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* status Completion status */
54 /* */
55 /* CALLS */
56 /* */
57 /* None */
58 /* */
59 /* CALLED BY */
60 /* */
61 /* _nx_secure_dtls_process_clienthello Process ClientHello */
62 /* _nx_secure_tls_process_clienthello Process ClientHello */
63 /* _nx_secure_tls_process_serverhello Process ServerHello */
64 /* */
65 /* RELEASE HISTORY */
66 /* */
67 /* DATE NAME DESCRIPTION */
68 /* */
69 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
70 /* 09-30-2020 Timothy Stapko Modified comment(s), return */
71 /* priority of selected suite, */
72 /* resulting in version 6.1 */
73 /* */
74 /**************************************************************************/
_nx_secure_tls_ciphersuite_lookup(NX_SECURE_TLS_SESSION * tls_session,UINT ciphersuite,NX_SECURE_TLS_CIPHERSUITE_INFO const ** info,USHORT * priority)75 UINT _nx_secure_tls_ciphersuite_lookup(NX_SECURE_TLS_SESSION *tls_session, UINT ciphersuite,
76 NX_SECURE_TLS_CIPHERSUITE_INFO const **info, USHORT *priority)
77 {
78 USHORT index;
79 NX_SECURE_TLS_CIPHERSUITE_INFO *cipher_table;
80 USHORT cipher_table_size;
81
82 cipher_table = tls_session -> nx_secure_tls_crypto_table -> nx_secure_tls_ciphersuite_lookup_table;
83 cipher_table_size = tls_session -> nx_secure_tls_crypto_table -> nx_secure_tls_ciphersuite_lookup_table_size;
84
85 /* The number of ciphersuites is very small so a linear search should be fine. */
86 for (index = 0; index < cipher_table_size; ++index)
87 {
88 /* See if the ciphersuite is supported. */
89 if (cipher_table[index].nx_secure_tls_ciphersuite == ciphersuite)
90 {
91 /* Return the ciphersuite information. */
92 *info = &cipher_table[index];
93
94 /* Return the priority index (lower number == higher priority). */
95 *priority = index;
96 return(NX_SUCCESS);
97 }
98 }
99
100 /* No ciphersuite found, suite unknown. */
101 return(NX_SECURE_TLS_UNKNOWN_CIPHERSUITE);
102 }
103
104