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