[Pkg-gnupg-commit] [gnupg2] 107/118: g10: Correctly compute the euclidean distance.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Sep 15 18:25:18 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch encoding-and-speling
in repository gnupg2.

commit 05b2b13efd8ecea86d31af863cbf82c8b38dc94f
Author: Neal H. Walfield <neal at g10code.com>
Date:   Wed Sep 14 15:20:33 2016 +0200

    g10: Correctly compute the euclidean distance.
    
    * g10/tofu.c (write_stats_status): Correctly compute the euclidean
    distance.
    (show_statistics): Likewise.
    
    --
    Signed-off-by: Neal H. Walfield <neal at g10code.com>
---
 g10/tofu.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/g10/tofu.c b/g10/tofu.c
index ed0d92c..5cc1c22 100644
--- a/g10/tofu.c
+++ b/g10/tofu.c
@@ -2514,16 +2514,17 @@ write_stats_status (estream_t fp,
   const char *validity;
   unsigned long messages;
 
-  /* Use the euclidean distance rather then the sum of the magnitudes
-     to ensure a balance between verified signatures and encrypted
-     messages.  */
-  messages = sqrtu32 (signature_count) + sqrtu32 (encryption_count);
+  /* 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.  */
+  messages = sqrtu32 (signature_count * signature_count
+                      + encryption_count * encryption_count);
 
   if (messages < 1)
     validity = "1"; /* Key without history.  */
-  else if (messages < sqrtu32 (2 * BASIC_TRUST_THRESHOLD))
+  else if (messages < 2 * BASIC_TRUST_THRESHOLD)
     validity = "2"; /* Key with too little history.  */
-  else if (messages < sqrtu32 (2 * FULL_TRUST_THRESHOLD))
+  else if (messages < 2 * FULL_TRUST_THRESHOLD)
     validity = "3"; /* Key with enough history for basic trust.  */
   else
     validity = "4"; /* Key with a lot of history.  */
@@ -2758,8 +2759,9 @@ show_statistics (tofu_dbs_t dbs, const char *fingerprint,
                         "  one message to this key and user id!\n"));
 
           /* Cf. write_stats_status  */
-          if (sqrtu32 (encryption_count) + sqrtu32 (signature_count)
-              < sqrtu32 (2 * BASIC_TRUST_THRESHOLD))
+          if (sqrtu32 (encryption_count * encryption_count
+                       + signature_count * signature_count)
+              < 2 * BASIC_TRUST_THRESHOLD)
             show_warning = 1;
         }
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list