From c5032a2269df2ef9daf57f27f36e42d0df313f69 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sun, 17 Nov 2002 13:58:06 +0000 Subject: [PATCH] Fixed MPI implementation of silc_mp_sizeinbase to return size correctly for interger smaller than <32 bit. --- lib/silccrypt/rsa.c | 4 ++-- lib/silcmath/mp_mpi.c | 10 ++++------ lib/silcske/silcske.c | 5 ++--- lib/silcutil/silcconfig.h | 7 ++++--- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/silccrypt/rsa.c b/lib/silccrypt/rsa.c index 2c94f29a..202ccf3f 100644 --- a/lib/silccrypt/rsa.c +++ b/lib/silccrypt/rsa.c @@ -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; diff --git a/lib/silcmath/mp_mpi.c b/lib/silcmath/mp_mpi.c index 3a893d7b..8ef0a40b 100644 --- a/lib/silcmath/mp_mpi.c +++ b/lib/silcmath/mp_mpi.c @@ -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; } diff --git a/lib/silcske/silcske.c b/lib/silcske/silcske.c index 604d9209..547ffb66 100644 --- a/lib/silcske/silcske.c +++ b/lib/silcske/silcske.c @@ -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; diff --git a/lib/silcutil/silcconfig.h b/lib/silcutil/silcconfig.h index 4d581f5c..91225867 100644 --- a/lib/silcutil/silcconfig.h +++ b/lib/silcutil/silcconfig.h @@ -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 * -- 2.24.0