Skip to content

Commit 13227bf

Browse files
committed
changed small pow to bigint version temporarily
1 parent 672fd29 commit 13227bf

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

demo/test.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,15 +1013,15 @@ static int test_mp_montgomery_reduce(void)
10131013
}
10141014

10151015
const uint8_t test_s_mp_radix_exponent_y[] = { 0, 0, /* 0 .. 1*/
1016-
20, 12, 10, 8, 7, 7, 6, 6, /* 2 .. 9 */
1017-
6, 5, 5, 5, 5, 5, 5, 4, /* 10 .. 17 */
1018-
4, 4, 4, 4, 4, 4, 4, 4, /* 18 .. 25 */
1019-
4, 4, 4, 4, 4, 4, 4, 3, /* 26 .. 33 */
1020-
3, 3, 3, 3, 3, 3, 3, 3, /* 34 .. 41 */
1021-
3, 3, 3, 3, 3, 3, 3, 3, /* 42 .. 49 */
1022-
3, 3, 3, 3, 3, 3, 3, 3, /* 51 .. 57 */
1023-
3, 3, 3, 3, 3, 3, 3 /* 58 .. 64 */
1024-
};
1016+
20, 12, 10, 8, 7, 7, 6, 6, /* 2 .. 9 */
1017+
6, 5, 5, 5, 5, 5, 5, 4, /* 10 .. 17 */
1018+
4, 4, 4, 4, 4, 4, 4, 4, /* 18 .. 25 */
1019+
4, 4, 4, 4, 4, 4, 4, 3, /* 26 .. 33 */
1020+
3, 3, 3, 3, 3, 3, 3, 3, /* 34 .. 41 */
1021+
3, 3, 3, 3, 3, 3, 3, 3, /* 42 .. 49 */
1022+
3, 3, 3, 3, 3, 3, 3, 3, /* 51 .. 57 */
1023+
3, 3, 3, 3, 3, 3, 3 /* 58 .. 64 */
1024+
};
10251025

10261026
static int test_mp_read_radix(void)
10271027
{

s_mp_faster_to_radix.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ static int32_t s_floor_ilog2(int32_t value)
1414
}
1515

1616
/* Exponentiation with small footprint */
17+
/*
1718
static int32_t s_pow(int32_t base, int32_t exponent)
1819
{
1920
int32_t result = 1;
@@ -26,7 +27,7 @@ static int32_t s_pow(int32_t base, int32_t exponent)
2627
}
2728
return result;
2829
}
29-
30+
*/
3031
static mp_err s_mp_to_radix_recursive(const mp_int *a, char **str, size_t *part_maxlen, size_t *part_written,
3132
int radix, int32_t k, int32_t t, bool pad, mp_int *P, mp_int *R)
3233
{
@@ -100,13 +101,20 @@ mp_err s_mp_faster_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *w
100101
size_t part_written = 0;
101102
size_t part_maxlen = maxlen;
102103

104+
mp_int N;
105+
103106
/* List of reciprocals */
104107
mp_int *R = NULL;
105108
/* List of moduli */
106109
mp_int *P = NULL;
107110

108111
/* Denominator for the reciprocal: b^y */
109-
n = s_pow((int32_t)radix, (int32_t)s_mp_radix_exponent_y[radix]);
112+
/*n = s_pow((int32_t)radix, (int32_t)s_mp_radix_exponent_y[radix]);*/
113+
/* FIXME: either do it full in bigint or fix the problem with the sanitizer */
114+
if ((err = mp_init_i32(&N,(int32_t)radix)) != MP_OKAY) goto LTM_ERR;
115+
if ((err = mp_expt_n(&N, (int)s_mp_radix_exponent_y[radix], &N)) != MP_OKAY) goto LTM_ERR;
116+
n = mp_get_i32(&N);
117+
mp_clear(&N);
110118

111119
/* Numerator of the reciprocal: ceil(log_2(n)) */
112120
k = s_floor_ilog2(n) + 1;

0 commit comments

Comments
 (0)