diff options
author | Marcus Brinkmann <marcus.brinkmann@ruhr-uni-bochum.de> | 2017-07-06 13:52:24 +0200 |
---|---|---|
committer | Marcus Brinkmann <marcus.brinkmann@ruhr-uni-bochum.de> | 2017-07-10 18:09:42 +0200 |
commit | d24594976686983c7186cbe4e78153888a13b6e4 (patch) | |
tree | 12d3e6bbcf3ec1f1a2436d1ad0aa4fded4a48ce1 /g10/tofu.c | |
parent | speedo: Provide a vagrantfile to test speedo in an isolated VM. (diff) | |
download | gnupg2-d24594976686983c7186cbe4e78153888a13b6e4.tar.xz gnupg2-d24594976686983c7186cbe4e78153888a13b6e4.zip |
tofu: Compare squares instead of square roots.
* g10/Makefile.am (tofu_source) [USE_TOFU]: Remove sqrtu32.h and
sqrtu32.c.
* g10/sqrtu32.h, g10/sqrtu32.c: Removed files.
* g10/tofu.c: Compare squares instead of square roots.
--
The original code is a factor 11.5 slower than using libm's sqrt(),
which in turn is a factor 3.5 slower than using one multiplication
on the other side of the comparison. Also, it's much simpler now.
Signed-off-by: Marcus Brinkmann <mb@g10code.com>
Diffstat (limited to 'g10/tofu.c')
-rw-r--r-- | g10/tofu.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/g10/tofu.c b/g10/tofu.c index ba46244b0..c183fc665 100644 --- a/g10/tofu.c +++ b/g10/tofu.c @@ -42,7 +42,6 @@ #include "../common/mkdir_p.h" #include "gpgsql.h" #include "../common/status.h" -#include "sqrtu32.h" #include "tofu.h" @@ -2922,19 +2921,18 @@ write_stats_status (estream_t fp, { int summary; int validity; - unsigned long days; + unsigned long days_sq; /* Use the euclidean distance (m = sqrt(a^2 + b^2)) rather then the sum of the magnitudes (m = a + b) to ensure a balance between verified signatures and encrypted messages. */ - days = sqrtu32 (signature_days * signature_days - + encryption_days * encryption_days); + days_sq = signature_days * signature_days + encryption_days * encryption_days; - if (days < 1) + if (days_sq < 1) validity = 1; /* Key without history. */ - else if (days < 2 * BASIC_TRUST_THRESHOLD) + else if (days_sq < (2 * BASIC_TRUST_THRESHOLD) * (2 * BASIC_TRUST_THRESHOLD)) validity = 2; /* Key with too little history. */ - else if (days < 2 * FULL_TRUST_THRESHOLD) + else if (days_sq < (2 * FULL_TRUST_THRESHOLD) * (2 * FULL_TRUST_THRESHOLD)) validity = 3; /* Key with enough history for basic trust. */ else validity = 4; /* Key with a lot of history. */ @@ -3232,9 +3230,9 @@ show_statistics (tofu_dbs_t dbs, " one message to this key!\n")); /* Cf. write_stats_status */ - if (sqrtu32 (encryption_count * encryption_count - + signature_count * signature_count) - < 2 * BASIC_TRUST_THRESHOLD) + if ((encryption_count * encryption_count + + signature_count * signature_count) + < ((2 * BASIC_TRUST_THRESHOLD) * (2 * BASIC_TRUST_THRESHOLD))) show_warning = 1; } } |