From e43524058b43fc5c9c2ae63f31376f1bf27b6986 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 30 Jul 2020 15:33:52 +0700 Subject: For safe primes, use Legendre symbol - DH public key validation when 'Q' available - In particular, greatly speeds up TLS FFDHE groups --- crypto/src/math/raw/Nat.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'crypto/src/math') diff --git a/crypto/src/math/raw/Nat.cs b/crypto/src/math/raw/Nat.cs index 8ec328d11..69942661f 100644 --- a/crypto/src/math/raw/Nat.cs +++ b/crypto/src/math/raw/Nat.cs @@ -278,6 +278,34 @@ namespace Org.BouncyCastle.Math.Raw //} } + public static int Compare(int len, uint[] x, uint[] y) + { + for (int i = len - 1; i >= 0; --i) + { + uint x_i = x[i]; + uint y_i = y[i]; + if (x_i < y_i) + return -1; + if (x_i > y_i) + return 1; + } + return 0; + } + + public static int Compare(int len, uint[] x, int xOff, uint[] y, int yOff) + { + for (int i = len - 1; i >= 0; --i) + { + uint x_i = x[xOff + i]; + uint y_i = y[yOff + i]; + if (x_i < y_i) + return -1; + if (x_i > y_i) + return 1; + } + return 0; + } + public static void Copy(int len, uint[] x, uint[] z) { Array.Copy(x, 0, z, 0, len); -- cgit 1.4.1