From 340f275a8a185df5751abebbb958a46ce339ec4a Mon Sep 17 00:00:00 2001 From: toddouska Date: Tue, 4 Oct 2011 12:29:59 -0700 Subject: [PATCH] add fastmath to bump, add fastmath FP_MAX_BITS runtime check --- configure.ac | 35 ++++++++++++++++++++--------------- ctaocrypt/src/tfm.c | 7 +++++++ ctaocrypt/test/test.c | 5 +++++ cyassl/ctaocrypt/tfm.h | 9 ++++++++- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index 38b2f4bea..38921369a 100644 --- a/configure.ac +++ b/configure.ac @@ -160,7 +160,7 @@ fi if test "$ENABLED_OPENSSLEXTRA" = "yes" && test "$ENABLED_SMALL" = "yes" then - AC_MSG_ERROR([can't enable small and opensslExtra, only one or the other.]) + AC_MSG_ERROR([cannot enable small and opensslExtra, only one or the other.]) fi @@ -177,6 +177,18 @@ then fi +# ssl bump build +AC_ARG_ENABLE(bump, + [ --enable-bump Enable SSL Bump build (default: disabled)], + [ ENABLED_BUMP=$enableval ], + [ ENABLED_BUMP=no ] + ) + +if test "$ENABLED_BUMP" = "yes" +then + AM_CFLAGS="$AM_CFLAGS -DSESSION_CERTS -DLARGE_STATIC_BUFFERS -DCYASSL_CERT_GEN -DCYASSL_KEY_GEN -DOPENSSL_EXTRA -DFP_MAX_BITS=8192" +fi + # fastmath AC_ARG_ENABLE(fastmath, [ --enable-fastmath Enable fast math for BigInts (default: disabled)], @@ -184,6 +196,11 @@ AC_ARG_ENABLE(fastmath, [ ENABLED_FASTMATH=no ] ) +if test "$ENABLED_BUMP" = "yes" +then + ENABLED_FASTMATH="yes" +fi + if test "x$ENABLED_FASTMATH" = "xyes" then AM_CFLAGS="$AM_CFLAGS -DUSE_FAST_MATH" @@ -419,18 +436,6 @@ fi AM_CONDITIONAL([BUILD_NOINLINE], [test "x$ENABLED_NOINLINE" = "xyes"]) -# ssl bump build -AC_ARG_ENABLE(bump, - [ --enable-bump Enable SSL Bump build (default: disabled)], - [ ENABLED_BUMP=$enableval ], - [ ENABLED_BUMP=no ] - ) - -if test "$ENABLED_BUMP" = "yes" -then - AM_CFLAGS="$AM_CFLAGS -DSESSION_CERTS -DLARGE_STATIC_BUFFERS -DCYASSL_CERT_GEN -DCYASSL_KEY_GEN -DOPENSSL_EXTRA" -fi - # ECC AC_ARG_ENABLE(ecc, [ --enable-ecc Enable ECC (default: disabled)], @@ -448,7 +453,7 @@ AM_CONDITIONAL([BUILD_ECC], [test "x$ENABLED_ECC" = "xyes"]) if test "$ENABLED_ECC" = "yes" && test "$ENABLED_SMALL" = "yes" then - AC_MSG_ERROR([can't enable ecc and small, ecc requires TLS which small turns off.]) + AC_MSG_ERROR([cannot enable ecc and small, ecc requires TLS which small turns off.]) fi @@ -473,7 +478,7 @@ AM_CONDITIONAL([BUILD_NTRU], [test "x$ENABLED_NTRU" = "xyes"]) if test "$ENABLED_NTRU" = "yes" && test "$ENABLED_SMALL" = "yes" then - AC_MSG_ERROR([can't enable ntru and small, ntru requires TLS which small turns off.]) + AC_MSG_ERROR([cannot enable ntru and small, ntru requires TLS which small turns off.]) fi diff --git a/ctaocrypt/src/tfm.c b/ctaocrypt/src/tfm.c index 37bb1d462..fb982e6ea 100644 --- a/ctaocrypt/src/tfm.c +++ b/ctaocrypt/src/tfm.c @@ -50,6 +50,13 @@ word32 CheckRunTimeSettings(void) } +/* math settings size check */ +word32 CheckRunTimeFastMath(void) +{ + return FP_SIZE; +} + + /* Functions */ void fp_add(fp_int *a, fp_int *b, fp_int *c) diff --git a/ctaocrypt/test/test.c b/ctaocrypt/test/test.c index 446acb4db..1bb0f021b 100644 --- a/ctaocrypt/test/test.c +++ b/ctaocrypt/test/test.c @@ -136,6 +136,11 @@ void ctaocrypt_test(void* args) if (CheckCtcSettings() != 1) err_sys("Build vs runtime math mismatch\n", -1234); + +#ifdef USE_FAST_MATH + if (CheckFastMathSettings() != 1) + err_sys("Build vs runtime fastmath FP_MAX_BITS mismatch\n", -1235); +#endif if ( (ret = md5_test()) ) err_sys("MD5 test failed!\n", ret); diff --git a/cyassl/ctaocrypt/tfm.h b/cyassl/ctaocrypt/tfm.h index 9322d3145..d684d115f 100644 --- a/cyassl/ctaocrypt/tfm.h +++ b/cyassl/ctaocrypt/tfm.h @@ -226,7 +226,9 @@ * * It defaults to 4096-bits [allowing multiplications upto 2048x2048 bits ] */ -#define FP_MAX_BITS 4096 +#ifndef FP_MAX_BITS + #define FP_MAX_BITS 4096 +#endif #define FP_MAX_SIZE (FP_MAX_BITS+(8*DIGIT_BIT)) /* will this lib work? */ @@ -668,6 +670,11 @@ int mp_sub_d(fp_int *a, fp_digit b, fp_int *c); int mp_prime_is_prime(mp_int* a, int t, int* result); #endif /* CYASSL_KEY_GEN */ +CYASSL_API word32 CheckRunTimeFastMath(void); + +/* If user uses RSA, DH, DSA, or ECC math lib directly then fast math FP_SIZE + must match, return 1 if a match otherwise 0 */ +#define CheckFastMathSettings() (FP_SIZE == CheckRunTimeFastMath()) #ifdef __cplusplus } #endif