updates.
authorPekka Riikonen <priikone@silcnet.org>
Tue, 12 Jun 2001 15:20:28 +0000 (15:20 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 12 Jun 2001 15:20:28 +0000 (15:20 +0000)
25 files changed:
Makefile.defines.pre
acconfig.h.pre
apps/silcd/silc.conf [deleted file]
configure.in.pre
lib/silccrypt/pkcs1.c
lib/silccrypt/rsa.c
lib/silccrypt/rsa_internal.h
lib/silccrypt/silcdh.h
lib/silccrypt/silcpkcs.h
lib/silcmath/Makefile.am
lib/silcmath/modinv.c
lib/silcmath/mp_gmp.c [new file with mode: 0644]
lib/silcmath/mp_gmp.h [new file with mode: 0644]
lib/silcmath/mp_mpi.c [new file with mode: 0644]
lib/silcmath/mp_mpi.h [new file with mode: 0644]
lib/silcmath/mpbin.c
lib/silcmath/silcmath.h
lib/silcmath/silcmp.h
lib/silcmath/silcprimegen.c
lib/silcske/groups.c
lib/silcske/groups_internal.h
lib/silcske/payload.c
lib/silcske/payload_internal.h
lib/silcske/silcske.c
lib/silcske/silcske.h

index 61644d1a3d0b1586484ed15c2ddf51fd41959fad..b795ed6600dceca5505d49af5fc2b534d665ba57 100644 (file)
@@ -47,7 +47,7 @@ INCLUDES = $(ADD_INCLUDES) \
        -I$(silc_top_srcdir)/lib/silccore \
        -I$(silc_top_srcdir)/lib/silccrypt \
         -I$(silc_top_srcdir)/lib/silcmath \
-        -I$(silc_top_srcdir)/lib/silcmath/gmp \
+        -I$(silc_top_srcdir)/lib/silcmath/mpi \
        -I$(silc_top_srcdir)/lib/silcske \
        -I$(silc_top_srcdir)/lib/silcsim \
        -I$(silc_top_srcdir)/lib/silcutil \
index 772c6d2ab97962b56e2e60daa57138573b5e52d1..340d8308d1289466c3dc9b13de87eb261d4e8b6a 100644 (file)
 #undef SILC_SIZEOF_CHAR
 #undef SILC_SIZEOF_VOID_P
 
+/* MP library */
+#undef SILC_MP_GMP
+#undef SILC_MP_NSS_MPI
+
+/* Redefs for SOCKS5 library */
 /* macros/curses checks */
 #undef HAS_CURSES
 #undef USE_SUNOS_CURSES
@@ -39,7 +44,6 @@
 #undef NO_COLOR_CURSES
 #undef SCO_FLAVOR
 
-/* Redefs for SOCKS5 library */
 #undef SOCKS
 #undef SOCKS5
 #undef Rconnect
diff --git a/apps/silcd/silc.conf b/apps/silcd/silc.conf
deleted file mode 100644 (file)
index f9d798c..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-[Cipher]
-aes-256-cbc:../lib/silcsim/modules/aes.sim.so:32:16
-aes-192-cbc:../lib/silcsim/modules/aes.sim.so:24:16
-aes-128-cbc:../lib/silcsim/modules/aes.sim.so:16:16
-twofish-256-cbc:../lib/silcsim/modules/twofish.sim.so:32:16
-twofish-192-cbc:../lib/silcsim/modules/twofish.sim.so:24:16
-twofish-128-cbc:../lib/silcsim/modules/twofish.sim.so:16:16
-mars-256-cbc:../lib/silcsim/modules/mars.sim.so:32:16
-mars-192-cbc:../lib/silcsim/modules/mars.sim.so:24:16
-mars-128-cbc:../lib/silcsim/modules/mars.sim.so:16:16
-none:../lib/silcsim/modules/none.sim.so:0:0
-
-[Hash]
-md5::64:16
-sha1::64:20
-
-[hmac]
-hmac-sha1-96:sha1:12
-hmac-md5-96:md5:12
-hmac-sha1:sha1:20
-hmac-md5:md5:16
-
-[PKCS]
-rsa
-
-[AdminInfo]
-SILC Project:SILCNet Router:Pekka Riikonen:priikone@silcnet.org
-
-[ServerInfo]
-silc.silcnet.org:195.168.3.187:Slovakia:706
-
-[ServerKeys]
-./pubkey.pub:./privkey.prv
-
-[ListenPort]
-195.168.3.187:194.168.3.187:706
-
-[Logging]
-infologfile:silcd.log:10000
-warninglogfile:silcd.log:
-errorlogfile:silcd.log:10000
-
-[ConnectionClass]
-1:100:100:100
-2:200:300:400
-
-[ClientConnection]
-:::706:1
-:::707:1
-
-[AdminConnection]
-195.168.3.187:priikone:pekka:passwd:mypasswd99
-
-[ServerConnection]
-195.168.3.187:passwd:sureissecret1101:706:1:1
-195.10.137.227:passwd:sureissecret1010:706:1:1
-
-[RouterConnection]
-
-[DenyConnection]
-
-[motd]
-./motd
index 3f403223d41453ed0f70b03c865cf964e95c08f9..3e48b35599df1e9428f0b92067a5c51f8e6bf417 100644 (file)
@@ -538,44 +538,25 @@ if test "x$socks" = "x5"; then
   AC_DEFINE(Rgethostbyname, SOCKSgethostbyname)
 fi
 
-# GMP Library checking
-AC_MSG_CHECKING(whether to compile GMP)
-AC_ARG_WITH(gmp,
-[  --with-gmp              Build the GMP in the SILC source tree],
-[ case "${withval}" in
-  yes) 
-    AM_CONDITIONAL(SILC_BUILD_GMP, test x$withval = xyes)
-    AC_MSG_RESULT(yes)
-    ;;
-  *)
-    AC_CHECK_HEADER(gmp.h,
-      AC_CHECK_LIB(gmp, __gmpz_init,
-        AM_CONDITIONAL(SILC_BUILD_GMP, test x$withval = yes)
-        LIBS="$LIBS -L/usr/lib -L/usr/local/lib -lgmp"
-        AC_MSG_RESULT(GMP will not be compiled),
-        AM_CONDITIONAL(SILC_BUILD_GMP, test x$withval != yes)
-        AC_MSG_RESULT(GMP will be compiled)
-      ),
-      AM_CONDITIONAL(SILC_BUILD_GMP, test x$withval != yes)
-      AC_MSG_RESULT(GMP will be compiled)
-    )
-    ;;
-esac ], [
-  AC_CHECK_HEADER(gmp.h,
-    AC_CHECK_LIB(gmp, __gmpz_init,
-      build_gmp=false
-      AM_CONDITIONAL(SILC_BUILD_GMP, test x$build_gmp = xtrue)
-      LIBS="$LIBS -L/usr/lib -L/usr/local/lib -lgmp"
-      AC_MSG_RESULT(GMP will not be compiled),
-      build_gmp=true
-      AM_CONDITIONAL(SILC_BUILD_GMP, test x$build_gmp = xtrue)
-      AC_MSG_RESULT(GMP will be compiled)
-    ),
-    build_gmp=true
-    AM_CONDITIONAL(SILC_BUILD_GMP, test x$build_gmp = xtrue)
-    AC_MSG_RESULT(GMP will be compiled)
+#
+# MP library checking. First check whether system has GMP. If it has that
+# then use it. If not then compile the MPI library in the source tree.
+#
+mp_gmp=false
+AC_CHECK_HEADER(gmp.h,
+  AC_CHECK_LIB(gmp, __gmpz_init,
+    mp_gmp=true
+    AC_DEFINE(SILC_MP_GMP)
+    LIBS="$LIBS -L/usr/lib -L/usr/local/lib -lgmp"
+    AC_MSG_RESULT(Using GMP as MP library)
   )
-])
+)
+AM_CONDITIONAL(SILC_MP_GMP, test x$mp_gmp = xtrue)
+if test x$mp_gmp = xfalse; then
+  AM_CONDITIONAL(SILC_MP_NSS_MPI, test x$mp_gmp = xfalse)
+  AC_DEFINE(SILC_MP_NSS_MPI)
+  AC_MSG_RESULT(Using NSS MPI as MP library)
+fi
 
 AC_ARG_WITH(silcd-config-file,
 [  --with-silcd-config-file[=PATH]
@@ -588,7 +569,6 @@ AC_ARG_WITH(silcd-config-file,
 #
 AC_CONFIG_SUBDIRS(irssi)
 AC_CONFIG_SUBDIRS(lib/dotconf)
-AC_CONFIG_SUBDIRS(lib/silcmath/gmp)
 AC_CONFIG_SUBDIRS(lib/trq)
 #AC_CONFIG_SUBDIRS(lib/zlib)
 
index a6a68146c08dd3c8e8a73cc2d7daffb1fece9b01..47950d3b24557e0c89c93b7469b452b721614f1c 100644 (file)
@@ -313,8 +313,8 @@ RSA_DecodeOneBlock(unsigned char *data,
 SILC_PKCS_API_ENCRYPT(pkcs1)
 {
   RsaKey *key = (RsaKey *)context;
-  SilcInt mp_tmp;
-  SilcInt mp_dst;
+  SilcMPInt mp_tmp;
+  SilcMPInt mp_dst;
   unsigned char *padded;
   uint32 padded_len, len = key->bits / 8;
 
@@ -323,8 +323,10 @@ SILC_PKCS_API_ENCRYPT(pkcs1)
                       RSA_BlockPublic, src, src_len))
     return FALSE;
 
-  silc_mp_init_set_ui(&mp_tmp, 0);
-  silc_mp_init_set_ui(&mp_dst, 0);
+  silc_mp_init(&mp_tmp);
+  silc_mp_init(&mp_dst);
+  silc_mp_set_ui(&mp_tmp, 0);
+  silc_mp_set_ui(&mp_dst, 0);
 
   /* Data to MP */
   silc_mp_bin2mp(padded, padded_len, &mp_tmp);
@@ -338,8 +340,8 @@ SILC_PKCS_API_ENCRYPT(pkcs1)
 
   memset(padded, 0, padded_len);
   silc_free(padded);
-  silc_mp_clear(&mp_tmp);
-  silc_mp_clear(&mp_dst);
+  silc_mp_uninit(&mp_tmp);
+  silc_mp_uninit(&mp_dst);
 
   return TRUE;
 }
@@ -347,13 +349,15 @@ SILC_PKCS_API_ENCRYPT(pkcs1)
 SILC_PKCS_API_DECRYPT(pkcs1)
 {
   RsaKey *key = (RsaKey *)context;
-  SilcInt mp_tmp;
-  SilcInt mp_dst;
+  SilcMPInt mp_tmp;
+  SilcMPInt mp_dst;
   unsigned char *padded, *unpadded;
   uint32 padded_len;
 
-  silc_mp_init_set_ui(&mp_tmp, 0);
-  silc_mp_init_set_ui(&mp_dst, 0);
+  silc_mp_init(&mp_tmp);
+  silc_mp_init(&mp_dst);
+  silc_mp_set_ui(&mp_tmp, 0);
+  silc_mp_set_ui(&mp_dst, 0);
 
   /* Data to MP */
   silc_mp_bin2mp(src, src_len, &mp_tmp);
@@ -370,8 +374,8 @@ SILC_PKCS_API_DECRYPT(pkcs1)
   if (!unpadded) {
     memset(padded, 0, padded_len);
     silc_free(padded);
-    silc_mp_clear(&mp_tmp);
-    silc_mp_clear(&mp_dst);
+    silc_mp_uninit(&mp_tmp);
+    silc_mp_uninit(&mp_dst);
     return FALSE;
   }
 
@@ -383,8 +387,8 @@ SILC_PKCS_API_DECRYPT(pkcs1)
   memset(unpadded, 0, padded_len);
   silc_free(padded);
   silc_free(unpadded);
-  silc_mp_clear(&mp_tmp);
-  silc_mp_clear(&mp_dst);
+  silc_mp_uninit(&mp_tmp);
+  silc_mp_uninit(&mp_dst);
 
   return TRUE;
 }
@@ -392,8 +396,8 @@ SILC_PKCS_API_DECRYPT(pkcs1)
 SILC_PKCS_API_SIGN(pkcs1)
 {
   RsaKey *key = (RsaKey *)context;
-  SilcInt mp_tmp;
-  SilcInt mp_dst;
+  SilcMPInt mp_tmp;
+  SilcMPInt mp_dst;
   unsigned char *padded;
   uint32 padded_len;
   uint32 len = key->bits / 8;
@@ -403,8 +407,10 @@ SILC_PKCS_API_SIGN(pkcs1)
                       src, src_len))
     return FALSE;
 
-  silc_mp_init_set_ui(&mp_tmp, 0);
-  silc_mp_init_set_ui(&mp_dst, 0);
+  silc_mp_init(&mp_tmp);
+  silc_mp_init(&mp_dst);
+  silc_mp_set_ui(&mp_tmp, 0);
+  silc_mp_set_ui(&mp_dst, 0);
 
   /* Data to MP */
   silc_mp_bin2mp(padded, len, &mp_tmp);
@@ -418,8 +424,8 @@ SILC_PKCS_API_SIGN(pkcs1)
 
   memset(padded, 0, padded_len);
   silc_free(padded);
-  silc_mp_clear(&mp_tmp);
-  silc_mp_clear(&mp_dst);
+  silc_mp_uninit(&mp_tmp);
+  silc_mp_uninit(&mp_dst);
 
   return TRUE;
 }
