add math library runtime settings check

This commit is contained in:
Todd A Ouska
2011-08-29 10:39:40 -07:00
parent d2de4875fe
commit d0193ba8eb
4 changed files with 40 additions and 0 deletions

View File

@@ -38,6 +38,13 @@
#include <cyassl/ctaocrypt/integer.h>
/* math settings check */
word32 CheckRunTimeSettings(void)
{
return CTC_SETTINGS;
}
/* handle up to 6 inits */
int mp_init_multi(mp_int* a, mp_int* b, mp_int* c, mp_int* d, mp_int* e,
mp_int* f)

View File

@@ -43,6 +43,12 @@
#include <ctaocrypt/src/asm.c> /* will define asm MACROS or C ones */
/* math settings check */
word32 CheckRunTimeSettings(void)
{
return CTC_SETTINGS;
}
/* Functions */

View File

@@ -131,6 +131,9 @@ void ctaocrypt_test(void* args)
int ret = 0;
((func_args*)args)->return_code = -1; /* error state */
if (CheckCtcSettings() != 1)
err_sys("Build vs runtime math mismatch\n", -1234);
if ( (ret = md5_test()) )
err_sys("MD5 test failed!\n", ret);

View File

@@ -190,6 +190,30 @@ enum {
};
/* settings detection for compile vs runtime math incombatibilities */
enum {
#if !defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
CTC_SETTINGS = 0x0
#elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG)
CTC_SETTINGS = 0x1
#elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG)
CTC_SETTINGS = 0x2
#elif defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
CTC_SETTINGS = 0x4
#elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG)
CTC_SETTINGS = 0x8
#elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG)
CTC_SETTINGS = 0x10
#endif
};
CYASSL_API word32 CheckRunTimeSettings(void);
#define CheckCtcSettings() (CTC_SETTINGS == CheckRunTimeSettings())
#ifdef __cplusplus
} /* extern "C" */
#endif