Created SILC Crypto Toolkit git repository.
[crypto.git] / lib / silcmath / silcprimegen.c
index 1b56acd8fa62d742b765f5147f9dc7a2e6ab259f..f1363f1e2954efae95ac82342a6f7cdeccad3189 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2007 Pekka Riikonen
+  Copyright (C) 1997 - 2008 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -17,9 +17,8 @@
 
 */
 /* Created: Mon Dec  8 16:35:37 GMT+0200 1997 */
-/* $Id$ */
 
-#include "silc.h"
+#include "silccrypto.h"
 
 /*
    Fixed primetable for small prime division. We use this primetable to
@@ -341,8 +340,13 @@ SilcBool silc_math_prime_test(SilcMPInt *p)
     silc_mp_mod_ui(&tmp, p, primetable[i]);
 
     /* If mod is 0, the number is composite */
-    if (silc_mp_cmp_ui(&tmp, 0) == 0)
-      ret = -1;
+    if (silc_mp_cmp_ui(&tmp, 0) == 0) {
+      SILC_LOG_DEBUG(("Number is not prime"));
+      silc_mp_uninit(&r);
+      silc_mp_uninit(&tmp);
+      silc_mp_uninit(&base);
+      return FALSE;
+    }
   }
 
   /* Does the prime pass the Fermat's prime test.
@@ -356,8 +360,10 @@ SilcBool silc_math_prime_test(SilcMPInt *p)
   silc_mp_uninit(&tmp);
   silc_mp_uninit(&base);
 
-  if (ret)
+  if (ret) {
+    SILC_LOG_DEBUG(("Number is not prime"));
     return FALSE;
+  }
 
   /* Number is probably a prime */
   return TRUE;