@@ -428,13 +434,15 @@ SILC_PKCS_API_VERIFY(pkcs1)
 {
   RsaKey *key = (RsaKey *)context;
   int ret = TRUE;
-  SilcInt mp_tmp2;
-  SilcInt mp_dst;
+  SilcMPInt mp_tmp2;
+  SilcMPInt mp_dst;
   unsigned char *verify, *unpadded;
   uint32 verify_len, len = key->bits / 8;
 
-  silc_mp_init_set_ui(&mp_tmp2, 0);
-  silc_mp_init_set_ui(&mp_dst, 0);
+  silc_mp_init(&mp_tmp2);
+  silc_mp_init(&mp_dst);
+  silc_mp_set_ui(&mp_tmp2, 0);
+  silc_mp_set_ui(&mp_dst, 0);
 
   /* Format the signature into MP int */
   silc_mp_bin2mp(signature, signature_len, &mp_tmp2);
@@ -451,8 +459,8 @@ SILC_PKCS_API_VERIFY(pkcs1)
   if (!unpadded) {
     memset(verify, 0, verify_len);
     silc_free(verify);
-    silc_mp_clear(&mp_tmp2);
-    silc_mp_clear(&mp_dst);
+    silc_mp_uninit(&mp_tmp2);
+    silc_mp_uninit(&mp_dst);
     return FALSE;
   }
 
@@ -464,8 +472,8 @@ SILC_PKCS_API_VERIFY(pkcs1)
   memset(unpadded, 0, verify_len);
   silc_free(verify);
   silc_free(unpadded);
-  silc_mp_clear(&mp_tmp2);
-  silc_mp_clear(&mp_dst);
+  silc_mp_uninit(&mp_tmp2);
+  silc_mp_uninit(&mp_dst);
 
   return ret;
 }
