From 7f3520b391f4b6198cfe740484e834b379175d81 Mon Sep 17 00:00:00 2001 From: Ryan Winter Date: Tue, 6 Apr 2021 10:29:43 -0700 Subject: [PATCH 1/2] update threadx/netxduo --- core/lib/netxduo | 2 +- core/lib/threadx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/netxduo b/core/lib/netxduo index 49cd9dd7..7fa5c07d 160000 --- a/core/lib/netxduo +++ b/core/lib/netxduo @@ -1 +1 @@ -Subproject commit 49cd9dd780c8398a49779aaa864e4c8b6cb801d7 +Subproject commit 7fa5c07d272da3c9e39fe037c5c8316ca27ca6ee diff --git a/core/lib/threadx b/core/lib/threadx index 32e3b3b2..b12bd44f 160000 --- a/core/lib/threadx +++ b/core/lib/threadx @@ -1 +1 @@ -Subproject commit 32e3b3b25f4b17ff51ce8a6bad8d9eb32729a0f6 +Subproject commit b12bd44faaca46dbad4b06cb93a8669c6e36e02a From b856382346a511606be7e1d6ac3d498f7a97b474 Mon Sep 17 00:00:00 2001 From: Ryan Winter Date: Tue, 6 Apr 2021 11:47:55 -0700 Subject: [PATCH 2/2] update STM netxduo fork --- .../STM32L4_L4+/lib/netxduo/CMakeLists.txt | 1 + .../STM32L4_L4+/lib/netxduo/common/nx_api.h | 3 + .../lib/netxduo/common/nx_utility.c | 399 ++++++++++++++++++ 3 files changed, 403 insertions(+) diff --git a/STMicroelectronics/STM32L4_L4+/lib/netxduo/CMakeLists.txt b/STMicroelectronics/STM32L4_L4+/lib/netxduo/CMakeLists.txt index 97e949e8..d175071c 100644 --- a/STMicroelectronics/STM32L4_L4+/lib/netxduo/CMakeLists.txt +++ b/STMicroelectronics/STM32L4_L4+/lib/netxduo/CMakeLists.txt @@ -420,6 +420,7 @@ set(SOURCES ${CORE_LIB_DIR}/netxduo/nx_secure/src/nx_secure_x509_extended_key_usage_extension_parse.c ${CORE_LIB_DIR}/netxduo/nx_secure/src/nx_secure_x509_extension_find.c ${CORE_LIB_DIR}/netxduo/nx_secure/src/nx_secure_x509_find_certificate_methods.c + ${CORE_LIB_DIR}/netxduo/nx_secure/src/nx_secure_x509_find_curve_method.c ${CORE_LIB_DIR}/netxduo/nx_secure/src/nx_secure_x509_free_certificate_get.c ${CORE_LIB_DIR}/netxduo/nx_secure/src/nx_secure_x509_key_usage_extension_parse.c ${CORE_LIB_DIR}/netxduo/nx_secure/src/nx_secure_x509_local_certificate_find.c diff --git a/STMicroelectronics/STM32L4_L4+/lib/netxduo/common/nx_api.h b/STMicroelectronics/STM32L4_L4+/lib/netxduo/common/nx_api.h index 1fe0b0bf..646fafbb 100644 --- a/STMicroelectronics/STM32L4_L4+/lib/netxduo/common/nx_api.h +++ b/STMicroelectronics/STM32L4_L4+/lib/netxduo/common/nx_api.h @@ -3835,6 +3835,9 @@ VOID _nx_ip_driver_link_status_event(NX_IP *ip_ptr, UINT interface_index); /* Utility functions. */ UINT _nx_utility_string_length_check(CHAR *input_string, UINT *string_length, UINT max_string_length); +UINT _nx_utility_string_to_uint(CHAR *input_string, UINT string_length, UINT *number); +UINT _nx_utility_base64_encode(UCHAR *name, UINT name_size, UCHAR *base64name, UINT base64name_size, UINT *bytes_copied); +UINT _nx_utility_base64_decode(UCHAR *base64name, UINT base64name_size, UCHAR *name, UINT name_size, UINT *bytes_copied); /* Determine if a C++ compiler is being used. If so, complete the standard C conditional started above. */ diff --git a/STMicroelectronics/STM32L4_L4+/lib/netxduo/common/nx_utility.c b/STMicroelectronics/STM32L4_L4+/lib/netxduo/common/nx_utility.c index eb2aac31..b8d1a827 100644 --- a/STMicroelectronics/STM32L4_L4+/lib/netxduo/common/nx_utility.c +++ b/STMicroelectronics/STM32L4_L4+/lib/netxduo/common/nx_utility.c @@ -28,6 +28,8 @@ #include "tx_api.h" #include "nx_api.h" +/* Define the base64 letters. */ +static CHAR _nx_utility_base64_array[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /**************************************************************************/ /* */ @@ -107,3 +109,400 @@ UINT i; return(NX_SUCCESS); } +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _nx_utility_string_to_uint PORTABLE C */ +/* 6.1.3 */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function converts the string to unsigned integer. */ +/* */ +/* INPUT */ +/* */ +/* input_string Pointer to input string */ +/* string_length Length of input string */ +/* number Pointer to the number */ +/* */ +/* OUTPUT */ +/* */ +/* status Completion status */ +/* */ +/* CALLS */ +/* */ +/* None */ +/* */ +/* CALLED BY */ +/* */ +/* Application Code */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 12-31-2020 Yuxin Zhou Initial Version 6.1.3 */ +/* */ +/**************************************************************************/ +UINT _nx_utility_string_to_uint(CHAR *input_string, UINT string_length, UINT *number) +{ + +UINT i; + + + /* Check for invalid input pointers. */ + if ((input_string == NX_NULL) || (number == NX_NULL)) + { + return(NX_PTR_ERROR); + } + + /* Check string length. */ + if (string_length == 0) + { + return(NX_SIZE_ERROR); + } + + /* Initialize. */ + i = 0; + *number = 0; + + /* Traverse the string. */ + while (i < string_length) + { + + /* Is a numeric character present? */ + if ((input_string[i] >= '0') && (input_string[i] <= '9')) + { + + /* Check overflow. Max Value: Hex:0xFFFFFFFF, Decimal: 4294967295. */ + if (((*number == 429496729) && (input_string[i] > '5')) || + (*number >= 429496730)) + { + return(NX_OVERFLOW); + } + + /* Yes, numeric character is present. Update the number. */ + *number = (*number * 10) + (UINT) (input_string[i] - '0'); + } + else + { + return(NX_INVALID_PARAMETERS); + } + + i++; + } + + /* Return success. */ + return(NX_SUCCESS); +} + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _nx_utility_base64_encode PORTABLE C */ +/* 6.1.6 */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function encodes the input string into a base64 */ +/* representation. */ +/* */ +/* INPUT */ +/* */ +/* name Name string */ +/* name_size Size of name */ +/* base64name Encoded base64 name string */ +/* base64name_size Size of encoded base64 name */ +/* bytes_copied Number of bytes copied */ +/* */ +/* OUTPUT */ +/* */ +/* status Completion status */ +/* */ +/* CALLS */ +/* */ +/* None */ +/* */ +/* CALLED BY */ +/* */ +/* Application Code */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 04-02-2021 Yuxin Zhou Initial Version 6.1.6 */ +/* */ +/**************************************************************************/ +UINT _nx_utility_base64_encode(UCHAR *name, UINT name_size, UCHAR *base64name, UINT base64name_size, UINT *bytes_copied) +{ +UINT pad; +UINT i, j; +UINT step; + + + /* Check for invalid input pointers. */ + if ((name == NX_NULL) || (base64name == NX_NULL) || (bytes_copied == NX_NULL)) + { + return(NX_PTR_ERROR); + } + + /* Check the size. */ + if ((name_size == 0) || (base64name_size == 0)) + { + return(NX_SIZE_ERROR); + } + + /* Adjust the length to represent the base64 name. */ + name_size = ((name_size * 8) / 6); + + /* Default padding to none. */ + pad = 0; + + /* Determine if an extra conversion is needed. */ + if ((name_size * 6) % 24) + { + + /* Some padding is needed. */ + + /* Calculate the number of pad characters. */ + pad = (name_size * 6) % 24; + pad = (24 - pad) / 6; + pad = pad - 1; + + /* Adjust the length to pickup the character fraction. */ + name_size++; + } + + /* Check the buffer size. */ + if (base64name_size <= (name_size + pad)) + { + return(NX_SIZE_ERROR); + } + + /* Setup index into the base64name. */ + j = 0; + + /* Compute the base64name. */ + step = 0; + i = 0; + while (j < name_size) + { + + /* Determine which step we are in. */ + if (step == 0) + { + + /* Use first 6 bits of name character for index. */ + base64name[j++] = (UCHAR)_nx_utility_base64_array[((UCHAR)name[i]) >> 2]; + step++; + } + else if (step == 1) + { + + /* Use last 2 bits of name character and first 4 bits of next name character for index. */ + base64name[j++] = (UCHAR)_nx_utility_base64_array[((((UCHAR)name[i]) & 0x3) << 4) | (((UCHAR)name[i + 1]) >> 4)]; + i++; + step++; + } + else if (step == 2) + { + + /* Use last 4 bits of name character and first 2 bits of next name character for index. */ + base64name[j++] = (UCHAR)_nx_utility_base64_array[((((UCHAR)name[i]) & 0xF) << 2) | (((UCHAR)name[i + 1]) >> 6)]; + i++; + step++; + } + else /* Step 3 */ + { + + /* Use last 6 bits of name character for index. */ + base64name[j++] = (UCHAR)_nx_utility_base64_array[(((UCHAR)name[i]) & 0x3F)]; + i++; + step = 0; + } + } + + /* Determine if the index needs to be advanced. */ + if (step != 3) + { + i++; + } + + /* Now add the PAD characters. */ + while (pad--) + { + + /* Pad base64name with '=' characters. */ + base64name[j++] = '='; + } + + /* Put a NULL character in. */ + base64name[j] = NX_NULL; + *bytes_copied = j; + + return(NX_SUCCESS); +} + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _nx_utility_base64_decode PORTABLE C */ +/* 6.1.6 */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function decodes the input base64 ASCII string and converts */ +/* it into a standard ASCII representation. */ +/* */ +/* INPUT */ +/* */ +/* base64name Encoded base64 name string */ +/* base64name_size Size of encoded base64 name */ +/* name Name string */ +/* name_size Size of name */ +/* bytes_copied Number of bytes copied */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ +/* None */ +/* */ +/* CALLED BY */ +/* */ +/* Application Code */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 04-02-2021 Yuxin Zhou Initial Version 6.1.6 */ +/* */ +/**************************************************************************/ +UINT _nx_utility_base64_decode(UCHAR *base64name, UINT base64name_size, UCHAR *name, UINT name_size, UINT *bytes_copied) +{ +UINT i, j; +UINT value1, value2; +UINT step; +UINT source_size = base64name_size; + + /* Check for invalid input pointers. */ + if ((base64name == NX_NULL) || (name == NX_NULL) || (bytes_copied == NX_NULL)) + { + return(NX_PTR_ERROR); + } + + /* Check the size. */ + if ((base64name_size == 0) || (name_size == 0)) + { + return(NX_SIZE_ERROR); + } + + /* Adjust the length to represent the ASCII name. */ + base64name_size = ((base64name_size * 6) / 8); + + if (base64name[source_size - 1] == '=') + { + if (base64name[source_size - 2] == '=') + { + base64name_size --; + } + base64name_size--; + } + + /* Check the buffer size. */ + if (name_size <= base64name_size) + { + return(NX_SIZE_ERROR); + } + + /* Setup index into the ASCII name. */ + j = 0; + + /* Compute the ASCII name. */ + step = 0; + i = 0; + while ((j < base64name_size) && (base64name[i]) && (base64name[i] != '=')) + { + + /* Derive values of the Base64 name. */ + if ((base64name[i] >= 'A') && (base64name[i] <= 'Z')) + value1 = (UINT) (base64name[i] - 'A'); + else if ((base64name[i] >= 'a') && (base64name[i] <= 'z')) + value1 = (UINT) (base64name[i] - 'a') + 26; + else if ((base64name[i] >= '0') && (base64name[i] <= '9')) + value1 = (UINT) (base64name[i] - '0') + 52; + else if ((base64name[i] == '+') || + (base64name[i] == '-')) /* Base64 URL. */ + value1 = 62; + else if ((base64name[i] == '/') || + (base64name[i] == '_')) /* Base64 URL. */ + value1 = 63; + else + value1 = 0; + + /* Derive value for the next character. */ + if ((base64name[i + 1] >= 'A') && (base64name[i + 1] <= 'Z')) + value2 = (UINT) (base64name[i+1] - 'A'); + else if ((base64name[i + 1] >= 'a') && (base64name[i + 1] <= 'z')) + value2 = (UINT) (base64name[i+1] - 'a') + 26; + else if ((base64name[i + 1] >= '0') && (base64name[i + 1] <= '9')) + value2 = (UINT) (base64name[i+1] - '0') + 52; + else if ((base64name[i + 1] == '+') || + (base64name[i + 1] == '-')) /* Base64 URL. */ + value2 = 62; + else if ((base64name[i + 1] == '/') || + (base64name[i + 1] == '_')) /* Base64 URL. */ + value2 = 63; + else + value2 = 0; + + /* Determine which step we are in. */ + if (step == 0) + { + + /* Use first value and first 2 bits of second value. */ + name[j++] = (UCHAR) (((value1 & 0x3f) << 2) | ((value2 >> 4) & 3)); + i++; + step++; + } + else if (step == 1) + { + + /* Use last 4 bits of first value and first 4 bits of next value. */ + name[j++] = (UCHAR) (((value1 & 0xF) << 4) | (value2 >> 2)); + i++; + step++; + } + else if (step == 2) + { + + /* Use first 2 bits and following 6 bits of next value. */ + name[j++] = (UCHAR) (((value1 & 3) << 6) | (value2 & 0x3f)); + i++; + i++; + step = 0; + } + } + + /* Put a NULL character in. */ + name[j] = NX_NULL; + *bytes_copied = j; + + return(NX_SUCCESS); +}