Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add introspection for math build and math cleanups #6123

Merged
merged 1 commit into from
Mar 30, 2023

Conversation

dgarske
Copy link
Contributor

@dgarske dgarske commented Feb 22, 2023

Description

  • Add introspection for math build.
  • Raise build error if more than one math library used.
  • Cleanups for building with WOLFCRYPT_ONLY and NO_BIG_INT.
  • Refactor math headers to use wolfmath.h
  • Fix ESP32 to support using any multi-precision math option.
  • Refactor of the opaque math variable type MATH_INT_T used by crypto hardware (QuickAssist, SE050, ESP32 and STM32).
  • Stop forcing use of fast math by default for platforms in settings.h.

Note: For users that still want to use fast math (tfm.c) they will need to add USE_FAST_MATH to their build settings.
Applies To:

WOLFSSL_ESPWROOM32
WOLFSSL_ESPWROOM32SE
MICROCHIP_PIC32
WOLFSSL_PICOTCP_DEMO
WOLFSSL_UTASKER
WOLFSSL_NRF5x
FREERTOS_TCP
WOLFSSL_TIRTOS
EBSNET
FREESCALE_COMMON
FREESCALE_KSDK_BM
WOLFSSL_DEOS
MICRIUM
WOLFSSL_SGX

Example Output:

Math: 	Multi-Precision: Wolf(SP) word-size=64 bits=4096 sp_int.c
	Single Precision: ecc 256 384 521 rsa/dh 2048 3072 4096 asm sp_x86_64.c

Math: 	Multi-Precision: Disabled
	Single Precision: ecc 256 2048 3072 sp_c64.c

Math: 	Multi-Precision: Fast max-bits=4096 not-constant-time tfm.c
	Single Precision: ecc 256 2048 3072 sp_c64.c

Math: 	Multi-Precision: Fast max-bits=4096 not-constant-time tfm.c

Math: 	Multi-Precision: Wolf(SP) word-size=64 bits=4096 sp_int.c
	Single Precision: ecc 256 384 521 rsa/dh 2048 3072 4096 sp_c64.c small

Testing

./configure --enable-usersettings --disable-examples && make
./wolfcrypt/test/testwolfcrypt

/* Place into user_settings.h */
/* Configuration example for ECC SP math only */
#define NO_BIG_INT
#define NO_RSA
#define NO_DSA
#define NO_DH
#define WOLFCRYPT_ONLY
#define HAVE_ECC
#define WOLFSSL_SP_MATH
#define WOLFSSL_HAVE_SP_ECC

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@dgarske dgarske requested review from douzzer and SparkiDev February 22, 2023 20:43
@dgarske dgarske self-assigned this Feb 22, 2023
@dgarske
Copy link
Contributor Author

dgarske commented Feb 23, 2023

Retest this please

@josepho0918
Copy link
Contributor

The macro USE_FAST_MATH are defined for lots of platforms by default in settings.h. They should be removed and let user to specify which math library to use.

@dgarske
Copy link
Contributor Author

dgarske commented Feb 24, 2023

The macro USE_FAST_MATH are defined for lots of platforms by default in settings.h. They should be removed and let user to specify which math library to use.

This is very good feedback! I will adjust.

@dgarske dgarske assigned dgarske and unassigned douzzer Feb 24, 2023
Copy link
Contributor

@douzzer douzzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great -- and dovetails with the testwolfcrypt retval refactor I'm churning through.

#if (defined(WOLFSSL_SP_MATH_ALL) && \
(defined(USE_FAST_MATH) || defined(USE_INTEGER_HEAP_MATH))) || \
(defined(USE_FAST_MATH) && defined(USE_INTEGER_HEAP_MATH))
#error Cannot enable more than one multiple precision math library!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed an opportunity for a really fun preprocessor construction here (this actually works!)

#if defined(WOLFSSL_SP_MATH_ALL) + defined(USE_FAST_MATH) + defined(USE_INTEGER_HEAP_MATH) > 1
#error nope
#endif