index a4479334ddf35701a36af6a51fe8a5302bdeaae4..2efd68bee9f88c7a9f9b1ef834f488fbf09004af 100644 (file)
@@ -74,7 +74,7 @@
 SILC_PKCS_API_INIT(rsa)
 {
   uint32 prime_bits = keylen / 2;
-  SilcInt p, q;
+  SilcMPInt p, q;
 
   printf("Generating RSA Public and Private keys, might take a while...\n");
 
@@ -96,21 +96,21 @@ SILC_PKCS_API_INIT(rsa)
 
   /* If p is smaller than q, switch them */
   if ((silc_mp_cmp(&p, &q)) > 0) {
-    SilcInt hlp;
+    SilcMPInt hlp;
     silc_mp_init(&hlp);
 
     silc_mp_set(&hlp, &p);
     silc_mp_set(&p, &q);
     silc_mp_set(&q, &hlp);
 
-    silc_mp_clear(&hlp);
+    silc_mp_uninit(&hlp);
   }
 
   /* Generate the actual keys */
   rsa_generate_keys((RsaKey *)context, keylen, &p, &q);
 
-  silc_mp_clear(&p);
-  silc_mp_clear(&q);
+  silc_mp_uninit(&p);
+  silc_mp_uninit(&q);
   
   printf("\nKeys generated succesfully.\n");
 
@@ -222,8 +222,8 @@ SILC_PKCS_API_SET_PUBLIC_KEY(rsa)
   memcpy(tmp, key_data, 4);
   SILC_GET32_MSB(e_len, tmp);
   if (e_len > key_len) {
-    silc_mp_clear(&key->e);
-    silc_mp_clear(&key->n);
+    silc_mp_uninit(&key->e);
+    silc_mp_uninit(&key->n);
     return 0;
   }
 
@@ -232,8 +232,8 @@ SILC_PKCS_API_SET_PUBLIC_KEY(rsa)
   memcpy(tmp, key_data + 4 + e_len, 4);
   SILC_GET32_MSB(n_len, tmp);
   if (e_len + n_len > key_len) {
-    silc_mp_clear(&key->e);
-    silc_mp_clear(&key->n);
+    silc_mp_uninit(&key->e);
+    silc_mp_uninit(&key->n);
     return 0;
   }
 
@@ -261,8 +261,8 @@ SILC_PKCS_API_SET_PRIVATE_KEY(rsa)
   memcpy(tmp, key_data, 4);
   SILC_GET32_MSB(e_len, tmp);
   if (e_len > key_len) {
-    silc_mp_clear(&key->e);
-    silc_mp_clear(&key->n);
+    silc_mp_uninit(&key->e);
+    silc_mp_uninit(&key->n);
     return FALSE;
   }
 
@@ -271,8 +271,8 @@ SILC_PKCS_API_SET_PRIVATE_KEY(rsa)
   memcpy(tmp, key_data + 4 + e_len, 4);
   SILC_GET32_MSB(n_len, tmp);
   if (e_len + n_len > key_len) {
-    silc_mp_clear(&key->e);
-    silc_mp_clear(&key->n);
+    silc_mp_uninit(&key->e);
+    silc_mp_uninit(&key->n);
     return FALSE;
   }
 
@@ -281,8 +281,8 @@ SILC_PKCS_API_SET_PRIVATE_KEY(rsa)
   memcpy(tmp, key_data + 4 + e_len + 4 + n_len, 4);
   SILC_GET32_MSB(d_len, tmp);
   if (e_len + n_len + d_len > key_len) {
-    silc_mp_clear(&key->e);
-    silc_mp_clear(&key->n);
+    silc_mp_uninit(&key->e);
+    silc_mp_uninit(&key->n);
     return FALSE;
   }
 
@@ -302,11 +302,13 @@ SILC_PKCS_API_ENCRYPT(rsa)
 {
   RsaKey *key = (RsaKey *)context;
   int i, tmplen;
-  SilcInt mp_tmp;
-  SilcInt mp_dst;
+  SilcMPInt mp_tmp;
+  SilcMPInt mp_dst;
 
-  silc_mp_init_set_ui(&mp_tmp, 0);
-  silc_mp_init_set_ui(&mp_dst, 0);
+  silc_mp_init(&mp_tmp);
+  silc_mp_init(&mp_dst);
+  silc_mp_set_ui(&mp_tmp, 0);
+  silc_mp_set_ui(&mp_dst, 0);
 
   /* Format the data into MP int */
   for (i = 0; i < src_len; i++) {
@@ -322,12 +324,12 @@ SILC_PKCS_API_ENCRYPT(rsa)
   /* Format the MP int back into data */
   for (i = tmplen; i > 0; i--) {
     dst[i - 1] = (unsigned char)(silc_mp_get_ui(&mp_dst) & 0xff);
-    silc_mp_fdiv_q_2exp(&mp_dst, &mp_dst, 8);
+    silc_mp_div_2exp(&mp_dst, &mp_dst, 8);
   }
   *dst_len = tmplen;
 
-  silc_mp_clear(&mp_tmp);
-  silc_mp_clear(&mp_dst);
+  silc_mp_uninit(&mp_tmp);
+  silc_mp_uninit(&mp_dst);
 
   return TRUE;
 }
@@ -336,11 +338,13 @@ SILC_PKCS_API_DECRYPT(rsa)
 {
   RsaKey *key = (RsaKey *)context;
   int i, tmplen;
-  SilcInt mp_tmp;
-  SilcInt mp_dst;
+  SilcMPInt mp_tmp;
+  SilcMPInt mp_dst;
 
-  silc_mp_init_set_ui(&mp_tmp, 0);
-  silc_mp_init_set_ui(&mp_dst, 0);
+  silc_mp_init(&mp_tmp);
+  silc_mp_init(&mp_dst);
+  silc_mp_set_ui(&mp_tmp, 0);
+  silc_mp_set_ui(&mp_dst, 0);
 
   /* Format the data into MP int */
   for (i = 0; i < src_len; i++) {
@@ -356,12 +360,12 @@ SILC_PKCS_API_DECRYPT(rsa)
   /* Format the MP int back into data */
   for (i = tmplen; i > 0; i--) {
     dst[i - 1] = (unsigned char)(silc_mp_get_ui(&mp_dst) & 0xff);
-    silc_mp_fdiv_q_2exp(&mp_dst, &mp_dst, 8);
+    silc_mp_div_2exp(&mp_dst, &mp_dst, 8);
   }
   *dst_len = tmplen;
 
-  silc_mp_clear(&mp_tmp);
-  silc_mp_clear(&mp_dst);
+  silc_mp_uninit(&mp_tmp);
+  silc_mp_uninit(&mp_dst);
 
   return TRUE;
 }
@@ -370,11 +374,13 @@ SILC_PKCS_API_SIGN(rsa)
 {
   RsaKey *key = (RsaKey *)context;
   int i, tmplen;
-  SilcInt mp_tmp;
-  SilcInt mp_dst;
+  SilcMPInt mp_tmp;
+  SilcMPInt mp_dst;
 
-  silc_mp_init_set_ui(&mp_tmp, 0);
-  silc_mp_init_set_ui(&mp_dst, 0);
+  silc_mp_init(&mp_tmp);
+  silc_mp_init(&mp_dst);
+  silc_mp_set_ui(&mp_tmp, 0);
+  silc_mp_set_ui(&mp_dst, 0);
 
   /* Format the data into MP int */
   for (i = 0; i < src_len; i++) {
@@ -390,12 +396,12 @@ SILC_PKCS_API_SIGN(rsa)
   /* Format the MP int back into data */
   for (i = tmplen; i > 0; i--) {
     dst[i - 1] = (unsigned char)(silc_mp_get_ui(&mp_dst) & 0xff);
-    silc_mp_fdiv_q_2exp(&mp_dst, &mp_dst, 8);
+    silc_mp_div_2exp(&mp_dst, &mp_dst, 8);
   }
   *dst_len = tmplen;
 
-  silc_mp_clear(&mp_tmp);
-  silc_mp_clear(&mp_dst);
+  silc_mp_uninit(&mp_tmp);
+  silc_mp_uninit(&mp_dst);
 
   return TRUE;
 }
@@ -404,12 +410,15 @@ SILC_PKCS_API_VERIFY(rsa)
 {
   RsaKey *key = (RsaKey *)context;
   int i, ret;
-  SilcInt mp_tmp, mp_tmp2;
-  SilcInt mp_dst;
+  SilcMPInt mp_tmp, mp_tmp2;
+  SilcMPInt mp_dst;
 
-  silc_mp_init_set_ui(&mp_tmp, 0);
-  silc_mp_init_set_ui(&mp_tmp2, 0);
-  silc_mp_init_set_ui(&mp_dst, 0);
+  silc_mp_init(&mp_tmp);
+  silc_mp_init(&mp_tmp2);
+  silc_mp_init(&mp_dst);
+  silc_mp_set_ui(&mp_tmp, 0);
+  silc_mp_set_ui(&mp_tmp2, 0);
+  silc_mp_set_ui(&mp_dst, 0);
 
   /* Format the signature into MP int */
   for (i = 0; i < signature_len; i++) {
@@ -432,9 +441,9 @@ SILC_PKCS_API_VERIFY(rsa)
   if ((silc_mp_cmp(&mp_tmp, &mp_dst)) != 0)
     ret = FALSE;
 
-  silc_mp_clear(&mp_tmp);
-  silc_mp_clear(&mp_tmp2);
-  silc_mp_clear(&mp_dst);
+  silc_mp_uninit(&mp_tmp);
+  silc_mp_uninit(&mp_tmp2);
+  silc_mp_uninit(&mp_dst);
 
   return ret;
 }
@@ -444,11 +453,11 @@ SILC_PKCS_API_VERIFY(rsa)
    are then sent as argument for the function. */
 
 void rsa_generate_keys(RsaKey *key, uint32 bits, 
-                      SilcInt *p, SilcInt *q)
+                      SilcMPInt *p, SilcMPInt *q)
 {
-  SilcInt phi, hlp;
-  SilcInt div, lcm;
-  SilcInt pm1, qm1;
+  SilcMPInt phi, hlp;
+  SilcMPInt div, lcm;
+  SilcMPInt pm1, qm1;
   
   /* Initialize variables */
   silc_mp_init(&key->p);
@@ -493,15 +502,15 @@ void rsa_generate_keys(RsaKey *key, uint32 bits,
   
   /* Find d, the private exponent. */
   silc_mp_gcd(&div, &pm1, &qm1);
-  silc_mp_fdiv_q(&lcm, &phi, &div);
+  silc_mp_div(&lcm, &phi, &div);
   silc_mp_modinv(&key->d, &key->e, &lcm);
   
-  silc_mp_clear(&phi);
-  silc_mp_clear(&hlp);
-  silc_mp_clear(&div);
-  silc_mp_clear(&lcm);
-  silc_mp_clear(&pm1);
-  silc_mp_clear(&qm1);
+  silc_mp_uninit(&phi);
+  silc_mp_uninit(&hlp);
+  silc_mp_uninit(&div);
+  silc_mp_uninit(&lcm);
+  silc_mp_uninit(&pm1);
+  silc_mp_uninit(&qm1);
 }
 
 /* Clears whole key structure. */
@@ -509,11 +518,11 @@ void rsa_generate_keys(RsaKey *key, uint32 bits,
 void rsa_clear_keys(RsaKey *key)
 {
   key->bits = 0;
-  silc_mp_clear(&key->p);
-  silc_mp_clear(&key->q);
-  silc_mp_clear(&key->n);
-  silc_mp_clear(&key->e);
-  silc_mp_clear(&key->d);
+  silc_mp_uninit(&key->p);
+  silc_mp_uninit(&key->q);
+  silc_mp_uninit(&key->n);
+  silc_mp_uninit(&key->e);
+  silc_mp_uninit(&key->d);
 }
 
 /* RSA encrypt/decrypt function. cm = ciphertext or plaintext,
@@ -524,8 +533,8 @@ void rsa_clear_keys(RsaKey *key)
    Decrypt: m = c ^ d mod n 
 */
 
-void rsa_en_de_crypt(SilcInt *cm, SilcInt *mc, 
-                    SilcInt *expo, SilcInt *modu)
+void rsa_en_de_crypt(SilcMPInt *cm, SilcMPInt *mc, 
+                    SilcMPInt *expo, SilcMPInt *modu)
 {
-  silc_mp_powm(cm, mc, expo, modu);
+  silc_mp_pow_mod(cm, mc, expo, modu);
 }
index 1f218a853fec72622116d98ae86b219d4f522982..33ffd88a6cf19bee3dfb5cf1324423d38acfde10 100644 (file)
 /* RSA Keys, includes both Private and Public key */
 typedef struct {
   int bits;                    /* bits in key */
-  SilcInt p;                   /* prime p */
-  SilcInt q;                   /* prime q */
-  SilcInt n;                   /* modulus */
-  SilcInt e;                   /* public exponent */
-  SilcInt d;                   /* private exponent */
+  SilcMPInt p;                 /* prime p */
+  SilcMPInt q;                 /* prime q */
+  SilcMPInt n;                 /* modulus */
+  SilcMPInt e;                 /* public exponent */
+  SilcMPInt d;                 /* private exponent */
 } RsaKey;
 
 void rsa_generate_keys(RsaKey *key, uint32 bits, 
-                      SilcInt *p, SilcInt *q);
+                      SilcMPInt *p, SilcMPInt *q);
 void rsa_clear_keys(RsaKey *key);
-void rsa_en_de_crypt(SilcInt *cm, SilcInt *mc, 
-                    SilcInt *expo, SilcInt *modu);
+void rsa_en_de_crypt(SilcMPInt *cm, SilcMPInt *mc, 
+                    SilcMPInt *expo, SilcMPInt *modu);
 
 #endif
index 02f1129e3020482e8075216a5532f7e5201cccbf..68d36764c48c7d332f11efbb82d062a774738dd3 100644 (file)
@@ -50,13 +50,13 @@ typedef struct SilcDHStruct *SilcDH;
 /* Diffie Hellman context. This includes the DH parameters including the
    negotiated key material. */
 struct SilcDHStruct {
-  SilcInt *g;             /* Global base (generator) */
-  SilcInt *p;            /* Global prime (modulus, prime) */
-  SilcInt *lpf;                  /* Largest prime factor (prime) */
-  SilcInt *my_x;                 /* x, My private value (random) */
-  SilcInt *my_y;                 /* y, My public value (y = g ^ x mod p) */
-  SilcInt *your_y;       /* y', Your public value (y' = g ^ x' mod p) */
-  SilcInt *z;            /* The computed secret key (z = y' ^ x mod p) */
+  SilcMPInt *g;             /* Global base (generator) */
+  SilcMPInt *p;                  /* Global prime (modulus, prime) */
+  SilcMPInt *lpf;                /* Largest prime factor (prime) */
+  SilcMPInt *my_x;               /* x, My private value (random) */
+  SilcMPInt *my_y;               /* y, My public value (y = g ^ x mod p) */
+  SilcMPInt *your_y;     /* y', Your public value (y' = g ^ x' mod p) */
+  SilcMPInt *z;                  /* The computed secret key (z = y' ^ x mod p) */
 
   SilcRng rng;           /* RNG */
 };
@@ -65,7 +65,7 @@ struct SilcDHStruct {
  *
  * SYNOPSIS
  *    
- *    SilcDH silc_dh_alloc(SilcRng rng, SilcInt *g, SilcInt *p, SilcInt *lpf);
+ *    SilcDH silc_dh_alloc(SilcRng rng, SilcMPInt *g, SilcMPInt *p, SilcMPInt *lpf);
  * 
  * DESCRIPTION
  *
@@ -78,7 +78,7 @@ struct SilcDHStruct {
  *    on error or allocated SilcDH context on success. 
  *
  ***/
-SilcDH silc_dh_alloc(SilcRng rng, SilcInt *g, SilcInt *p, SilcInt *lpf);
+SilcDH silc_dh_alloc(SilcRng rng, SilcMPInt *g, SilcMPInt *p, SilcMPInt *lpf);
 
 /****f* silccrypt/SilcDH/silc_dh_free
  *
@@ -98,7 +98,7 @@ void silc_dh_free(SilcDH dh);
  *
  * SYNOPSIS
  *
- *    int silc_dh_generate_private(SilcDH dh, SilcInt **x);
+ *    int silc_dh_generate_private(SilcDH dh, SilcMPInt **x);
  *
  * DESCRIPTION
  *
@@ -108,13 +108,13 @@ void silc_dh_free(SilcDH dh);
  *    the `x' is NULL. The returned `x' must no be freed by the caller. 
  *
  ***/
-int silc_dh_generate_private(SilcDH dh, SilcInt **x);
+int silc_dh_generate_private(SilcDH dh, SilcMPInt **x);
 
 /****f* silccrypt/SilcDH/silc_dh_compute_public
  *
  * SYNOPSIS
  *
- *    int silc_dh_compute_public(SilcDH dh, SilcInt **y);
+ *    int silc_dh_compute_public(SilcDH dh, SilcMPInt **y);
  *
  * DESCRIPTION
  *
@@ -124,13 +124,13 @@ int silc_dh_generate_private(SilcDH dh, SilcInt **x);
  *    freed by the caller. 
  *
  ***/
-int silc_dh_compute_public(SilcDH dh, SilcInt **y);
+int silc_dh_compute_public(SilcDH dh, SilcMPInt **y);
 
 /****f* silccrypt/SilcDH/silc_dh_remote_public
  *
  * SYNOPSIS
  *
- *    int silc_dh_compute_public(SilcDH dh, SilcInt **y);
+ *    int silc_dh_compute_public(SilcDH dh, SilcMPInt **y);
  *
  * DESCRIPTION
  *
@@ -139,13 +139,13 @@ int silc_dh_compute_public(SilcDH dh, SilcInt **y);
  *    on error. 
  *
  ***/
-int silc_dh_set_remote_public(SilcDH dh, SilcInt *y);
+int silc_dh_set_remote_public(SilcDH dh, SilcMPInt *y);
 
 /****f* silccrypt/SilcDH/silc_dh_compute_key
  *
  * SYNOPSIS
  *
- *    int silc_dh_compute_key(SilcDH dh, SilcInt **z);
+ *    int silc_dh_compute_key(SilcDH dh, SilcMPInt **z);
  *
  * DESCRIPTION
  *
@@ -155,7 +155,7 @@ int silc_dh_set_remote_public(SilcDH dh, SilcInt *y);
  *    freed by the caller. 
  *
  ***/
-int silc_dh_compute_key(SilcDH dh, SilcInt **z);
+int silc_dh_compute_key(SilcDH dh, SilcMPInt **z);
 
 /****f* silccrypt/SilcDH/silc_dh_remote_public
  *
index 94a7fd8b36184e6b1a854d55b864aa1403a1c04a..92b420386414c8935269d50a0aa696d2d314fcc4 100644 (file)
@@ -118,7 +118,7 @@ extern SilcPKCSObject silc_default_pkcs[];
 
    Now we wouldn't have to send the SilcRng object since the primes are 
    provided as arguments. To send them as void * they could actually be 
-   used as in anyway for real (MP_INT (SilcInt) or even something else 
+   used as in anyway for real (MP_INT (SilcMPInt) or even something else 
    (the pointer could be kludged to be something else in the module))
    (Plus, the SilcRng object management in prime generation would be
    simpler and better what it is now (in silcprimegen.c, that is)).
index 663a2ef8c7d899ee1207c72050b07e20cb90ed5a..e362edcb8924eef9943afd51501edd8878916642 100644 (file)
 
 AUTOMAKE_OPTIONS = 1.0 no-dependencies foreign
 
-if SILC_BUILD_GMP
-SUBDIRS = gmp
+if SILC_MP_NSS_MPI
+SUBDIRS = mpi
 else
 SUBDIRS =
 endif
 
 noinst_LIBRARIES = libsilcmath.a
 
+if SILC_MP_NSS_MPI
+MP_SOURCE = mp_mpi.c
+else
+MP_SOURCE = mp_gmp.c
+endif
+
 libsilcmath_a_SOURCES = \
        silcprimegen.c \
        modinv.c \
-       mpbin.c
+       mpbin.c \
+       $(MP_SOURCE)
 
 EXTRA_DIST = *.h
 
index c41dab0022835db0122f9844ac5445f9783eaf30..7863923e4bf7dc76c88163d91812bd638255a3fd 100644 (file)
@@ -23,7 +23,7 @@
 
 /* Table for finding multiplicative inverse */
 typedef struct {
-  SilcInt x;
+  SilcMPInt x;
 } ModInv;
 
 #define plus1  (i == 2 ? 0 : i + 1)
@@ -47,11 +47,11 @@ typedef struct {
    not needed by the algorithm so it does not have to be included.)
 */
 
-void silc_mp_modinv(SilcInt *inv, SilcInt *a, SilcInt *n)
+void silc_mp_modinv(SilcMPInt *inv, SilcMPInt *a, SilcMPInt *n)
 {
   int i;
-  SilcInt y;
-  SilcInt x;
+  SilcMPInt y;
+  SilcMPInt x;
   
   ModInv g[3];
   ModInv v[3];
@@ -59,11 +59,15 @@ void silc_mp_modinv(SilcInt *inv, SilcInt *a, SilcInt *n)
   /* init MP vars */
   silc_mp_init(&y);
   silc_mp_init(&x);
-  silc_mp_init_set_ui(&v[0].x, 0L);            /* v(0) = 0 */
-  silc_mp_init_set_ui(&v[1].x, 1L);            /* v(1) = 1 */
+  silc_mp_init(&v[0].x);
+  silc_mp_init(&v[1].x);
+  silc_mp_set_ui(&v[0].x, 0L);         /* v(0) = 0 */
+  silc_mp_set_ui(&v[1].x, 1L);         /* v(1) = 1 */
   silc_mp_init(&v[2].x);
-  silc_mp_init_set(&g[0].x, n);                        /* g(0) = n */
-  silc_mp_init_set(&g[1].x, a);                        /* g(1) = a */
+  silc_mp_init(&g[0].x);
+  silc_mp_init(&g[1].x);
+  silc_mp_set(&g[0].x, n);                     /* g(0) = n */
+  silc_mp_set(&g[1].x, a);             /* g(1) = a */
   silc_mp_init(&g[2].x);
   
   i = 1;
@@ -86,12 +90,12 @@ void silc_mp_modinv(SilcInt *inv, SilcInt *a, SilcInt *n)
   /* clear the vars */
   memset(&g, 0, sizeof(g));
   memset(&v, 0, sizeof(v));
-  silc_mp_clear(&y);
-  silc_mp_clear(&x);
-  silc_mp_clear(&g[0].x);
-  silc_mp_clear(&g[1].x);
-  silc_mp_clear(&g[2].x);
-  silc_mp_clear(&v[0].x);
-  silc_mp_clear(&v[1].x);
-  silc_mp_clear(&v[2].x);
+  silc_mp_uninit(&y);
+  silc_mp_uninit(&x);
+  silc_mp_uninit(&g[0].x);
+  silc_mp_uninit(&g[1].x);
+  silc_mp_uninit(&g[2].x);
+  silc_mp_uninit(&v[0].x);
+  silc_mp_uninit(&v[1].x);
+  silc_mp_uninit(&v[2].x);
 }
diff --git a/lib/silcmath/mp_gmp.c b/lib/silcmath/mp_gmp.c
new file mode 100644 (file)
index 0000000..b8f1cda
--- /dev/null
@@ -0,0 +1,237 @@
+/*
+
+  mp_gmp.c
+
+  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+  Copyright (C) 2001 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
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+  
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+*/
+/* $Id$ */
+
+#include "silcincludes.h"
+#include <gmp.h>
+
+void silc_mp_init(SilcMPInt *mp)
+{
+  mpz_init(mp);
+}
+
+void silc_mp_uninit(SilcMPInt *mp)
+{
+  mpz_clear(mp);
+}
+
+size_t silc_mp_size(SilcMPInt *mp)
+{
+  return mpz_size(mp);
+}
+
+size_t silc_mp_sizeinbase(SilcMPInt *mp, int base)
+{
+  return mpz_sizeinbase(mp, base);
+}
+
+void silc_mp_set(SilcMPInt *dst, SilcMPInt *src)
+{
+  mpz_set(dst, src);
+}
+
+void silc_mp_set_ui(SilcMPInt *dst, uint32 ui)
+{
+  mpz_set_ui(dst, ui);
+}
+
+void silc_mp_set_si(SilcMPInt *dst, int32 si)
+{
+  mpz_set_si(dst, si);
+}
+
+void silc_mp_set_str(SilcMPInt *dst, const char *str, int base)
+{
+  mpz_set_str(dst, str, base);
+}
+
+uint32 silc_mp_get_ui(SilcMPInt *mp)
+{
+  return (uint32)mpz_get_ui(mp);
+}
+
+char *silc_mp_get_str(char *str, SilcMPInt *mp, int base)
+{
+  return mpz_get_str(str, base, mp);
+}
+
+void silc_mp_add(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  mpz_add(dst, mp1, mp2);
+}
+
+void silc_mp_add_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui)
+{
+  mpz_add_ui(dst, mp1, ui);
+}
+
+void silc_mp_sub(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  mpz_sub(dst, mp1, mp2);
+}
+
+void silc_mp_sub_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui)
+{
+  mpz_sub_ui(dst, mp1, ui);
+}
+
+void silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  mpz_mul(dst, mp1, mp2);
+}
+
+void silc_mp_mul_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui)
+{
+  mpz_mul_ui(dst, mp1, ui);
+}
+
+void silc_mp_mul_2exp(SilcMPInt *dst, SilcMPInt *mp1, uint32 exp)
+{
+  mpz_mul_2exp(dst, mp1, exp);
+}
+
+void silc_mp_sqrt(SilcMPInt *dst, SilcMPInt *src)
+{
+  mpz_sqrt(dst, src);
+}
+
+void silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  mpz_div(dst, mp1, mp2);
+}
+
+void silc_mp_div_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui)
+{
+  mpz_div_ui(dst, mp1, ui);
+}
+
+void silc_mp_div_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, 
+                   SilcMPInt *mp2)
+{
+  if (q && r)
+    mpz_fdiv_qr(q, r, mp1, mp2);
+  if (q && !r)
+    mpz_div(q, mp1, mp2);
+  if (!q && r)
+    mpz_mod(r, mp1, mp2);
+}
+
+void silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, uint32 exp)
+{
+  mpz_fdiv_q_2exp(dst, mp1, exp);
+}
+
+void silc_mp_div_2exp_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, 
+                        uint32 exp)
+{
+  if (q)
+    mpz_fdiv_q_2exp(q, mp1, exp);
+  if (r)
+    mpz_fdiv_r_2exp(r, mp1, exp);
+}
+
+void silc_mp_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  mpz_mod(dst, mp1, mp2);
+}
+
+void silc_mp_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui)
+{
+  mpz_mod_ui(dst, mp1, ui);
+}
+
+void silc_mp_mod_2exp(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui)
+{
+  mpz_mod_2exp(dst, mp1, ui);
+}
+
+void silc_mp_pow(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp)
+{
+  uint32 uiexp = mpz_get_ui(exp);
+  mpz_pow_ui(dst, mp1, uiexp);
+}
+
+void silc_mp_pow_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 exp)
+{
+  mpz_pow_ui(dst, mp1, exp);
+}
+
+void silc_mp_pow_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp, 
+                    SilcMPInt *mod)
+{
+  mpz_powm(dst, mp1, exp, mod);
+}
+
+void silc_mp_pow_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 exp, 
+                       SilcMPInt *mod)
+{
+  mpz_powm_ui(dst, mp1, exp, mod);
+}
+
+void silc_mp_gcd(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  mpz_gcd(dst, mp1, mp2);
+}
+
+void silc_mp_gcdext(SilcMPInt *g, SilcMPInt *s, SilcMPInt *t, SilcMPInt *mp1,
+                   SilcMPInt *mp2)
+{
+  mpz_gcdext(g, s, t, mp1, mp2);
+}
+
+int silc_mp_cmp(SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  return mpz_cmp(mp1, mp2);
+}
+
+int silc_mp_cmp_si(SilcMPInt *mp1, int32 si)
+{
+  return mpz_cmp_si(mp1, si);
+}
+
+int silc_mp_cmp_ui(SilcMPInt *mp1, uint32 ui)
+{
+  return mpz_cmp_ui(mp1, ui);
+}
+
+void silc_mp_abs(SilcMPInt *dst, SilcMPInt *src)
+{
+  mpz_abs(dst, src);
+}
+
+void silc_mp_neg(SilcMPInt *dst, SilcMPInt *src)
+{
+  mpz_neg(dst, src);
+}
+
+void silc_mp_and(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  mpz_and(dst, mp1, mp2);
+}
+
+void silc_mp_or(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  mpz_ior(dst, mp1, mp2);
+}
+
+void silc_mp_xor(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  mpz_xor(dst, mp1, mp2);
+}
diff --git a/lib/silcmath/mp_gmp.h b/lib/silcmath/mp_gmp.h
new file mode 100644 (file)
index 0000000..14ae512
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+
+  mp_gmp.h
+
+  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+  Copyright (C) 2001 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
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+  
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+*/
+
+#ifndef MP_GMP_H
+#define MP_GMP_H
+
+#include <gmp.h>
+
+#define SILC_MP_INT MP_INT
+
+#endif
diff --git a/lib/silcmath/mp_mpi.c b/lib/silcmath/mp_mpi.c
new file mode 100644 (file)
index 0000000..179aa97
--- /dev/null
@@ -0,0 +1,254 @@
+/*
+
+  mp_mpi.c
+
+  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+  Copyright (C) 2001 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
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+  
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+*/
+/* $Id$ */
+
+#include "silcincludes.h"
+#include "mpi.h"
+#include "mplogic.h"
+
+void silc_mp_init(SilcMPInt *mp)
+{
+  (void)mp_init(mp);
+}
+
+void silc_mp_uninit(SilcMPInt *mp)
+{
+  (void)mp_clear(mp);
+}
+
+size_t silc_mp_size(SilcMPInt *mp)
+{
+  return mp_raw_size(mp);
+}
+
+size_t silc_mp_sizeinbase(SilcMPInt *mp, int base)
+{
+  return mp_radix_size(mp, base) - 2; /* XXX this is wrong but it looks like
+                                        the MPI always returns the correct
+                                        value plus one as opposed what the
+                                        GMP does, it returns always one less,
+                                        and SILC code expects that. Bad thing
+                                        is that the condition "returns always
+                                        correct value" cannot be trusted! */
+}
+
+void silc_mp_set(SilcMPInt *dst, SilcMPInt *src)
+{
+  (void)mp_copy(src, dst);
+}
+
+void silc_mp_set_ui(SilcMPInt *dst, uint32 ui)
+{
+  mp_set(dst, ui);
+}
+
+void silc_mp_set_si(SilcMPInt *dst, int32 si)
+{
+  (void)mp_set_int(dst, si);
+}
+
+void silc_mp_set_str(SilcMPInt *dst, const char *str, int base)
+{
+  (void)mp_read_variable_radix(dst, str, base);
+}
+
+uint32 silc_mp_get_ui(SilcMPInt *mp)
+{
+  return (uint32)MP_DIGIT(mp, 0);
+}
+
+char *silc_mp_get_str(char *str, SilcMPInt *mp, int base)
+{
+  if (mp_toradix(mp, str, base) != MP_OKAY)
+    return NULL;
+  return str;
+}
+
+void silc_mp_add(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  (void)mp_add(mp1, mp2, dst);
+}
+
+void silc_mp_add_ui(SilcMPInt *dst, SilcMPInt *mp1, mp_digit ui)
+{
+  mp_add_d(mp1, ui, dst);
+}
+
+void silc_mp_sub(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  (void)mp_sub(mp1, mp2, dst);
+}
+
+void silc_mp_sub_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui)
+{
+  (void)mp_sub_d(mp1, (mp_digit)ui, dst);
+}
+
+void silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  (void)mp_mul(mp1, mp2, dst);
+}
+
+void silc_mp_mul_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui)
+{
+  (void)mp_mul_d(mp1, (mp_digit)ui, dst);
+}
+
+void silc_mp_mul_2exp(SilcMPInt *dst, SilcMPInt *mp1, uint32 exp)
+{
+  SilcMPInt tmp;
+  silc_mp_init(&tmp);
+  (void)mp_2expt(&tmp, (mp_digit)exp);
+  (void)mp_mul(mp1, &tmp, dst);
+  silc_mp_uninit(&tmp);
+}
+
+void silc_mp_sqrt(SilcMPInt *dst, SilcMPInt *src)
+{
+  (void)mp_sqrt(src, dst);
+}
+
+void silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  (void)mp_div(mp1, mp2, dst, NULL);
+}
+
+void silc_mp_div_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui)
+{
+  (void)mp_div_d(mp1, (mp_digit)ui, dst, NULL);
+}
+
+void silc_mp_div_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, 
+                   SilcMPInt *mp2)
+{
+  (void)mp_div(mp1, mp2, q, r);
+}
+
+void silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, uint32 exp)
+{
+  SilcMPInt tmp;
+  silc_mp_init(&tmp);
+  (void)mp_2expt(&tmp, (mp_digit)exp);
+  (void)mp_div(mp1, &tmp, dst, NULL);
+  silc_mp_uninit(&tmp);
+}
+
+void silc_mp_div_2exp_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, 
+                        uint32 exp)
+{
+  if (q) {
+    (void)mp_2expt(q, (mp_digit)exp);
+    (void)mp_div(mp1, q, q, r);
+  }
+}
+
+void silc_mp_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  (void)mp_mod(mp1, mp2, dst);
+}
+
+void silc_mp_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui)
+{
+  mp_digit uidst;
+  (void)mp_mod_d(mp1, (mp_digit)ui, &uidst);
+  mp_set(dst, uidst);
+}
+
+void silc_mp_mod_2exp(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui)
+{
+  SilcMPInt tmp;
+  silc_mp_init(&tmp);
+  (void)mp_2expt(&tmp, (mp_digit)ui);
+  (void)mp_mod(mp1, &tmp, dst);
+  silc_mp_uninit(&tmp);
+}
+
+void silc_mp_pow(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp)
+{
+  (void)mp_expt(mp1, exp, dst);
+}
+
+void silc_mp_pow_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 exp)
+{
+  (void)mp_expt_d(mp1, (mp_digit)exp, dst);
+}
+
+void silc_mp_pow_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp, 
+                    SilcMPInt *mod)
+{
+  (void)mp_exptmod(mp1, exp, mod, dst);
+}
+
+void silc_mp_pow_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 exp, 
+                       SilcMPInt *mod)
+{
+  (void)mp_exptmod_d(mp1, (mp_digit)exp, mod, dst);
+}
+
+void silc_mp_gcd(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  (void)mp_gcd(mp1, mp2, dst);
+}
+
+void silc_mp_gcdext(SilcMPInt *g, SilcMPInt *s, SilcMPInt *t, SilcMPInt *mp1,
+                   SilcMPInt *mp2)
+{
+  (void)mp_xgcd(mp1, mp2, g, s, t);
+}
+
+int silc_mp_cmp(SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  return mp_cmp(mp1, mp2);
+}
+
+int silc_mp_cmp_si(SilcMPInt *mp1, int32 si)
+{
+  return mp_cmp_int(mp1, (long)si);
+}
+
+int silc_mp_cmp_ui(SilcMPInt *mp1, uint32 ui)
+{
+  return mp_cmp_d(mp1, ui);
+}
+
+void silc_mp_abs(SilcMPInt *dst, SilcMPInt *src)
+{
+  mp_abs(src, dst);
+}
+
+void silc_mp_neg(SilcMPInt *dst, SilcMPInt *src)
+{
+  mp_neg(src, dst);
+}
+
+void silc_mp_and(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  mpl_and(mp1, mp2, dst);
+}
+
+void silc_mp_or(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  mpl_or(mp1, mp2, dst);
+}
+
+void silc_mp_xor(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2)
+{
+  mpl_xor(mp1, mp2, dst);
+}
diff --git a/lib/silcmath/mp_mpi.h b/lib/silcmath/mp_mpi.h
new file mode 100644 (file)
index 0000000..54614a3
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+
+  mp_mpi.h
+
+  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+  Copyright (C) 2001 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
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+  
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+*/
+
+#ifndef MP_MPI_H
+#define MP_MPI_H
+
+#include "mpi.h"
+#include "mplogic.h"
+
+#define SILC_MP_INT mp_int
+
+#endif
index 844cb038f4c108b1d9fdfeebef954a8b96a36ac7..8074f2bc706429416fd087563a8ac187bdfb0d35 100644 (file)
    must be free'd by the caller. If `len' is provided the destination
    buffer is allocated that large. If zero then the size is approximated. */
 
