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 /**    X.509 Digital Certificates                                         */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define NX_SECURE_SOURCE_CODE
24 
25 #include "nx_secure_x509.h"
26 
27 #ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE
28 
29 /* Supported named curves. */
30 const USHORT *_nx_secure_x509_ecc_supported_groups;
31 
32 /* Number of supported named curves. */
33 USHORT  _nx_secure_x509_ecc_supported_groups_count;
34 
35 /* Corresponding crypto methods for the supported named curve. */
36 const NX_CRYPTO_METHOD **_nx_secure_x509_ecc_curves;
37 
38 /**************************************************************************/
39 /*                                                                        */
40 /*  FUNCTION                                               RELEASE        */
41 /*                                                                        */
42 /*    _nx_secure_x509_find_curve_method                   PORTABLE C      */
43 /*                                                           6.1.6        */
44 /*  AUTHOR                                                                */
45 /*                                                                        */
46 /*    Timothy Stapko, Microsoft Corporation                               */
47 /*                                                                        */
48 /*  DESCRIPTION                                                           */
49 /*                                                                        */
50 /*    This function finds the curve method for the specified named curve  */
51 /*    ID.                                                                 */
52 /*                                                                        */
53 /*  INPUT                                                                 */
54 /*                                                                        */
55 /*    named_curve                           Named curve ID                */
56 /*    curve_method                          Pointer to hold the curve     */
57 /*                                            method                      */
58 /*                                                                        */
59 /*  OUTPUT                                                                */
60 /*                                                                        */
61 /*    status                                Completion status             */
62 /*                                                                        */
63 /*  CALLS                                                                 */
64 /*                                                                        */
65 /*    None                                                                */
66 /*                                                                        */
67 /*  CALLED BY                                                             */
68 /*                                                                        */
69 /*    _nx_secure_x509_certificate_verify    Verify a certificate          */
70 /*    _nx_secure_x509_crl_verify            Verify revocation list        */
71 /*                                                                        */
72 /*  RELEASE HISTORY                                                       */
73 /*                                                                        */
74 /*    DATE              NAME                      DESCRIPTION             */
75 /*                                                                        */
76 /*  04-02-2021     Timothy Stapko           Initial Version 6.1.6         */
77 /*                                                                        */
78 /**************************************************************************/
_nx_secure_x509_find_curve_method(USHORT named_curve,const NX_CRYPTO_METHOD ** curve_method)79 UINT _nx_secure_x509_find_curve_method(USHORT named_curve, const NX_CRYPTO_METHOD **curve_method)
80 {
81 USHORT i;
82 
83     /* Find out the curve method for the named curve. */
84     for (i = 0; i < _nx_secure_x509_ecc_supported_groups_count; i++)
85     {
86         if (named_curve == _nx_secure_x509_ecc_supported_groups[i])
87         {
88             *curve_method = _nx_secure_x509_ecc_curves[i];
89             return(NX_SECURE_X509_SUCCESS);
90         }
91     }
92 
93     *curve_method = NX_CRYPTO_NULL;
94     return(NX_CRYTPO_MISSING_ECC_CURVE);
95 }
96 #endif /* NX_SECURE_ENABLE_ECC_CIPHERSUITE */
97