Skip to content

Commit a331095

Browse files
committed
fix changed ltm API
1 parent a68b703 commit a331095

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/math/ltm_desc.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
#include <tommath.h>
1616

1717
static const struct {
18-
int mpi_code, ltc_code;
18+
mp_err mpi_code;
19+
int ltc_code;
1920
} mpi_to_ltc_codes[] = {
2021
{ MP_OKAY , CRYPT_OK},
2122
{ MP_MEM , CRYPT_MEM},
2223
{ MP_VAL , CRYPT_INVALID_ARG},
23-
#if defined(MP_ITER) || defined(MP_USE_ENUMS)
24+
#if defined(MP_BUF) || defined(MP_USE_ENUMS)
2425
{ MP_ITER , CRYPT_INVALID_PACKET},
26+
{ MP_BUF , CRYPT_BUFFER_OVERFLOW},
2527
#endif
2628
};
2729

@@ -30,11 +32,11 @@ static const struct {
3032
@param err The error to convert
3133
@return The equivalent LTC error code or CRYPT_ERROR if none found
3234
*/
33-
static int mpi_to_ltc_error(int err)
35+
static int mpi_to_ltc_error(mp_err err)
3436
{
35-
int x;
37+
size_t x;
3638

37-
for (x = 0; x < (int)(sizeof(mpi_to_ltc_codes)/sizeof(mpi_to_ltc_codes[0])); x++) {
39+
for (x = 0; x < sizeof(mpi_to_ltc_codes)/sizeof(mpi_to_ltc_codes[0]); x++) {
3840
if (err == mpi_to_ltc_codes[x].mpi_code) {
3941
return mpi_to_ltc_codes[x].ltc_code;
4042
}
@@ -139,11 +141,9 @@ static int get_digit_count(void *a)
139141

140142
static int compare(void *a, void *b)
141143
{
142-
int ret;
143144
LTC_ARGCHK(a != NULL);
144145
LTC_ARGCHK(b != NULL);
145-
ret = mp_cmp(a, b);
146-
switch (ret) {
146+
switch (mp_cmp(a, b)) {
147147
case MP_LT: return LTC_MP_LT;
148148
case MP_EQ: return LTC_MP_EQ;
149149
case MP_GT: return LTC_MP_GT;
@@ -153,10 +153,8 @@ static int compare(void *a, void *b)
153153

154154
static int compare_d(void *a, ltc_mp_digit b)
155155
{
156-
int ret;
157156
LTC_ARGCHK(a != NULL);
158-
ret = mp_cmp_d(a, b);
159-
switch (ret) {
157+
switch (mp_cmp_d(a, b)) {
160158
case MP_LT: return LTC_MP_LT;
161159
case MP_EQ: return LTC_MP_EQ;
162160
case MP_GT: return LTC_MP_GT;
@@ -201,31 +199,43 @@ static int write_radix(void *a, char *b, int radix)
201199
#ifdef BN_MP_TORADIX_C
202200
return mpi_to_ltc_error(mp_toradix(a, b, radix));
203201
#else
204-
return mpi_to_ltc_error(mp_to_radix(a, b, SIZE_MAX, radix));
202+
return mpi_to_ltc_error(mp_to_radix(a, b, SIZE_MAX, NULL, radix));
205203
#endif
206204
}
207205

208206
/* get size as unsigned char string */
209207
static unsigned long unsigned_size(void *a)
210208
{
211209
LTC_ARGCHK(a != NULL);
210+
#ifdef BN_MP_UNSIGNED_BIN_SIZE_C
212211
return mp_unsigned_bin_size(a);
212+
#else
213+
return (unsigned long)mp_ubin_size(a);
214+
#endif
213215
}
214216

215217
/* store */
216218
static int unsigned_write(void *a, unsigned char *b)
217219
{
218220
LTC_ARGCHK(a != NULL);
219221
LTC_ARGCHK(b != NULL);
222+
#ifdef BN_MP_TO_UNSIGNED_BIN_C
220223
return mpi_to_ltc_error(mp_to_unsigned_bin(a, b));
224+
#else
225+
return mpi_to_ltc_error(mp_to_ubin(a, b, SIZE_MAX, NULL));
226+
#endif
221227
}
222228

223229
/* read */
224230
static int unsigned_read(void *a, unsigned char *b, unsigned long len)
225231
{
226232
LTC_ARGCHK(a != NULL);
227233
LTC_ARGCHK(b != NULL);
234+
#ifdef BN_MP_READ_UNSIGNED_BIN_C
228235
return mpi_to_ltc_error(mp_read_unsigned_bin(a, b, len));
236+
#else
237+
return mpi_to_ltc_error(mp_from_ubin(a, b, (size_t)len));
238+
#endif
229239
}
230240

231241
/* add */

0 commit comments

Comments
 (0)