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