-unsigned char *silc_mp_mp2bin(SilcInt *val, uint32 len,
+unsigned char *silc_mp_mp2bin(SilcMPInt *val, uint32 len,
                              uint32 *ret_len)
 {
   int i;
   uint32 size;
   unsigned char *ret;
-  SilcInt tmp;
+  SilcMPInt tmp;
 
   size = (len ? len : ((silc_mp_sizeinbase(val, 2) + 7) / 8));
   ret = silc_calloc(size, sizeof(*ret));
   
-  silc_mp_init_set(&tmp, val);
+  silc_mp_init(&tmp);
+  silc_mp_set(&tmp, val);
 
   for (i = size; i > 0; i--) {
     ret[i - 1] = (unsigned char)(silc_mp_get_ui(&tmp) & 0xff);
-    silc_mp_fdiv_q_2exp(&tmp, &tmp, 8);
+    silc_mp_div_2exp(&tmp, &tmp, 8);
   }
 
-  silc_mp_clear(&tmp);
+  silc_mp_uninit(&tmp);
 
   if (ret_len)
     *ret_len = size;
@@ -54,27 +55,28 @@ unsigned char *silc_mp_mp2bin(SilcInt *val, uint32 len,
 /* Samve as above but does not allocate any memory.  The encoded data is
    returned into `dst' and it's length to the `ret_len'. */
 
-void silc_mp_mp2bin_noalloc(SilcInt *val, unsigned char *dst,
+void silc_mp_mp2bin_noalloc(SilcMPInt *val, unsigned char *dst,
                            uint32 dst_len)
 {
   int i;
   uint32 size = dst_len;
-  SilcInt tmp;
+  SilcMPInt tmp;
 
-  silc_mp_init_set(&tmp, val);
+  silc_mp_init(&tmp);
+  silc_mp_set(&tmp, val);
 
   for (i = size; i > 0; i--) {
     dst[i - 1] = (unsigned char)(silc_mp_get_ui(&tmp) & 0xff);
-    silc_mp_fdiv_q_2exp(&tmp, &tmp, 8);
+    silc_mp_div_2exp(&tmp, &tmp, 8);
   }
 
-  silc_mp_clear(&tmp);
+  silc_mp_uninit(&tmp);
 }
 
 /* Decodes binary data into MP integer. The integer sent as argument
    must be initialized. */
 
-void silc_mp_bin2mp(unsigned char *data, uint32 len, SilcInt *ret)
+void silc_mp_bin2mp(unsigned char *data, uint32 len, SilcMPInt *ret)
 {
   int i;
 
index 0c1141ee493d1c102cc402e0d90b8e4ee95afd4b..ef2241bf82eeeedef9d441794cca8f07da2daa31 100644 (file)
@@ -35,7 +35,7 @@
  *
  * SYNOPSIS
  *
- *    int silc_math_gen_prime(SilcInt *prime, uint32 bits, int verbose);
+ *    int silc_math_gen_prime(SilcMPInt *prime, uint32 bits, int verbose);
  *
  * DESCRIPTION
  *
  *    about the progress of generation.
  *
  ***/
-int silc_math_gen_prime(SilcInt *prime, uint32 bits, int verbose);
+int silc_math_gen_prime(SilcMPInt *prime, uint32 bits, int verbose);
 
 /****f* silcmath/SilcMathAPI/silc_math_prime_test
  *
  * SYNOPSIS
  *
- *    int silc_math_prime_test(SilcInt *p);
+ *    int silc_math_prime_test(SilcMPInt *p);
  *
  * DESCRIPTION
  *
@@ -62,6 +62,6 @@ int silc_math_gen_prime(SilcInt *prime, uint32 bits, int verbose);
  *    number is probably a prime.
  *
  ***/
-int silc_math_prime_test(SilcInt *p);
+int silc_math_prime_test(SilcMPInt *p);
 
 #endif
index 00cc5f1651f1cc5f0bd4c8c310470b6f545edd4a..e611554fcfa15b43565c75dc3aa5f7c78a0565ba 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
+ * DESCRIPTION
+ *
+ * SILC MP Library Interface. This interface defines the arbitrary
+ * precision arithmetic routines for SILC. Currently the actual routines
+ * are implemented separately, usually by some other MP library. The
+ * interface is generic but is mainly intended for crypto usage. This
+ * interface is used by SILC routines that needs big numbers, such as
+ * RSA implementation, Diffie-Hellman implementation etc.
+ *
  ***/
 
 #ifndef SILCMP_H
 #define SILCMP_H
 
-#include "gmp.h"
-
-#if 1
-
-/* SILC MP library definitions. We use GNU MP library as default
-   MP library. However, to make possible future changes easier (SILC 
-   might have its own MP library in the future) we implement our own 
-   MP API with simple macros. */ 
-
-typedef MP_INT SilcInt;
-#define silc_mp_abs(a, b) mpz_abs((a), (b))
-#define silc_mp_add(a, b, c) mpz_add((a), (b), (c))
-#define silc_mp_add_ui(a, b, c) mpz_add_ui((a), (b), (c))
-#define silc_mp_and(a, b, c) mpz_and((a), (b), (c))
-#define silc_mp_cdiv_q(a, b, c) mpz_cdiv_q((a), (b), (c))
-#define silc_mp_cdiv_q_ui(a, b, c) mpz_cdiv_q_ui((a), (b), (c))
-#define silc_mp_cdiv_r(a, b, c) mpz_cdiv_r((a), (b), (c))
-#define silc_mp_cdiv_r_ui(a, b, c) mpz_cdiv_r_ui((a), (b), (c))
-#define silc_mp_cdiv_ui(a, b) mpz_cdiv_ui((a), (b))
-#define silc_mp_clear(a) mpz_clear((a))
-#define silc_mp_clrbit(a, b) mpz_clrbit((a), (b))
-#define silc_mp_cmp(a, b) mpz_cmp((a), (b))
-#define silc_mp_cmp_si(a, b) mpz_cmp_si((a), (b))
-#define silc_mp_cmp_ui(a, b) mpz_cmp_ui((a), (b))
-#define silc_mp_com(a, b) mpz_com((a), (b))
-#define silc_mp_divexact(a, b, c) mpz_divexact((a), (b), (c))
-#define silc_mp_div(a, b, c) mpz_div((a), (b), (c))
-#define silc_mp_div_ui(a, b, c) mpz_div_ui((a), (b), (c))
-#define silc_mp_fdiv_ui(a, b) mpz_fdiv_ui((a), (b))
-#define silc_mp_fdiv_q(a, b, c) mpz_fdiv_q((a), (b), (c))
-#define silc_mp_fdiv_q_2exp(a, b, c) mpz_fdiv_q_2exp((a), (b), (c))
-#define silc_mp_fdiv_q_ui(a, b, c) mpz_fdiv_q_ui((a), (b), (c))
-#define silc_mp_fdiv_qr(a, b, c, d) mpz_fdiv_qr((a), (b), (c), (d))
-#define silc_mp_fdiv_qr_ui(a, b, c, d) mpz_fdiv_qr_ui((a), (b), (c), (d))
-#define silc_mp_fdiv_r(a, b, c) mpz_fdiv_r((a), (b), (c))
-#define silc_mp_fdiv_r_2exp(a, b, c) mpz_fdiv_r_2exp((a), (b), (c))
-#define silc_mp_fdiv_r_ui(a, b, c) mpz_fdiv_r_ui((a), (b), (c))
-#define silc_mp_fdiv_ui(a, b) mpz_fdiv_ui((a), (b))
-#define silc_mp_gcd(a, b, c) mpz_gcd((a), (b), (c))
-#define silc_mp_gcd_ui(a, b, c) mpz_gcd_ui((a), (b), (c))
-#define silc_mp_gcdext(a, b, c, d, e) mpz_gcdext((a), (b), (c), (d), (e))
-#define silc_mp_get_ui(a) mpz_get_ui((a))
-#define silc_mp_init(a) mpz_init((a))
-#define silc_mp_init_set(a, b) mpz_init_set((a), (b))
-#define silc_mp_init_set_d(a, b) mpz_init_set_d((a), (b))
-#define silc_mp_init_set_si(a, b) mpz_init_set_si((a), (b))
-#define silc_mp_init_set_str(a, b, c) mpz_init_set_str((a), (b), (c))
-#define silc_mp_init_set_ui(a, b) mpz_init_set_ui((a), (b))
-#define silc_mp_invert(a, b, c) mpz_invert((a), (b), (c))
-#define silc_mp_ior(a, b, c) mpz_ior((a), (b), (c))
-#define silc_mp_mod(a, b, c) mpz_mod((a), (b), (c))
-#define silc_mp_mod_2exp(a, b, c) mpz_mod_2exp((a), (b), (c))
-#define silc_mp_mod_ui(a, b, c) mpz_mod_ui((a), (b), (c))
-#define silc_mp_mul(a, b, c) mpz_mul((a), (b), (c))
-#define silc_mp_mul_2exp(a, b, c) mpz_mul_2exp((a), (b), (c))
-#define silc_mp_mul_ui(a, b, c) mpz_mul_ui((a), (b), (c))
-#define silc_mp_neg(a, b) mpz_neg((a), (b))
-#define silc_mp_pow_ui(a, b, c) mpz_pow_ui((a), (b), (c))
-#define silc_mp_powm(a, b, c, d) mpz_powm((a), (b), (c), (d))
-#define silc_mp_powm_ui(a, b, c, d) mpz_powm_ui((a), (b), (c), (d))
-#define silc_mp_probab_prime_p(a, b) mpz_probab_prime_p((a), (b))
-#define silc_mp_set(a, b) mpz_set((a), (b))
-#define silc_mp_set_d(a, b) mpz_set_d((a), (b))
-#define silc_mp_set_f(a, b) mpz_set_f((a), (b))
-#define silc_mp_set_q(a, b) mpz_set_q((a), (b))
-#define silc_mp_set_si(a, b) mpz_set_si((a), (b))
-#define silc_mp_set_str(a, b, c) mpz_set_str((a), (b), (c))
-#define silc_mp_set_ui(a, b) mpz_set_ui((a), (b))
-#define silc_mp_setbit(a, b) mpz_setbit((a), (b))
-#define silc_mp_size(a) mpz_size((a))
-#define silc_mp_sizeinbase(a, b) mpz_sizeinbase((a), (b))
-#define silc_mp_sqrt(a, b) mpz_sqrt((a), (b))
-#define silc_mp_sqrtrem(a, b, c) mpz_sqrtrem((a), (b), (c))
-#define silc_mp_sub(a, b, c) mpz_sub((a), (b), (c))
-#define silc_mp_sub_ui(a, b, c) mpz_sub_ui((a), (b), (c))
-#define silc_mp_tdiv_ui(a, b) mpz_tdiv_ui((a), (b))
-#define silc_mp_tdiv_q(a, b, c) mpz_tdiv_q((a), (b), (c))
-#define silc_mp_tdiv_q_2exp(a, b, c) mpz_tdiv_q_2exp((a), (b), (c))
-#define silc_mp_tdiv_q_ui(a, b, c) mpz_tdiv_q_ui((a), (b), (c))
-#define silc_mp_tdiv_qr(a, b, c, d) mpz_tdiv_qr((a), (b), (c), (d))
-#define silc_mp_tdiv_qr_ui(a, b, c, d) mpz_tdiv_qr_ui((a), (b), (c), (d))
-#define silc_mp_tdiv_r(a, b, c) mpz_tdiv_r((a), (b), (c))
-#define silc_mp_tdiv_r_2exp(a, b, c) mpz_tdiv_r_2exp((a), (b), (c))
-#define silc_mp_tdiv_r_ui(a, b, c) mpz_tdiv_r_ui((a), (b), (c))
-#define silc_mp_tdiv_ui(a, b) mpz_tdiv_ui((a), (b))
-#define silc_mp_ui_pow_ui(a, b, c) mpz_ui_pow_ui((a), (b), (c))
-#define silc_mp_get_str(a, b, c) mpz_get_str((a), (b), (c))
-#define silc_mp_out_str(a, b, c) mpz_out_str((a), (b), (c))
-
+#ifdef SILC_MP_GMP
+#include "mp_gmp.h"            /* SILC_MP_GMP */
 #else
-
-/* SILC MP Library Interface. This interface defines the arbitrary
-   precision arithmetic routines for SILC. Currently the actual routines
-   are implemented separately, usually by some other MP library. The
-   interface is generic but is mainly intended for crypto usage. This
-   interface is used by SILC routines that needs big numbers, such as
-   RSA implementation, Diffie-Hellman implementation etc. */
-
-/* XXX Move this to implementation specific files */
-#define SILC_MP_INT MP_INT
+#include "mp_mpi.h"            /* SILC_MP_NSS_MPI */
+#endif
 
 /****d* silcmath/SilcMPAPI/SilcMPInt
  *
@@ -171,348 +85,351 @@ void silc_mp_init(SilcMPInt *mp);
  ***/
 void silc_mp_uninit(SilcMPInt *mp);
 
-/****f* silcmath/SilcMPAPI/silc_mp_abs
+/****f* silcmath/SilcMPAPI/silc_mp_size
  *
  * SYNOPSIS
  *
- *    void silc_mp_abs(SilcMPInt *src, SilcMPInt *dst);
+ *    size_t silc_mp_size(SilcMPInt *mp);
  *
  * DESCRIPTION
  *
- *    Assign the absolute value of `src' to `dst'.
+ *    Return the precision size of the integer `mp'.
  *
  ***/
-void silc_mp_abs(SilcMPInt *dst, SilcMPInt *src);
+size_t silc_mp_size(SilcMPInt *mp);
 
-/****f* silcmath/SilcMPAPI/silc_mp_add
+/****f* silcmath/SilcMPAPI/silc_mp_sizeinbase
  *
  * SYNOPSIS
  *
- *    void silc_mp_add(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *    size_t silc_mp_sizeinbase(SilcMPInt *mp, int base);
  *
  * DESCRIPTION
  *
- *    Add two integers `mp1' and `mp2' and save the result to `dst'.
+ *    Return the size of the integer in base `base'. Note that this size
+ *    is probably only an approximation.  However, it is guaranteed that
+ *    the returned size is always at least the size of the integer, however,
+ *    it may be larger.
  *
  ***/
-void silc_mp_add(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+size_t silc_mp_sizeinbase(SilcMPInt *mp, int base);
 
-/****f* silcmath/SilcMPAPI/silc_mp_add_ui
+/****f* silcmath/SilcMPAPI/silc_mp_set
  *
  * SYNOPSIS
  *
- *    void silc_mp_add_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
+ *    void silc_mp_set(SilcMPInt *dst, SilcMPInt *src);
  *
  * DESCRIPTION
  *
- *    Add two integers `mp1' and unsigned word `ui' and save the result
- *    to `dst'.
+ *    Set `dst' integer from `src' integer. The `dst' must already be
+ *    initialized.
  *
  ***/
-void silc_mp_add_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
+void silc_mp_set(SilcMPInt *dst, SilcMPInt *src);
 
-/****f* silcmath/SilcMPAPI/silc_mp_and
+/****f* silcmath/SilcMPAPI/silc_mp_set_ui
  *
  * SYNOPSIS
  *
- *    void silc_mp_and(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *    void silc_mp_set_ui(SilcMPInt *dst, uint32 ui);
  *
  * DESCRIPTION
  *
- *    Logical and operator. The result is saved to `dst'.
+ *    Set `dst' integer from unsigned word `ui'. The `dst' must already be
+ *    initialized.
  *
  ***/
-void silc_mp_and(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+void silc_mp_set_ui(SilcMPInt *dst, uint32 ui);
 
-/****f* silcmath/SilcMPAPI/silc_mp_cmp
+/****f* silcmath/SilcMPAPI/silc_mp_set_si
  *
  * SYNOPSIS
  *
- *    int silc_mp_cmp(SilcMPInt *mp1, SilcMPInt *mp2);
+ *    void silc_mp_set_si(SilcMPInt *dst, int32 si);
  *
  * DESCRIPTION
  *
- *    Compare `mp1' and `mp2'. Returns posivite, zero, or negative
- *    if `mp1' > `mp2', `mp1' == `mp2', or `mp1' < `mp2', respectively.
+ *    Set `dst' integer from single word `si'. The `dst' must
+ *    already be initialized.
  *
  ***/
-int silc_mp_cmp(SilcMPInt *mp1, SilcMPInt *mp2);
+void silc_mp_set_si(SilcMPInt *dst, int32 si);
 
-/****f* silcmath/SilcMPAPI/silc_mp_cmp_si
+/****f* silcmath/SilcMPAPI/silc_mp_set_str
  *
  * SYNOPSIS
  *
- *    int silc_mp_cmp_si(SilcMPInt *mp1, int32 si);
+ *    void silc_mp_set_str(SilcMPInt *dst, const char *str, int base);
  *
  * DESCRIPTION
  *
- *    Compare `mp1' and single word `si'. Returns posivite, zero, or negative
- *    if `mp1' > `si', `mp1' == `si', or `mp1' < `si', respectively.
+ *    Set `dst' integer from string `str' of base `base'. The `dst' must
+ *    already be initialized.
  *
  ***/
-int silc_mp_cmp_si(SilcMPInt *mp1, int32 si);
+void silc_mp_set_str(SilcMPInt *dst, const char *str, int base);
 
-/****f* silcmath/SilcMPAPI/silc_mp_cmp_ui
+/****f* silcmath/SilcMPAPI/silc_mp_get_ui
  *
  * SYNOPSIS
  *
- *    int silc_mp_cmp_ui(SilcMPInt *mp1, uint32 ui);
+ *    uint32 silc_mp_get_ui(SilcMPInt *mp);
  *
  * DESCRIPTION
  *
- *    Compare `mp1' and unsigned word `ui'. Returns posivite, zero, or 
- *    negative if `mp1' > `ui', `mp1' == `ui', or `mp1' < `ui', 
- *    respectively.
+ *    Returns the least significant unsigned word from `mp'.
  *
  ***/
-int silc_mp_cmp_ui(SilcMPInt *mp1, uint32 ui);
+uint32 silc_mp_get_ui(SilcMPInt *mp);
 
-/****f* silcmath/SilcMPAPI/silc_mp_div
+/****f* silcmath/SilcMPAPI/silc_mp_get_str
  *
  * SYNOPSIS
  *
- *    void silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *    void silc_mp_get_str(char *str, SilcMPInt *mp, int base);
  *
  * DESCRIPTION
  *
- *    Divide the `mp1' and `mp2' and save the result to the `dst'. This
- *    is equivalent to dst = mp1 / mp2;
+ *    Converts integer `mp' into a string of base `base'. The `str'
+ *    must already have space allocated. The function returns the same
+ *    as `str' or NULL on error.
  *
  ***/
-void silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+char *silc_mp_get_str(char *str, SilcMPInt *mp, int base);
 
-/****f* silcmath/SilcMPAPI/silc_mp_div_ui
+/****f* silcmath/SilcMPAPI/silc_mp_add
  *
  * SYNOPSIS
  *
- *    void silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *    void silc_mp_add(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
  *
  * DESCRIPTION
  *
- *    Divide the `mp1' and unsigned word `ui' and save the result to the
- *    `dst'. This is equivalent to dst = mp1 / ui;
+ *    Add two integers `mp1' and `mp2' and save the result to `dst'.
  *
  ***/
-void silc_mp_div_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
+void silc_mp_add(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
 
-/****f* silcmath/SilcMPAPI/silc_mp_div_qr
+/****f* silcmath/SilcMPAPI/silc_mp_add_ui
  *
  * SYNOPSIS
  *
- *    void silc_mp_div_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, 
- *                        SilcMPInt *mp2);
+ *    void silc_mp_add_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
  *
  * DESCRIPTION
  *
- *    Divide the `mp1' and `mp2' and save the quotient to the `q' and
- *    the remainder to the `r'.  This is equivalent to the q = mp1 / mp2, 
- *    r = mp1 mod mp2 (or mp1 = mp2 * q + r). If the `q' or `r' is NULL
- *    then the operation is omitted.
+ *    Add two integers `mp1' and unsigned word `ui' and save the result
+ *    to `dst'.
  *
  ***/
-void silc_mp_div_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, SilcMPInt *mp2);
+void silc_mp_add_ui(SilcMPInt *dst, SilcMPInt *mp1, mp_digit ui);
 
-/****f* silcmath/SilcMPAPI/silc_mp_div_2exp
+/****f* silcmath/SilcMPAPI/silc_mp_sub
  *
  * SYNOPSIS
  *
- *    void silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *    void silc_mp_sub(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
  *
  * DESCRIPTION
  *
- *    Divide the `mp1' with 2 ** `exp' and save the result to `dst'.
- *    This is equivalent to dst = mp1 / (2 ^ exp).
+ *    Subtract two integers `mp1' and `mp2' and save the result to `dst'.
  *
  ***/
-void silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, uint32 exp);
+void silc_mp_sub(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
 
-/****f* silcmath/SilcMPAPI/silc_mp_div_2exp
+/****f* silcmath/SilcMPAPI/silc_mp_sub_ui
  *
  * SYNOPSIS
  *
- *    void silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *    void silc_mp_sub_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
  *
  * DESCRIPTION
  *
- *    Divide the `mp1' with 2 ** `exp' and save the quotient to `q' and
- *    the remainder to `r'. This is equivalent to q = mp1 / (2 ^ exp),
- *    r = mp1 mod (2 ^ exp). If the `q' or `r' is NULL then the operation
- *    is omitted.
+ *    Subtract integers `mp1' and unsigned word `ui' and save the result
+ *    to `dst'.
  *
  ***/
-void silc_mp_div_2exp_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, uint32 exp);
+void silc_mp_sub_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
 
-/****f* silcmath/SilcMPAPI/silc_mp_gcd
+/****f* silcmath/SilcMPAPI/silc_mp_mul
  *
  * SYNOPSIS
  *
- *    void silc_mp_gcd(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *    void silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
  *
  * DESCRIPTION
  *
- *    Calculate the greatest common divisor of the integers `mp1' and `mp2'
- *    and save the result to `dst'.
+ *    Multiply two integers `mp1' and `mp2' and save the result to `dst'.
  *
  ***/
-void silc_mp_gcd(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+void silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
 
-/****f* silcmath/SilcMPAPI/silc_mp_gcdext
+/****f* silcmath/SilcMPAPI/silc_mp_mul_ui
  *
  * SYNOPSIS
  *
- *    void silc_mp_gcdext(SilcMPInt *g, SilcMPInt *s, SilcMPInt *t, SilcMPInt *mp1,
- *                        SilcMPInt *mp2);
+ *    void silc_mp_mul_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
  *
  * DESCRIPTION
  *
- *    Calculate the extended greatest common divisor `g', `s' and `t' such
- *    that g = mp1 * s + mp2 * + t.
+ *    Multiply integer `mp1' and unsigned word `ui' and save the result
+ *    to `dst'.
  *
  ***/
-void silc_mp_gcdext(SilcMPInt *g, SilcMPInt *s, SilcMPInt *t, SilcMPInt *mp1,
-                   SilcMPInt *mp2);
+void silc_mp_mul_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
 
-/****f* silcmath/SilcMPAPI/silc_mp_get_ui
+/****f* silcmath/SilcMPAPI/silc_mp_mul_2exp
  *
  * SYNOPSIS
  *
- *    uint32 silc_mp_get_ui(SilcMPInt *mp);
+ *    void silc_mp_mul_2exp(SilcMPInt *dst, SilcMPInt *mp1, uint32 exp);
  *
  * DESCRIPTION
  *
- *    Returns the least significant unsigned word from `mp'.
+ *    Multiply integers `mp1' with 2 ** `exp' and save the result to 
+ *    `dst'. This is equivalent to dst = mp1 * (2 ^ exp).
  *
  ***/
-uint32 silc_mp_get_ui(SilcMPInt *mp);
+void silc_mp_mul_2exp(SilcMPInt *dst, SilcMPInt *mp1, uint32 exp);
 
-/****f* silcmath/SilcMPAPI/silc_mp_get_str
+/****f* silcmath/SilcMPAPI/silc_mp_sqrt
  *
  * SYNOPSIS
  *
- *    void silc_mp_get_str(char *str, SilcMPInt *mp, int base);
+ *    void silc_mp_sqrt(SilcMPInt *dst, SilcMPInt *src);
  *
  * DESCRIPTION
  *
- *    Converts integer `mp' into a string of base `base'. The `str'
- *    must already have space allocated. The function returns the same
- *    as `str' or NULL on error.
+ *    Compute square root of floor(sqrt(src)) and save the result to `dst'.
  *
  ***/
-char *silc_mp_get_str(char *str, SilcMPInt *mp, int base);
+void silc_mp_sqrt(SilcMPInt *dst, SilcMPInt *src);
 
-/****f* silcmath/SilcMPAPI/silc_mp_or
+/****f* silcmath/SilcMPAPI/silc_mp_div
  *
  * SYNOPSIS
  *
- *    void silc_mp_or(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *    void silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
  *
  * DESCRIPTION
  *
- *    Logical inclusive OR operator. The result is saved to `dst'.
+ *    Divide the `mp1' and `mp2' and save the result to the `dst'. This
+ *    is equivalent to dst = mp1 / mp2;
  *
  ***/
-void silc_mp_or(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+void silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
 
-/****f* silcmath/SilcMPAPI/silc_mp_mod
+/****f* silcmath/SilcMPAPI/silc_mp_div_ui
  *
  * SYNOPSIS
  *
- *    void silc_mp_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *    void silc_mp_div_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
  *
  * DESCRIPTION
  *
- *    Mathematical MOD function. Produces the remainder of `mp1' and `mp2'
- *    and saves the result to `dst'. This is equivalent to dst = mp1 mod mp2.
- *    The same result can also be get with silc_mp_div_qr as that function
- *    returns the remainder as well.
+ *    Divide the `mp1' and unsigned word `ui' and save the result to the
+ *    `dst'. This is equivalent to dst = mp1 / ui;
  *
  ***/
-void silc_mp_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+void silc_mp_div_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
 
-/****f* silcmath/SilcMPAPI/silc_mp_mod_ui
+/****f* silcmath/SilcMPAPI/silc_mp_div_qr
  *
  * SYNOPSIS
  *
- *    void silc_mp_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
+ *    void silc_mp_div_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, 
+ *                        SilcMPInt *mp2);
  *
  * DESCRIPTION
  *
- *    Mathematical MOD function. Produces the remainder of `mp1' and 
- *    unsigned word `ui' and saves the result to `dst'. This is equivalent
- *    to dst = mp1 mod ui.
+ *    Divide the `mp1' and `mp2' and save the quotient to the `q' and
+ *    the remainder to the `r'.  This is equivalent to the q = mp1 / mp2, 
+ *    r = mp1 mod mp2 (or mp1 = mp2 * q + r). If the `q' or `r' is NULL
+ *    then the operation is omitted.
  *
  ***/
-void silc_mp_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
+void silc_mp_div_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, 
+                   SilcMPInt *mp2);
 
-/****f* silcmath/SilcMPAPI/silc_mp_mod_2exp
+/****f* silcmath/SilcMPAPI/silc_mp_div_2exp
  *
  * SYNOPSIS
  *
- *    void silc_mp_mod_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *    void silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
  *
  * DESCRIPTION
  *
- *    Computes the remainder of `mp1' with 2 ** `exp' and saves the
- *    result to `dst'. This is equivalent to dst = mp1 mod (2 ^ exp).
- *    The same result can also be get with silc_mp_div_2exp_qr as that
- *    function returns the remainder as well.
+ *    Divide the `mp1' with 2 ** `exp' and save the result to `dst'.
+ *    This is equivalent to dst = mp1 / (2 ^ exp).
  *
  ***/
-void silc_mp_mod_2exp(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
+void silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, uint32 exp);
 
-/****f* silcmath/SilcMPAPI/silc_mp_mul
+/****f* silcmath/SilcMPAPI/silc_mp_div_2exp
  *
  * SYNOPSIS
  *
- *    void silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *    void silc_mp_div_2exp_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, 
+ *                             uint32 exp);
  *
  * DESCRIPTION
  *
- *    Multiply two integers `mp1' and `mp2' and save the result to `dst'.
+ *    Divide the `mp1' with 2 ** `exp' and save the quotient to `q' and
+ *    the remainder to `r'. This is equivalent to q = mp1 / (2 ^ exp),
+ *    r = mp1 mod (2 ^ exp). If the `q' or `r' is NULL then the operation
+ *    is omitted.
  *
  ***/
-void silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+void silc_mp_div_2exp_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, 
+                        uint32 exp);
 
-/****f* silcmath/SilcMPAPI/silc_mp_mul_ui
+/****f* silcmath/SilcMPAPI/silc_mp_mod
  *
  * SYNOPSIS
  *
- *    void silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *    void silc_mp_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
  *
  * DESCRIPTION
  *
- *    Multiply integer `mp1' and unsigned word `ui' and save the result
- *    to `dst'.
+ *    Mathematical MOD function. Produces the remainder of `mp1' and `mp2'
+ *    and saves the result to `dst'. This is equivalent to dst = mp1 mod mp2.
+ *    The same result can also be get with silc_mp_div_qr as that function
+ *    returns the remainder as well.
  *
  ***/
-void silc_mp_mul_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
+void silc_mp_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
 
-/****f* silcmath/SilcMPAPI/silc_mp_mul_2exp
+/****f* silcmath/SilcMPAPI/silc_mp_mod_ui
  *
  * SYNOPSIS
  *
- *    void silc_mp_mul_2exp(SilcMPInt *dst, SilcMPInt *mp1, uint32 exp);
+ *    void silc_mp_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
  *
  * DESCRIPTION
  *
- *    Multiply integers `mp1' with 2 ** `exp' and save the result to 
- *    `dst'. This is equivalent to dst = mp1 * (2 ^ exp).
+ *    Mathematical MOD function. Produces the remainder of `mp1' and 
+ *    unsigned word `ui' and saves the result to `dst'. This is equivalent
+ *    to dst = mp1 mod ui.
  *
  ***/
-void silc_mp_mul_2exp(SilcMPInt *dst, SilcMPInt *mp1, uint32 exp);
+void silc_mp_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
 
-/****f* silcmath/SilcMPAPI/silc_mp_neg
+/****f* silcmath/SilcMPAPI/silc_mp_mod_2exp
  *
  * SYNOPSIS
  *
- *    void silc_mp_neg(SilcMPInt *dst, SilcMPInt *src);
+ *    void silc_mp_mod_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
  *
  * DESCRIPTION
  *
- *    Negate `src' and save the result to `dst'.
+ *    Computes the remainder of `mp1' with 2 ** `exp' and saves the
+ *    result to `dst'. This is equivalent to dst = mp1 mod (2 ^ exp).
+ *    The same result can also be get with silc_mp_div_2exp_qr as that
+ *    function returns the remainder as well.
  *
  ***/
-void silc_mp_neg(SilcMPInt *dst, SilcMPInt *src);
+void silc_mp_mod_2exp(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
 
 /****f* silcmath/SilcMPAPI/silc_mp_pow
  *
@@ -602,6 +519,79 @@ void silc_mp_pow_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 exp,
  ***/
 void silc_mp_modinv(SilcMPInt *inv, SilcMPInt *a, SilcMPInt *n);
 
+/****f* silcmath/SilcMPAPI/silc_mp_gcd
+ *
+ * SYNOPSIS
+ *
+ *    void silc_mp_gcd(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *
+ * DESCRIPTION
+ *
+ *    Calculate the greatest common divisor of the integers `mp1' and `mp2'
+ *    and save the result to `dst'.
+ *
+ ***/
+void silc_mp_gcd(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+
+/****f* silcmath/SilcMPAPI/silc_mp_gcdext
+ *
+ * SYNOPSIS
+ *
+ *    void silc_mp_gcdext(SilcMPInt *g, SilcMPInt *s, SilcMPInt *t, 
+ *                        SilcMPInt *mp1, SilcMPInt *mp2);
+ *
+ * DESCRIPTION
+ *
+ *    Calculate the extended greatest common divisor `g', `s' and `t' such
+ *    that g = mp1 * s + mp2 * + t.
+ *
+ ***/
+void silc_mp_gcdext(SilcMPInt *g, SilcMPInt *s, SilcMPInt *t, SilcMPInt *mp1,
+                   SilcMPInt *mp2);
+
+/****f* silcmath/SilcMPAPI/silc_mp_cmp
+ *
+ * SYNOPSIS
+ *
+ *    int silc_mp_cmp(SilcMPInt *mp1, SilcMPInt *mp2);
+ *
+ * DESCRIPTION
+ *
+ *    Compare `mp1' and `mp2'. Returns posivite, zero, or negative
+ *    if `mp1' > `mp2', `mp1' == `mp2', or `mp1' < `mp2', respectively.
+ *
+ ***/
+int silc_mp_cmp(SilcMPInt *mp1, SilcMPInt *mp2);
+
+/****f* silcmath/SilcMPAPI/silc_mp_cmp_si
+ *
+ * SYNOPSIS
+ *
+ *    int silc_mp_cmp_si(SilcMPInt *mp1, int32 si);
+ *
+ * DESCRIPTION
+ *
+ *    Compare `mp1' and single word `si'. Returns posivite, zero, or negative
+ *    if `mp1' > `si', `mp1' == `si', or `mp1' < `si', respectively.
+ *
+ ***/
+int silc_mp_cmp_si(SilcMPInt *mp1, int32 si);
+
+/****f* silcmath/SilcMPAPI/silc_mp_cmp_ui
+ *
+ * SYNOPSIS
+ *
+ *    int silc_mp_cmp_ui(SilcMPInt *mp1, uint32 ui);
+ *
+ * DESCRIPTION
+ *
+ *    Compare `mp1' and unsigned word `ui'. Returns posivite, zero, or 
+ *    negative if `mp1' > `ui', `mp1' == `ui', or `mp1' < `ui', 
+ *    respectively.
+ *
+ ***/
+int silc_mp_cmp_ui(SilcMPInt *mp1, uint32 ui);
+
 /****f* silcmath/SilcMPAPI/silc_mp_mp2bin
  *
  * SYNOPSIS
@@ -616,13 +606,14 @@ void silc_mp_modinv(SilcMPInt *inv, SilcMPInt *a, SilcMPInt *n);
  *    buffer is allocated that large. If zero then the size is approximated.
  *
  ***/
-unsigned char *silc_mp_mp2bin(SilcMPInt *val, uint32 len, uint32 *ret_len);
+unsigned char *silc_mp_mp2bin(SilcMPInt *val, uint32 len, 
+                             uint32 *ret_len);
 
 /****f* silcmath/SilcMPAPI/silc_mp_mp2bin_noalloc
  *
  * SYNOPSIS
  *
- *    void silc_mp_mp2bin_noalloc(SilcMPInt val, unsigned char *dst,
+ *    void silc_mp_mp2bin_noalloc(SilcMPInt *val, unsigned char *dst,
  *                                uint32 dst_len);
  *
  * DESCRIPTION
@@ -631,14 +622,15 @@ unsigned char *silc_mp_mp2bin(SilcMPInt *val, uint32 len, uint32 *ret_len);
  *    encoded data is returned into `dst' and it's length to the `ret_len'.
  *
  ***/
-void silc_mp_mp2bin_noalloc(SilcMPInt val, unsigned char *dst,
+void silc_mp_mp2bin_noalloc(SilcMPInt *val, unsigned char *dst,
                            uint32 dst_len);
 
 /****f* silcmath/SilcMPAPI/silc_mp_bin2mp
  *
  * SYNOPSIS
  *
- *    void silc_mp_bin2mp(unsigned char *data, uint32 len, SilcMPInt *ret);
+ *    void silc_mp_bin2mp(unsigned char *data, uint32 len, 
+ *                        SilcMPInt *ret);
  *
  * DESCRIPTION
  *
@@ -648,30 +640,69 @@ void silc_mp_mp2bin_noalloc(SilcMPInt val, unsigned char *dst,
  ***/
 void silc_mp_bin2mp(unsigned char *data, uint32 len, SilcMPInt *ret);
 
-/****f* silcmath/SilcMPAPI/silc_mp_set
+/****f* silcmath/SilcMPAPI/silc_mp_abs
  *
  * SYNOPSIS
  *
- *    void silc_mp_set(SilcMPInt *dst, SilcMPInt *src);
+ *    void silc_mp_abs(SilcMPInt *src, SilcMPInt *dst);
  *
  * DESCRIPTION
  *
- *    Set `dst' integer from `src' integer.
+ *    Assign the absolute value of `src' to `dst'.
  *
  ***/
-void silc_mp_set(SilcMPInt *dst, SilcMPInt *src);
+void silc_mp_abs(SilcMPInt *dst, SilcMPInt *src);
 
-void silc_mp_set_ui(SilcMPInt *dst, uint32 ui);
-void silc_mp_set_ui64(SilcMPInt *dst, uint64 ui);
-void silc_mp_set_si(SilcMPInt *dst, uint32 ui);
-void silc_mp_set_si64(SilcMPInt *dst, uint64 ui);
-void silc_mp_set_str(SilcMPInt *dst, const char *str, int base);
-size_t silc_mp_size(SilcMPInt *mp);
-size_t silc_mp_sizeinbase(SilcMPInt *mp, int base);
-void silc_mp_sqrt(SilcMPInt *dst, SilcMPInt *src);
-void silc_mp_sub(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
-void silc_mp_sub_ui(SilcMPInt *dst, SilcMPInt *mp1, uint32 ui);
+/****f* silcmath/SilcMPAPI/silc_mp_neg
+ *
+ * SYNOPSIS
+ *
+ *    void silc_mp_neg(SilcMPInt *dst, SilcMPInt *src);
+ *
+ * DESCRIPTION
+ *
+ *    Negate `src' and save the result to `dst'.
+ *
+ ***/
+void silc_mp_neg(SilcMPInt *dst, SilcMPInt *src);
+
+/****f* silcmath/SilcMPAPI/silc_mp_and
+ *
+ * SYNOPSIS
+ *
+ *    void silc_mp_and(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *
+ * DESCRIPTION
+ *
+ *    Logical and operator. The result is saved to `dst'.
+ *
+ ***/
+void silc_mp_and(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
 
-#endif /* 1 */
+/****f* silcmath/SilcMPAPI/silc_mp_or
+ *
+ * SYNOPSIS
+ *
+ *    void silc_mp_or(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *
+ * DESCRIPTION
+ *
+ *    Logical inclusive OR operator. The result is saved to `dst'.
+ *
+ ***/
+void silc_mp_or(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+
+/****f* silcmath/SilcMPAPI/silc_mp_or
+ *
+ * SYNOPSIS
+ *
+ *    void silc_mp_xor(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
+ *
+ * DESCRIPTION
+ *
+ *    Logical exclusive OR operator. The result is saved to `dst'.
+ *
+ ***/
+void silc_mp_xor(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
 
 #endif
index beb07f285f87ea09d3cba6d34638a4f66c9682ce..e868637c66fbb99df9d0ced69a24b72564e4c5dd 100644 (file)
@@ -195,19 +195,21 @@ static uint32 primetable[] =
    If argument verbose is TRUE this will display some status information
    about the progress of generation. */
 
-int silc_math_gen_prime(SilcInt *prime, uint32 bits, int verbose)
+int silc_math_gen_prime(SilcMPInt *prime, uint32 bits, int verbose)
 {
   unsigned char *numbuf;
   uint32 i, b, k;
   uint32 *spmods;
-  SilcInt r, base, tmp, tmp2, oprime;
+  SilcMPInt r, base, tmp, tmp2, oprime;
 
   silc_mp_init(&r);
-  silc_mp_init_set_ui(&base, 2);
+  silc_mp_init(&base);
   silc_mp_init(&tmp);
   silc_mp_init(&tmp2);
   silc_mp_init(&oprime);
 
+  silc_mp_set_ui(&base, 2);
+
   SILC_LOG_DEBUG(("Generating new prime"));
 
   /* Get random number */
@@ -225,7 +227,7 @@ int silc_math_gen_prime(SilcInt *prime, uint32 bits, int verbose)
 
   /* Number could be even number, so we'll make it odd. */
   silc_mp_set_ui(&tmp, 1);
-  silc_mp_ior(prime, prime, &tmp);             /* OR operator */
+  silc_mp_or(prime, prime, &tmp);              /* OR operator */
 
   /* Init modulo table with the prime candidate and the primes
      in the primetable. */
@@ -263,7 +265,7 @@ int silc_math_gen_prime(SilcInt *prime, uint32 bits, int verbose)
     /* Does the prime pass the Fermat's prime test.
      * r = 2 ^ p mod p, if r == 2, then p is probably a prime. 
      */
-    silc_mp_powm(&r, &base, &oprime, &oprime);
+    silc_mp_pow_mod(&r, &base, &oprime, &oprime);
     if (silc_mp_cmp_ui(&r, 2) != 0) {
       if (verbose) {
        printf(".");
@@ -289,11 +291,11 @@ int silc_math_gen_prime(SilcInt *prime, uint32 bits, int verbose)
   }
 
   silc_free(spmods);
-  silc_mp_clear(&r);
-  silc_mp_clear(&base);
-  silc_mp_clear(&tmp);
-  silc_mp_clear(&tmp2);
-  silc_mp_clear(&oprime);
+  silc_mp_uninit(&r);
+  silc_mp_uninit(&base);
+  silc_mp_uninit(&tmp);
+  silc_mp_uninit(&tmp2);
+  silc_mp_uninit(&oprime);
 
   return TRUE;
 }
@@ -301,14 +303,15 @@ int silc_math_gen_prime(SilcInt *prime, uint32 bits, int verbose)
 /* Performs primality testings for given number. Returns TRUE if the 
    number is probably a prime. */
 
-int silc_math_prime_test(SilcInt *p)
+int silc_math_prime_test(SilcMPInt *p)
 {
-  SilcInt r, base, tmp;
+  SilcMPInt r, base, tmp;
   int i, ret = 0;
   
   silc_mp_init(&r);
   silc_mp_init(&tmp);
-  silc_mp_init_set_ui(&base, 2);
+  silc_mp_init(&base);
+  silc_mp_set_ui(&base, 2);
   
   SILC_LOG_DEBUG(("Testing probability of prime"));
 
@@ -325,13 +328,13 @@ int silc_math_prime_test(SilcInt *p)
   /* Does the prime pass the Fermat's prime test.
    * r = 2 ^ p mod p, if r == 2, then p is probably a prime.
    */
-  silc_mp_powm(&r, &base, p, p);
+  silc_mp_pow_mod(&r, &base, p, p);
   if (silc_mp_cmp_ui(&r, 2) != 0)
     ret = -1;
 
-  silc_mp_clear(&r);
-  silc_mp_clear(&tmp);
-  silc_mp_clear(&base);
+  silc_mp_uninit(&r);
+  silc_mp_uninit(&tmp);
+  silc_mp_uninit(&base);
   
   if (ret)
     return FALSE;
index fd664a06129ba0032099252e26e5fabd99cfaf31..20cba0c01ea3f61c9a703d45a55de11d67651d34 100644 (file)
@@ -30,41 +30,41 @@ const struct SilcSKEDiffieHellmanGroupDefStruct silc_ske_groups[] =
   /* 1024 bits modulus (Mandatory group) */
   { 1, "diffie-hellman-group1",
     "0x"
-    "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1"
-    "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD"
-    "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245"
-    "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED"
-    "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE65381"
-    "FFFFFFFF FFFFFFFF",
+    "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
+    "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
+    "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
+    "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
+    "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381"
+    "FFFFFFFFFFFFFFFF",
     "0x"
-    "7FFFFFFF FFFFFFFF E487ED51 10B4611A 62633145 C06E0E68"
-    "94812704 4533E63A 0105DF53 1D89CD91 28A5043C C71A026E"
-    "F7CA8CD9 E69D218D 98158536 F92F8A1B A7F09AB6 B6A8E122"
-    "F242DABB 312F3F63 7A262174 D31BF6B5 85FFAE5B 7A035BF6"
-    "F71C35FD AD44CFD2 D74F9208 BE258FF3 24943328 F67329C0"
-    "FFFFFFFF FFFFFFFF",
+    "7FFFFFFFFFFFFFFFE487ED5110B4611A62633145C06E0E68"
+    "948127044533E63A0105DF531D89CD9128A5043CC71A026E"
+    "F7CA8CD9E69D218D98158536F92F8A1BA7F09AB6B6A8E122"
+    "F242DABB312F3F637A262174D31BF6B585FFAE5B7A035BF6"
+    "F71C35FDAD44CFD2D74F9208BE258FF324943328F67329C0"
+    "FFFFFFFFFFFFFFFF",
     "0x2" },
 
   /* 1536 bits modulus (Optional group) */
   { 2, "diffie-hellman-group2",
     "0x"
-    "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1"
-    "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD"
-    "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245"
-    "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED"
-    "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D"
-    "C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F"
-    "83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D"
-    "670C354E 4ABC9804 F1746C08 CA237327 FFFFFFFF FFFFFFFF",
+    "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
+    "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
+    "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
+    "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
+    "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"
+    "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"
+    "83655D23DCA3AD961C62F356208552BB9ED529077096966D"
+    "670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF",
     "0x"
-    "7FFFFFFF FFFFFFFF E487ED51 10B4611A 62633145 C06E0E68"
-    "94812704 4533E63A 0105DF53 1D89CD91 28A5043C C71A026E"
-    "F7CA8CD9 E69D218D 98158536 F92F8A1B A7F09AB6 B6A8E122"
-    "F242DABB 312F3F63 7A262174 D31BF6B5 85FFAE5B 7A035BF6"
-    "F71C35FD AD44CFD2 D74F9208 BE258FF3 24943328 F6722D9E"
-    "E1003E5C 50B1DF82 CC6D241B 0E2AE9CD 348B1FD4 7E9267AF"
-    "C1B2AE91 EE51D6CB 0E3179AB 1042A95D CF6A9483 B84B4B36"
-    "B3861AA7 255E4C02 78BA3604 6511B993 FFFFFFFF FFFFFFFF",
+    "7FFFFFFFFFFFFFFFE487ED5110B4611A62633145C06E0E68"
+    "948127044533E63A0105DF531D89CD9128A5043CC71A026E"
+    "F7CA8CD9E69D218D98158536F92F8A1BA7F09AB6B6A8E122"
+    "F242DABB312F3F637A262174D31BF6B585FFAE5B7A035BF6"
+    "F71C35FDAD44CFD2D74F9208BE258FF324943328F6722D9E"
+    "E1003E5C50B1DF82CC6D241B0E2AE9CD348B1FD47E9267AF"
+    "C1B2AE91EE51D6CB0E3179AB1042A95DCF6A9483B84B4B36"
+    "B3861AA7255E4C0278BA36046511B993FFFFFFFFFFFFFFFF",
     "0x2" },
 
   { 0, NULL, NULL, NULL }
@@ -94,9 +94,9 @@ SilcSKEStatus silc_ske_get_group_by_number(int number,
     silc_mp_init(&group->group);
     silc_mp_init(&group->group_order);
     silc_mp_init(&group->generator);
-    silc_mp_set_str(&group->group, silc_ske_groups[i].group, 0);
-    silc_mp_set_str(&group->group_order, silc_ske_groups[i].group_order, 0);
-    silc_mp_set_str(&group->generator, silc_ske_groups[i].generator, 0);
+    silc_mp_set_str(&group->group, silc_ske_groups[i].group, 16);
+    silc_mp_set_str(&group->group_order, silc_ske_groups[i].group_order, 16);
+    silc_mp_set_str(&group->generator, silc_ske_groups[i].generator, 16);
     
     *ret = group;
   }
@@ -128,9 +128,9 @@ SilcSKEStatus silc_ske_get_group_by_name(const char *name,
     silc_mp_init(&group->group);
     silc_mp_init(&group->group_order);
     silc_mp_init(&group->generator);
-    silc_mp_set_str(&group->group, silc_ske_groups[i].group, 0);
-    silc_mp_set_str(&group->group_order, silc_ske_groups[i].group_order, 0);
-    silc_mp_set_str(&group->generator, silc_ske_groups[i].generator, 0);
+    silc_mp_set_str(&group->group, silc_ske_groups[i].group, 16);
+    silc_mp_set_str(&group->group_order, silc_ske_groups[i].group_order, 16);
+    silc_mp_set_str(&group->generator, silc_ske_groups[i].generator, 16);
     
     *ret = group;
   }
index 015c125eed8cd2911d9d12f9b171bedf4a100380..2651885d77f1249f453877ef1847dd6d5e3948df 100644 (file)
@@ -34,9 +34,9 @@ struct SilcSKEDiffieHellmanGroupDefStruct {
 struct SilcSKEDiffieHellmanGroupStruct {
   int number;
   char *name;
-  SilcInt group;
-  SilcInt group_order;
-  SilcInt generator;
+  SilcMPInt group;
+  SilcMPInt group_order;
+  SilcMPInt generator;
 };
 
 #endif
index 835613ae030e35be58f81522d63eb8b8eff9eb24..0a987e8eedd443e1102e263bb440e16881db7bd6 100644 (file)
@@ -347,7 +347,7 @@ void silc_ske_payload_ke_free(SilcSKEKEPayload *payload)
   if (payload) {
     if (payload->pk_data)
       silc_free(payload->pk_data);
-    silc_mp_clear(&payload->x);
+    silc_mp_uninit(&payload->x);
     if (payload->sign_data)
       silc_free(payload->sign_data);
     silc_free(payload);
index 580919b8fcb088f8362415f6275cc20f58f3fa1c..3312d1ea63b12cb15e17c4e21d09abb4d7df0bc8 100644 (file)
@@ -57,7 +57,7 @@ typedef struct {
   unsigned char *pk_data;
   uint16 pk_type;
 
-  SilcInt x;
+  SilcMPInt x;
 
   uint16 sign_len;
   unsigned char *sign_data;
index e95c57e225761a7ef090da41d409a36f1fd241fd..7d34d61aa2c426e706921c6064fdb51b3bb88bdf 100644 (file)
@@ -71,11 +71,11 @@ void silc_ske_free(SilcSKE ske)
     if (ske->pk)
       silc_free(ske->pk);
     if (ske->x) {
-      silc_mp_clear(ske->x);
+      silc_mp_uninit(ske->x);
       silc_free(ske->x);
     }
     if (ske->KEY) {
-      silc_mp_clear(ske->KEY);
+      silc_mp_uninit(ske->KEY);
       silc_free(ske->KEY);
     }
     if (ske->hash)
@@ -228,7 +228,7 @@ SilcSKEStatus silc_ske_initiator_phase_2(SilcSKE ske,
 {
   SilcSKEStatus status = SILC_SKE_STATUS_OK;
   SilcBuffer payload_buf;
-  SilcInt *x, e;
+  SilcMPInt *x, e;
   SilcSKEKEPayload *payload;
   uint32 pk_len;
 
@@ -242,7 +242,7 @@ SilcSKEStatus silc_ske_initiator_phase_2(SilcSKE ske,
                        silc_mp_sizeinbase(&ske->prop->group->group_order, 2),
                        x);
   if (status != SILC_SKE_STATUS_OK) {
-    silc_mp_clear(x);
+    silc_mp_uninit(x);
     silc_free(x);
     ske->status = status;
     return status;
@@ -252,8 +252,8 @@ SilcSKEStatus silc_ske_initiator_phase_2(SilcSKE ske,
 
   /* Do the Diffie Hellman computation, e = g ^ x mod p */
   silc_mp_init(&e);
-  silc_mp_powm(&e, &ske->prop->group->generator, x, 
-              &ske->prop->group->group);
+  silc_mp_pow_mod(&e, &ske->prop->group->generator, x, 
+                 &ske->prop->group->group);
 
   /* Encode the result to Key Exchange Payload. */
 
@@ -266,9 +266,9 @@ SilcSKEStatus silc_ske_initiator_phase_2(SilcSKE ske,
   if (public_key) {
     payload->pk_data = silc_pkcs_public_key_encode(public_key, &pk_len);
     if (!payload->pk_data) {
-      silc_mp_clear(x);
+      silc_mp_uninit(x);
       silc_free(x);
-      silc_mp_clear(&e);
+      silc_mp_uninit(&e);
       silc_free(payload);
       ske->status = SILC_SKE_STATUS_OK;
       return ske->status;
@@ -303,9 +303,9 @@ SilcSKEStatus silc_ske_initiator_phase_2(SilcSKE ske,
 
   status = silc_ske_payload_ke_encode(ske, payload, &payload_buf);
   if (status != SILC_SKE_STATUS_OK) {
-    silc_mp_clear(x);
+    silc_mp_uninit(x);
     silc_free(x);
-    silc_mp_clear(&e);
+    silc_mp_uninit(&e);
     silc_free(payload->pk_data);
     silc_free(payload);
     ske->status = status;
@@ -413,7 +413,7 @@ static void silc_ske_initiator_finish_final(SilcSKE ske,
   silc_ske_payload_ke_free(payload);
   ske->ke2_payload = NULL;
 
-  silc_mp_clear(ske->KEY);
+  silc_mp_uninit(ske->KEY);
   silc_free(ske->KEY);
   ske->KEY = NULL;
 
@@ -465,7 +465,7 @@ SilcSKEStatus silc_ske_initiator_finish(SilcSKE ske,
 {
   SilcSKEStatus status = SILC_SKE_STATUS_OK;
   SilcSKEKEPayload *payload;
-  SilcInt *KEY;
+  SilcMPInt *KEY;
   SKEInitiatorFinish finish;
 
   SILC_LOG_DEBUG(("Start"));
@@ -490,7 +490,7 @@ SilcSKEStatus silc_ske_initiator_finish(SilcSKE ske,
   /* Compute the shared secret key */
   KEY = silc_calloc(1, sizeof(*KEY));
   silc_mp_init(KEY);
-  silc_mp_powm(KEY, &payload->x, ske->x, &ske->prop->group->group);
+  silc_mp_pow_mod(KEY, &payload->x, ske->x, &ske->prop->group->group);
   ske->KEY = KEY;
 
   finish = silc_calloc(1, sizeof(*finish));
@@ -518,7 +518,7 @@ SilcSKEStatus silc_ske_initiator_finish(SilcSKE ske,
   silc_ske_payload_ke_free(payload);
   ske->ke2_payload = NULL;
 
-  silc_mp_clear(ske->KEY);
+  silc_mp_uninit(ske->KEY);
   silc_free(ske->KEY);
   ske->KEY = NULL;
 
@@ -694,7 +694,7 @@ static void silc_ske_responder_phase2_final(SilcSKE ske,
 {
   SKEResponderPhaseII finish = (SKEResponderPhaseII)context;
   SilcSKEKEPayload *recv_payload, *send_payload;
-  SilcInt *x, f;
+  SilcMPInt *x, f;
 
   recv_payload = ske->ke1_payload;
 
@@ -776,7 +776,7 @@ static void silc_ske_responder_phase2_final(SilcSKE ske,
                        silc_mp_sizeinbase(&ske->prop->group->group_order, 2),
                        x);
   if (status != SILC_SKE_STATUS_OK) {
-    silc_mp_clear(x);
+    silc_mp_uninit(x);
     silc_free(x);
     ske->status = status;
     if (finish->callback)
@@ -789,8 +789,8 @@ static void silc_ske_responder_phase2_final(SilcSKE ske,
 
   /* Do the Diffie Hellman computation, f = g ^ x mod p */
   silc_mp_init(&f);
-  silc_mp_powm(&f, &ske->prop->group->generator, x, 
-              &ske->prop->group->group);
+  silc_mp_pow_mod(&f, &ske->prop->group->generator, x, 
+                 &ske->prop->group->group);
   
   /* Save the results for later processing */
   send_payload = silc_calloc(1, sizeof(*send_payload));
@@ -896,7 +896,7 @@ SilcSKEStatus silc_ske_responder_finish(SilcSKE ske,
 {
   SilcSKEStatus status = SILC_SKE_STATUS_OK;
   SilcBuffer payload_buf;
-  SilcInt *KEY;
+  SilcMPInt *KEY;
   unsigned char hash[32], sign[1024], *pk;
   uint32 hash_len, sign_len, pk_len;
 
@@ -907,8 +907,8 @@ SilcSKEStatus silc_ske_responder_finish(SilcSKE ske,
   /* Compute the shared secret key */
   KEY = silc_calloc(1, sizeof(*KEY));
   silc_mp_init(KEY);
-  silc_mp_powm(KEY, &ske->ke1_payload->x, ske->x, 
-              &ske->prop->group->group);
+  silc_mp_pow_mod(KEY, &ske->ke1_payload->x, ske->x, 
+                 &ske->prop->group->group);
   ske->KEY = KEY;
 
   if (public_key && private_key) {
@@ -963,7 +963,7 @@ SilcSKEStatus silc_ske_responder_finish(SilcSKE ske,
   return status;
 
  err:
-  silc_mp_clear(ske->KEY);
+  silc_mp_uninit(ske->KEY);
   silc_free(ske->KEY);
   ske->KEY = NULL;
   silc_ske_payload_ke_free(ske->ke2_payload);
@@ -1460,9 +1460,9 @@ silc_ske_select_security_properties(SilcSKE ske,
 /* Creates random number such that 1 < rnd < n and at most length
    of len bits. The rnd sent as argument must be initialized. */
 
-SilcSKEStatus silc_ske_create_rnd(SilcSKE ske, SilcInt n, 
+SilcSKEStatus silc_ske_create_rnd(SilcSKE ske, SilcMPInt n, 
                                  uint32 len, 
-                                 SilcInt *rnd)
+                                 SilcMPInt *rnd)
 {
   SilcSKEStatus status = SILC_SKE_STATUS_OK;
   unsigned char *string;
index 1828d10fd49b5e31dd52124f070e29966df2ebb4..14620c71a0635ddd4b9b8e5b6c60ef592b680405 100644 (file)
@@ -141,10 +141,10 @@ struct SilcSKEStruct {
 
   /* Random number x, 1 < x < q. This is the secret exponent
      used in Diffie Hellman computations. */
-  SilcInt *x;
+  SilcMPInt *x;
   
   /* The secret shared key */
-  SilcInt *KEY;
+  SilcMPInt *KEY;
   
   /* The hash value HASH of the key exchange */
   unsigned char *hash;
@@ -224,9 +224,9 @@ silc_ske_select_security_properties(SilcSKE ske,
                                    char *version,
                                    SilcSKEStartPayload *payload,
                                    SilcSKEStartPayload *remote_payload);
-SilcSKEStatus silc_ske_create_rnd(SilcSKE ske, SilcInt n, 
+SilcSKEStatus silc_ske_create_rnd(SilcSKE ske, SilcMPInt n, 
                                  uint32 len, 
-                                 SilcInt *rnd);
+                                 SilcMPInt *rnd);
 SilcSKEStatus silc_ske_make_hash(SilcSKE ske, 
                                 unsigned char *return_hash,
                                 uint32 *return_hash_len,