not seriously suggesting... not even sure it's portable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yours is much more elegant, but I cannot guarantee portability. I think they would have to =1 and that is just not a guarantee.

@douzzer douzzer self-requested a review February 24, 2023 07:40
IDE/Espressif/ESP-IDF/test/test_wolfssl.c Show resolved Hide resolved
@dgarske dgarske requested review from gojimmypi and douzzer February 24, 2023 17:47
@dgarske dgarske force-pushed the math_info branch 2 times, most recently from 49b4b07 to 65609db Compare February 24, 2023 19:11
@@ -2842,6 +2843,10 @@ int benchmark_init(void)
return EXIT_FAILURE;
}

#ifdef HAVE_WC_INTROSPECTION
printf("Math: %s\n", wc_GetMathInfo());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have something that will be more embedded-friendly than printf ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

printf is fine for embedded targets. it even works (more or less) in newlib-nano. troubles arise with fprintf though, so your point is well taken.

@gojimmypi
Copy link
Contributor

Turning on

#define HAVE_WC_INTROSPECTION

and I see this new information at the beginning of tests:

image

It might be nice to have something other than printf().

@@ -2033,7 +2025,7 @@ extern void uITRON4_free(void *p) ;
#undef HAVE_ECC_KEY_IMPORT
#define HAVE_ECC_KEY_IMPORT
#endif
#ifndef NO_ECC_KEY_EXPORT
#if !defined(NO_ECC_KEY_EXPORT) && !defined(NO_BIG_INT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is curious logic. Perhaps add a comment as to why !defined(NO_BIG_INT) is now required for HAVE_ECC_KEY_EXPORT ?

@@ -2503,7 +2495,7 @@ extern void uITRON4_free(void *p) ;
#endif

/* warning for not using harden build options (default with ./configure) */
#ifndef WC_NO_HARDEN
#if !defined(WC_NO_HARDEN) && !defined(NO_BIG_INT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too is curious. How is !defined(NO_BIG_INT) related to the !defined(WC_NO_HARDEN) here?

@dgarske dgarske assigned dgarske and unassigned douzzer and SparkiDev Mar 3, 2023
dgarske added a commit to dgarske/wolfAsyncCrypt that referenced this pull request Mar 27, 2023
@dgarske dgarske requested a review from SparkiDev March 27, 2023 21:16
@dgarske dgarske assigned SparkiDev and unassigned dgarske Mar 27, 2023
@SparkiDev SparkiDev assigned dgarske and unassigned SparkiDev Mar 27, 2023
@dgarske
Copy link
Contributor Author

dgarske commented Mar 27, 2023

Retest this please

@dgarske
Copy link
Contributor Author

dgarske commented Mar 28, 2023

retest this please

@bandi13
Copy link
Contributor

bandi13 commented Mar 29, 2023

Jenkins retest this please

* Add introspection for math build.
* Raise build error if more than one multi-precision math library used.
* Fix ESP32 to support using any multi-precision math option.
* Refactor math headers to use `wolfmath.h`
* Refactor of the opaque math variable type `MATH_INT_T` used by crypto hardware (QuickAssist, SE050, ESP32 and STM32).
* Cleanups for building with `WOLFCRYPT_ONLY` and `NO_BIG_INT`.
* Stop forcing use of fast math by default for platforms in settings.h. Note: For users that still want to use fast math (tfm.c) they will need to add USE_FAST_MATH to their build settings.

Applies To:
```
WOLFSSL_ESPWROOM32
WOLFSSL_ESPWROOM32SE
MICROCHIP_PIC32
WOLFSSL_PICOTCP_DEMO
WOLFSSL_UTASKER
WOLFSSL_NRF5x
FREERTOS_TCP
WOLFSSL_TIRTOS
EBSNET
FREESCALE_COMMON
FREESCALE_KSDK_BM
WOLFSSL_DEOS
MICRIUM
WOLFSSL_SGX
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants