projects
/
silc.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added SILC Thread Queue API
[silc.git]
/
lib
/
silcmath
/
mpbin.c
diff --git
a/lib/silcmath/mpbin.c
b/lib/silcmath/mpbin.c
index 8b598aa1a1f4759196ee96291b3510cd95dcba27..ea3070e58485500b58b34db8f2a833b98469e58b 100644
(file)
--- a/
lib/silcmath/mpbin.c
+++ b/
lib/silcmath/mpbin.c
@@
-2,15
+2,14
@@
mpbin.c
mpbin.c
- Author: Pekka Riikonen <priikone@
poseidon.pspt.fi
>
+ Author: Pekka Riikonen <priikone@
silcnet.org
>
- Copyright (C) 2000 - 200
1
Pekka Riikonen
+ Copyright (C) 2000 - 200
5
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
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.
-
+ the Free Software Foundation; version 2 of the License.
+
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
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
@@
-19,31
+18,24
@@
*/
/* $Id$ */
*/
/* $Id$ */
-#include "silc
includes
.h"
+#include "silc.h"
/* Encodes MP integer into binary data. Returns allocated data that
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. */
/* Encodes MP integer into binary data. Returns allocated data that
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(Silc
Int *val, unsigned int
len,
-
unsigned int
*ret_len)
+unsigned char *silc_mp_mp2bin(Silc
MPInt *val, SilcUInt32
len,
+
SilcUInt32
*ret_len)
{
{
- int i;
- unsigned int size;
+ SilcUInt32 size;
unsigned char *ret;
unsigned char *ret;
- SilcInt tmp;
size = (len ? len : ((silc_mp_sizeinbase(val, 2) + 7) / 8));
ret = silc_calloc(size, sizeof(*ret));
size = (len ? len : ((silc_mp_sizeinbase(val, 2) + 7) / 8));
ret = silc_calloc(size, sizeof(*ret));
-
- silc_mp_init_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);
- }
+ if (!ret)
+ return NULL;
- silc_mp_
clear(&tmp
);
+ silc_mp_
mp2bin_noalloc(val, ret, size
);
if (ret_len)
*ret_len = size;
if (ret_len)
*ret_len = size;
@@
-52,30
+44,30
@@
unsigned char *silc_mp_mp2bin(SilcInt *val, unsigned int len,
}
/* Samve as above but does not allocate any memory. The encoded data is
}
/* 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(Silc
MP
Int *val, unsigned char *dst,
+
SilcUInt32
dst_len)
{
int i;
{
int i;
-
unsigned int
size = dst_len;
- SilcInt tmp;
+
SilcUInt32
size = dst_len;
+ Silc
MP
Int 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);
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. */
}
/* Decodes binary data into MP integer. The integer sent as argument
must be initialized. */
-void silc_mp_bin2mp(unsigned char *data,
unsigned int len, Silc
Int *ret)
+void silc_mp_bin2mp(unsigned char *data,
SilcUInt32 len, SilcMP
Int *ret)
{
int i;
{
int i;