commit 5ad4f5a22f4cbd04c53c9ca43800397747147922
parent 1c36293fb92d83bd6f0d7a9e945f923f10c8a60a
Author: Andres Navarro <canavarro82@gmail.com>
Date: Tue, 12 Apr 2011 15:01:30 -0300
Added klisp_State parameter to mp_int_to_binary/read_binary/to_unsigned/read_unsigned.
Diffstat:
2 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/src/imath.c b/src/imath.c
@@ -2033,7 +2033,8 @@ mp_result mp_int_count_bits(mp_int z)
/* {{{ mp_int_to_binary(z, buf, limit) */
-mp_result mp_int_to_binary(mp_int z, unsigned char *buf, int limit)
+mp_result mp_int_to_binary(klisp_State *K, mp_int z, unsigned char *buf,
+ int limit)
{
static const int PAD_FOR_2C = 1;
@@ -2054,7 +2055,8 @@ mp_result mp_int_to_binary(mp_int z, unsigned char *buf, int limit)
/* {{{ mp_int_read_binary(z, buf, len) */
-mp_result mp_int_read_binary(mp_int z, unsigned char *buf, int len)
+mp_result mp_int_read_binary(klisp_State *K, mp_int z, unsigned char *buf,
+ int len)
{
mp_size need, i;
unsigned char *tmp;
@@ -2064,7 +2066,7 @@ mp_result mp_int_read_binary(mp_int z, unsigned char *buf, int len)
/* Figure out how many digits are needed to represent this value */
need = ((len * CHAR_BIT) + (MP_DIGIT_BIT - 1)) / MP_DIGIT_BIT;
- if(!s_pad(KK, z, need))
+ if(!s_pad(K, z, need))
return MP_MEMORY;
mp_int_zero(z);
@@ -2078,7 +2080,7 @@ mp_result mp_int_read_binary(mp_int z, unsigned char *buf, int len)
dz = MP_DIGITS(z);
for(tmp = buf, i = len; i > 0; --i, ++tmp) {
- s_qmul(KK, z, (mp_size) CHAR_BIT);
+ s_qmul(K, z, (mp_size) CHAR_BIT);
*dz |= *tmp;
}
@@ -2116,7 +2118,8 @@ mp_result mp_int_binary_len(mp_int z)
/* {{{ mp_int_to_unsigned(z, buf, limit) */
-mp_result mp_int_to_unsigned(mp_int z, unsigned char *buf, int limit)
+mp_result mp_int_to_unsigned(klisp_State *K, mp_int z, unsigned char *buf,
+ int limit)
{
static const int NO_PADDING = 0;
@@ -2129,7 +2132,7 @@ mp_result mp_int_to_unsigned(mp_int z, unsigned char *buf, int limit)
/* {{{ mp_int_read_unsigned(z, buf, len) */
-mp_result mp_int_read_unsigned(mp_int z, unsigned char *buf, int len)
+mp_result mp_int_read_unsigned(klisp_State *K, mp_int z, unsigned char *buf, int len)
{
mp_size need, i;
unsigned char *tmp;
@@ -2139,14 +2142,14 @@ mp_result mp_int_read_unsigned(mp_int z, unsigned char *buf, int len)
/* Figure out how many digits are needed to represent this value */
need = ((len * CHAR_BIT) + (MP_DIGIT_BIT - 1)) / MP_DIGIT_BIT;
- if(!s_pad(KK, z, need))
+ if(!s_pad(K, z, need))
return MP_MEMORY;
mp_int_zero(z);
dz = MP_DIGITS(z);
for(tmp = buf, i = len; i > 0; --i, ++tmp) {
- (void) s_qmul(KK, z, CHAR_BIT);
+ (void) s_qmul(K, z, CHAR_BIT);
*dz |= *tmp;
}
diff --git a/src/imath.h b/src/imath.h
@@ -266,24 +266,31 @@ mp_result mp_int_read_cstring(klisp_State *K, mp_int z, mp_size radix,
mp_result mp_int_count_bits(mp_int z);
/* Convert z to two's complement binary, writing at most limit bytes */
-mp_result mp_int_to_binary(mp_int z, unsigned char *buf, int limit);
+mp_result mp_int_to_binary(klisp_State *K, mp_int z, unsigned char *buf,
+ int limit);
/* Read a two's complement binary value into z from the given buffer */
-mp_result mp_int_read_binary(mp_int z, unsigned char *buf, int len);
+mp_result mp_int_read_binary(klisp_State *K, mp_int z, unsigned char *buf,
+ int len);
/* Return the number of bytes required to represent z in binary. */
+/* NOTE: this doesn't use the allocator */
mp_result mp_int_binary_len(mp_int z);
/* Convert z to unsigned binary, writing at most limit bytes */
-mp_result mp_int_to_unsigned(mp_int z, unsigned char *buf, int limit);
+mp_result mp_int_to_unsigned(klisp_State *K, mp_int z, unsigned char *buf,
+ int limit);
/* Read an unsigned binary value into z from the given buffer */
-mp_result mp_int_read_unsigned(mp_int z, unsigned char *buf, int len);
+mp_result mp_int_read_unsigned(klisp_State *K, mp_int z, unsigned char *buf,
+ int len);
/* Return the number of bytes required to represent z as unsigned output */
+/* NOTE: this doesn't use the allocator */
mp_result mp_int_unsigned_len(mp_int z);
/* Return a statically allocated string describing error code res */
+/* NOTE: this doesn't use the allocator */
const char *mp_error_string(mp_result res);
#if DEBUG