Mercurial > dropbear
view libtommath/etc/tune.c @ 1499:2d450c1056e3
options: Complete the transition to numeric toggles (`#if')
For the sake of review, this commit alters only the code; the affiliated
comments within the source files also need to be updated, but doing so
now would obscure the operational changes that have been made here.
* All on/off options have been switched to the numeric `#if' variant;
that is the only way to make this `default_options.h.in' thing work
in a reasonable manner.
* There is now some very minor compile-time checking of the user's
choice of options.
* NO_FAST_EXPTMOD doesn't seem to be used, so it has been removed.
* ENABLE_USER_ALGO_LIST was supposed to be renamed DROPBEAR_USER_ALGO_LIST,
and this commit completes that work.
* DROPBEAR_FUZZ seems to be a relatively new, as-yet undocumented option,
which was added by the following commit:
commit 6e0b539e9ca0b5628c6c5a3d118ad6a2e79e8039
Author: Matt Johnston <[email protected]>
Date: Tue May 23 22:29:21 2017 +0800
split out checkpubkey_line() separately
It has now been added to `sysoptions.h' and defined as `0' by default.
* The configuration option `DROPBEAR_PASSWORD_ENV' is no longer listed in
`default_options.h.in'; it is no longer meant to be set by the user, and
is instead left to be defined in `sysoptions.h' (where it was already being
defined) as merely the name of the environment variable in question:
DROPBEAR_PASSWORD
To enable or disable use of that environment variable, the user must now
toggle `DROPBEAR_USE_DROPBEAR_PASSWORD'.
* The sFTP support is now toggled by setting `DROPBEAR_SFTPSERVER', and the
path of the sFTP server program is set independently through the usual
SFTPSERVER_PATH.
author | Michael Witten <mfwitten@gmail.com> |
---|---|
date | Thu, 20 Jul 2017 19:38:26 +0000 |
parents | 8bba51a55704 |
children |
line wrap: on
line source
/* Tune the Karatsuba parameters * * Tom St Denis, [email protected] */ #include <tommath.h> #include <time.h> #include <stdint.h> /* how many times todo each size mult. Depends on your computer. For slow computers * this can be low like 5 or 10. For fast [re: Athlon] should be 25 - 50 or so */ #define TIMES (1UL<<14UL) #ifndef X86_TIMER /* RDTSC from Scott Duplichan */ static uint64_t TIMFUNC (void) { #if defined __GNUC__ #if defined(__i386__) || defined(__x86_64__) /* version from http://www.mcs.anl.gov/~kazutomo/rdtsc.html * the old code always got a warning issued by gcc, clang did not complain... */ unsigned hi, lo; __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); return ((uint64_t)lo)|( ((uint64_t)hi)<<32); #else /* gcc-IA64 version */ unsigned long result; __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); while (__builtin_expect ((int) result == -1, 0)) __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); return result; #endif // Microsoft and Intel Windows compilers #elif defined _M_IX86 __asm rdtsc #elif defined _M_AMD64 return __rdtsc (); #elif defined _M_IA64 #if defined __INTEL_COMPILER #include <ia64intrin.h> #endif return __getReg (3116); #else #error need rdtsc function for this build #endif } /* generic ISO C timer */ uint64_t LBL_T; void t_start(void) { LBL_T = TIMFUNC(); } uint64_t t_read(void) { return TIMFUNC() - LBL_T; } #else extern void t_start(void); extern uint64_t t_read(void); #endif uint64_t time_mult(int size, int s) { unsigned long x; mp_int a, b, c; uint64_t t1; mp_init (&a); mp_init (&b); mp_init (&c); mp_rand (&a, size); mp_rand (&b, size); if (s == 1) { KARATSUBA_MUL_CUTOFF = size; } else { KARATSUBA_MUL_CUTOFF = 100000; } t_start(); for (x = 0; x < TIMES; x++) { mp_mul(&a,&b,&c); } t1 = t_read(); mp_clear (&a); mp_clear (&b); mp_clear (&c); return t1; } uint64_t time_sqr(int size, int s) { unsigned long x; mp_int a, b; uint64_t t1; mp_init (&a); mp_init (&b); mp_rand (&a, size); if (s == 1) { KARATSUBA_SQR_CUTOFF = size; } else { KARATSUBA_SQR_CUTOFF = 100000; } t_start(); for (x = 0; x < TIMES; x++) { mp_sqr(&a,&b); } t1 = t_read(); mp_clear (&a); mp_clear (&b); return t1; } int main (void) { uint64_t t1, t2; int x, y; for (x = 8; ; x += 2) { t1 = time_mult(x, 0); t2 = time_mult(x, 1); printf("%d: %9llu %9llu, %9llu\n", x, t1, t2, t2 - t1); if (t2 < t1) break; } y = x; for (x = 8; ; x += 2) { t1 = time_sqr(x, 0); t2 = time_sqr(x, 1); printf("%d: %9llu %9llu, %9llu\n", x, t1, t2, t2 - t1); if (t2 < t1) break; } printf("KARATSUBA_MUL_CUTOFF = %d\n", y); printf("KARATSUBA_SQR_CUTOFF = %d\n", x); return 0; } /* ref: $Format:%D$ */ /* git commit: $Format:%H$ */ /* commit time: $Format:%ai$ */