X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcmath%2Fmpbin.c;h=29d80f7711e71e007b2ddb8d20dde27fd766cd9d;hb=a818c5b5411bbc4436d1c5f011236985c96bb787;hp=8b598aa1a1f4759196ee96291b3510cd95dcba27;hpb=04f41c4481381e8e7c1e685a4edb6be6ec5d2c66;p=silc.git diff --git a/lib/silcmath/mpbin.c b/lib/silcmath/mpbin.c index 8b598aa1..29d80f77 100644 --- a/lib/silcmath/mpbin.c +++ b/lib/silcmath/mpbin.c @@ -25,25 +25,26 @@ 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, unsigned int len, - unsigned int *ret_len) +unsigned char *silc_mp_mp2bin(SilcMPInt *val, SilcUInt32 len, + SilcUInt32 *ret_len) { int i; - unsigned int size; + SilcUInt32 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; @@ -52,30 +53,30 @@ unsigned char *silc_mp_mp2bin(SilcInt *val, unsigned int 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'. If `dst_len is - non-zero then the destination buffer is assumbed to be that large. */ + returned into `dst' and it's length to the `ret_len'. */ -void silc_mp_mp2bin_noalloc(SilcInt *val, unsigned char *dst, - unsigned int dst_len) +void silc_mp_mp2bin_noalloc(SilcMPInt *val, unsigned char *dst, + SilcUInt32 dst_len) { int i; - unsigned int size = dst_len; - SilcInt tmp; + SilcUInt32 size = dst_len; + 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, unsigned int len, SilcInt *ret) +void silc_mp_bin2mp(unsigned char *data, SilcUInt32 len, SilcMPInt *ret) { int i;