Fixed MPI implementation of silc_mp_sizeinbase to return size
authorPekka Riikonen <priikone@silcnet.org>
Sun, 17 Nov 2002 13:58:06 +0000 (13:58 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 17 Nov 2002 13:58:06 +0000 (13:58 +0000)
correctly for interger smaller than <32 bit.

lib/silccrypt/rsa.c
lib/silcmath/mp_mpi.c
lib/silcske/silcske.c
lib/silcutil/silcconfig.h

index 2c94f29a0dd39ee185a7f6098ec0b1f4f20b55ef..202ccf3ffd16759079a849d6bc9e3803d3a3dfa8 100644 (file)
@@ -241,7 +241,7 @@ SILC_PKCS_API_SET_PUBLIC_KEY(rsa)
 
   memcpy(tmp, key_data, 4);
   SILC_GET32_MSB(e_len, tmp);
-  if (e_len > key_len) {
+  if (!e_len || e_len > key_len) {
     silc_mp_uninit(&key->e);
     silc_mp_uninit(&key->n);
     return 0;
@@ -251,7 +251,7 @@ 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) {
+  if (!n_len || e_len + n_len > key_len) {
     silc_mp_uninit(&key->e);
     silc_mp_uninit(&key->n);
     return 0;
index 3a893d7bdb2b6e82d1f5591f967cdf2be6f82afe..8ef0a40b5100e11ea8cfcecb3dfa6d0b974b1523 100644 (file)
@@ -39,13 +39,11 @@ size_t silc_mp_size(SilcMPInt *mp)
 
 size_t silc_mp_sizeinbase(SilcMPInt *mp, int base)
 {
-  size_t sib = mp_radix_size(mp, base);
+  size_t sib = mp_unsigned_octet_size(mp);
+  sib = s_mp_outlen(sib * CHAR_BIT, base);
   if (sib > 2)
-    sib -= 2;                  /* XXX This is actually wrong since
-                                  this might produce wrong balue.
-                                  But, it looks like MPI always returns
-                                  correct value plus one, whereas
-                                  GMP returns always the right value. */
+    sib -= 2;                  /* Looks like MPI returns extra zero
+                                  bytes for C-strings. */
   return sib;
 }
 
index 604d92093b44fa54787b1c8204aa9bc4ff1af266..547ffb66ef3e2f14993067f61a5f8961f9283aa8 100644 (file)
@@ -1597,18 +1597,17 @@ static SilcSKEStatus silc_ske_create_rnd(SilcSKE ske, SilcMPInt *n,
   SILC_LOG_DEBUG(("Creating random number"));
 
   /* Get the random number as string */
-  string = silc_rng_get_rn_data(ske->rng, (len / 8));
+  string = silc_rng_get_rn_data(ske->rng, ((len - 1) / 8));
   if (!string)
     return SILC_SKE_STATUS_OUT_OF_MEMORY;
 
   /* Decode the string into a MP integer */
-  silc_mp_bin2mp(string, (len / 8), rnd);
+  silc_mp_bin2mp(string, ((len - 1) / 8), rnd);
   silc_mp_mod_2exp(rnd, rnd, len);
 
   /* Checks */
   if (silc_mp_cmp_ui(rnd, 1) < 0)
     status = SILC_SKE_STATUS_ERROR;
-
   if (silc_mp_cmp(rnd, n) >= 0)
     status = SILC_SKE_STATUS_ERROR;
 
index 4d581f5c8795d577c990855159b1e1aa6e3caf8c..91225867c716fd5c34a01ba053b39d61a6e6e6de 100644 (file)
@@ -144,7 +144,8 @@ typedef enum {
  * SYNOPSIS
  *
  *    typedef int (*SilcConfigCallback)(SilcConfigType type, const char *name,
- *                                      SilcUInt32 line, void *val, void *context);
+ *                                      SilcUInt32 line, void *val,
+ *                                      void *context);
  * DESCRIPTION
  *
  *    This is the callback prototype for the options handler.  The pointer
@@ -207,7 +208,7 @@ typedef struct SilcConfigTableStruct {
  *
  * SYNOPSIS
  *
- *    typedef struct { ... } SilcConfigFile;
+ *    typedef struct SilcConfigFileObject SilcConfigFile;
  *
  * DESCRIPTION
  *
@@ -223,7 +224,7 @@ typedef struct SilcConfigFileObject SilcConfigFile;
  *
  * SYNOPSIS
  *
- *    typedef struct { ... } SilcConfigEntity;
+ *    typedef struct SilcConfigEntityObject *SilcConfigEntity;
  *
  * DESCRIPTION
  *