AzureMXChip/MXCHIPAZ3166/core/lib/netxduo/nx_secure/src/nx_secure_tls_session_create_ext.c
static UINT _find_cipher(UINT cipher_id, UINT cipher_role_id, UINT key_size, const NX_CRYPTO_METHOD **crypto_array, UINT array_size, const NX_CRYPTO_METHOD **crypto_method)
{
UINT i;

    for(i = 0; i < array_size; ++i)
    {
        if(crypto_array[i]->nx_crypto_algorithm == cipher_id)
        {
            if (cipher_role_id == NX_CRYPTO_ROLE_SYMMETRIC &&
                crypto_array[i] -> nx_crypto_key_size_in_bits != key_size << 3)
            {
                continue;
            }

            *crypto_method = crypto_array[i];
            return(NX_SUCCESS);
        }
    }

    *crypto_method = NX_NULL;
    return(NX_SECURE_TLS_UNSUPPORTED_CIPHER);
}
/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _nx_secure_tls_session_create_ext                   PORTABLE C      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Timothy Stapko, Microsoft Corporation                               */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function is the new-style API for creating a new TLS session.  */
/*    Like the original function, it initializes a TLS session control    */
/*    block for later use in establishing a secure TLS session over a TCP */
/*    socket or other lower-level networking protocol. The difference is  */
/*    that this function takes an un-ordered array of cryptographic       */
/*    methods and a mapping table from ciphersuites to algorithm          */
/*    identifiers so the mapping of crypto methods to ciphersuites can be */
/*    done automatically, rather than needing to link in all possible     */
/*    cipher routines in a single table.                                  */
/*                                                                        */
/*    To calculate the necessary metadata size, the API                   */
/*    nx_secure_tls_metadata_size_calculate may be used.                  */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    session_ptr                           TLS session control block     */
/*    crypto_array                          crypto methods to use         */
/*    cipher_map                            Mapping table for ciphersuites*/
/*    metadata_buffer                       Encryption metadata area      */
/*    metadata_size                         Encryption metadata size      */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    status                                Completion status             */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    _nx_secure_tls_session_reset          Clear out the session         */
/*    tx_mutex_get                          Get protection mutex          */
/*    tx_mutex_put                          Put protection mutex          */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    Application Code                                                    */
/*                                                                        */
/*  RELEASE HISTORY                                                       */
/*                                                                        */
/*    DATE              NAME                      DESCRIPTION             */
/*                                                                        */
/*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
/*  09-30-2020     Timothy Stapko           Modified comment(s), and      */
/*                                            fixed race condition for    */
/*                                            multithread transmission,   */
/*                                            added ECC initialization,   */
/*                                            fixed renegotiation bug,    */
/*                                            resulting in version 6.1    */
/*                                                                        */
/**************************************************************************/
FUNCTION                                               RELEASE

_nx_secure_tls_session_create_ext                   PORTABLE C
6.1
AUTHOR

Timothy Stapko, Microsoft Corporation

DESCRIPTION

This function is the new-style API for creating a new TLS session.
Like the original function, it initializes a TLS session control
block for later use in establishing a secure TLS session over a TCP
socket or other lower-level networking protocol. The difference is
that this function takes an un-ordered array of cryptographic
methods and a mapping table from ciphersuites to algorithm
identifiers so the mapping of crypto methods to ciphersuites can be
done automatically, rather than needing to link in all possible
cipher routines in a single table.

To calculate the necessary metadata size, the API
nx_secure_tls_metadata_size_calculate may be used.

INPUT

session_ptr                           TLS session control block
crypto_array                          crypto methods to use
cipher_map                            Mapping table for ciphersuites
metadata_buffer                       Encryption metadata area
metadata_size                         Encryption metadata size

OUTPUT

status                                Completion status

CALLS

_nx_secure_tls_session_reset          Clear out the session
tx_mutex_get                          Get protection mutex
tx_mutex_put                          Put protection mutex

CALLED BY

Application Code

RELEASE HISTORY

DATE              NAME                      DESCRIPTION

05-19-2020     Timothy Stapko           Initial Version 6.0
09-30-2020     Timothy Stapko           Modified comment(s), and
fixed race condition for
multithread transmission,
added ECC initialization,
fixed renegotiation bug,
resulting in version 6.1
FUNCTION RELEASE _nx_secure_tls_session_create_ext PORTABLE C 6 . 1 AUTHOR Timothy Stapko Microsoft Corporation DESCRIPTION This function is the new - style API for creating a new TLS session . Like the original function it initializes a TLS session control block for later use in establishing a secure TLS session over a TCP socket or other lower - level networking protocol . The difference is that this function takes an un - ordered array of cryptographic methods and a mapping table from ciphersuites to algorithm identifiers so the mapping of crypto methods to ciphersuites can be done automatically rather than needing to link in all possible cipher routines in a single table . To calculate the necessary metadata size the API nx_secure_tls_metadata_size_calculate may be used . INPUT session_ptr TLS session control block crypto_array crypto methods to use cipher_map Mapping table for ciphersuites metadata_buffer Encryption metadata area metadata_size Encryption metadata size OUTPUT status Completion status CALLS _nx_secure_tls_session_reset Clear out the session tx_mutex_get Get protection mutex tx_mutex_put Put protection mutex CALLED BY Application Code RELEASE HISTORY DATE NAME DESCRIPTION 05 - 19 - 2020 Timothy Stapko Initial Version 6 . 0 09 - 30 - 2020 Timothy Stapko Modified comment ( s ) and fixed race condition for multithread transmission added ECC initialization fixed renegotiation bug resulting in version 6 . 1
static UINT _find_cipher(UINT cipher_id, UINT cipher_role_id, UINT key_size, const NX_CRYPTO_METHOD **crypto_array, UINT array_size, const NX_CRYPTO_METHOD **crypto_method)
{
UINT i;
    for(i = 0; i < array_size; ++i)
    {
        if(crypto_array[i]->nx_crypto_algorithm == cipher_id)
        {
            if (cipher_role_id == NX_CRYPTO_ROLE_SYMMETRIC &&
                crypto_array[i] -> nx_crypto_key_size_in_bits != key_size << 3)
            {
                continue;
            }
            *crypto_method = crypto_array[i];
            return(NX_SUCCESS);
        }
    }
    *crypto_method = NX_NULL;
    return(NX_SECURE_TLS_UNSUPPORTED_CIPHER);
}
static UINT _find_cipher ( UINT cipher_id , UINT cipher_role_id , UINT key_size , const NX_CRYPTO_METHOD * * crypto_array , UINT array_size , const NX_CRYPTO_METHOD * * crypto_method ) { UINT i ; for ( i = 0 ; i < array_size ; ++ i ) { if ( crypto_array [ i ] -> nx_crypto_algorithm == cipher_id ) { if ( cipher_role_id == NX_CRYPTO_ROLE_SYMMETRIC && crypto_array [ i ] -> nx_crypto_key_size_in_bits != key_size << 3 ) { continue ; } * crypto_method = crypto_array [ i ] ; return ( NX_SUCCESS ) ; } } * crypto_method = NX_NULL ; return ( NX_SECURE_TLS_UNSUPPORTED_CIPHER ) ; }
FUNCTION                                               RELEASE
FUNCTION RELEASE