Skip to content

Commit b9977ad

Browse files
committed
use uint8_t instead of unsigned char
1 parent 98753c6 commit b9977ad

12 files changed

+42
-42
lines changed

demo/mtest_opponent.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ static int mtest_opponent(void)
139139
/* test the sign/unsigned storage functions */
140140

141141
rr = (unsigned)mp_sbin_size(&c);
142-
DO(mp_to_sbin(&c, (unsigned char *) cmd, (size_t)rr, NULL));
142+
DO(mp_to_sbin(&c, (uint8_t *) cmd, (size_t)rr, NULL));
143143
memset(cmd + rr, rand() & 0xFF, sizeof(cmd) - rr);
144-
DO(mp_from_sbin(&d, (unsigned char *) cmd, (size_t)rr));
144+
DO(mp_from_sbin(&d, (uint8_t *) cmd, (size_t)rr));
145145
if (mp_cmp(&c, &d) != MP_EQ) {
146146
printf("mp_signed_bin failure!\n");
147147
draw(&c);
@@ -150,9 +150,9 @@ static int mtest_opponent(void)
150150
}
151151

152152
rr = (unsigned)mp_ubin_size(&c);
153-
DO(mp_to_ubin(&c, (unsigned char *) cmd, (size_t)rr, NULL));
153+
DO(mp_to_ubin(&c, (uint8_t *) cmd, (size_t)rr, NULL));
154154
memset(cmd + rr, rand() & 0xFF, sizeof(cmd) - rr);
155-
DO(mp_from_ubin(&d, (unsigned char *) cmd, (size_t)rr));
155+
DO(mp_from_ubin(&d, (uint8_t *) cmd, (size_t)rr));
156156
if (mp_cmp_mag(&c, &d) != MP_EQ) {
157157
printf("mp_unsigned_bin failure!\n");
158158
draw(&c);

demo/test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ static int test_mp_read_write_ubin(void)
21692169
{
21702170
mp_int a, b, c;
21712171
size_t size, len;
2172-
unsigned char *buf = NULL;
2172+
uint8_t *buf = NULL;
21732173

21742174
DOR(mp_init_multi(&a, &b, &c, NULL));
21752175

@@ -2207,7 +2207,7 @@ static int test_mp_read_write_sbin(void)
22072207
{
22082208
mp_int a, b, c;
22092209
size_t size, len;
2210-
unsigned char *buf = NULL;
2210+
uint8_t *buf = NULL;
22112211

22122212
DOR(mp_init_multi(&a, &b, &c, NULL));
22132213

@@ -2246,7 +2246,7 @@ static int test_mp_pack_unpack(void)
22462246
{
22472247
mp_int a, b;
22482248
size_t written, count;
2249-
unsigned char *buf = NULL;
2249+
uint8_t *buf = NULL;
22502250

22512251
mp_order order = MP_LSB_FIRST;
22522252
mp_endian endianess = MP_NATIVE_ENDIAN;

doc/bn.tex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,15 +2444,15 @@ \section{Binary Conversions}
24442444

24452445
\index{mp\_to\_ubin}
24462446
\begin{alltt}
2447-
mp_err mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
2447+
mp_err mp_to_ubin(const mp_int *a, uint8_t *buf, size_t maxlen, size_t *written)
24482448
\end{alltt}
24492449
This will store $a$ into the buffer \texttt{buf} of size \texttt{maxlen} in big--endian format
24502450
storing the number of bytes written in \texttt{len}. Fortunately this is exactly what DER (or is
24512451
it ASN?) requires. It does not store the sign of the integer.
24522452

24532453
\index{mp\_from\_ubin}
24542454
\begin{alltt}
2455-
mp_err mp_from_ubin(mp_int *a, unsigned char *b, size_t size);
2455+
mp_err mp_from_ubin(mp_int *a, uint8_t *b, size_t size);
24562456
\end{alltt}
24572457
This will read in an unsigned big--endian array of bytes (octets) from \texttt{b} of length
24582458
\texttt{size} into $a$. The resulting big--integer $a$ will always be positive.
@@ -2462,8 +2462,8 @@ \section{Binary Conversions}
24622462
\index{mp\_sbin\_size} \index{mp\_from\_sbin} \index{mp\_to\_sbin}
24632463
\begin{alltt}
24642464
size_t mp_sbin_size(const mp_int *a);
2465-
mp_err mp_from_sbin(mp_int *a, const unsigned char *b, size_t size);
2466-
mp_err mp_to_sbin(const mp_int *a, unsigned char *b, size_t maxsize, size_t *len);
2465+
mp_err mp_from_sbin(mp_int *a, const uint8_t *b, size_t size);
2466+
mp_err mp_to_sbin(const mp_int *a, uint8_t *b, size_t maxsize, size_t *len);
24672467
\end{alltt}
24682468
They operate essentially the same as the unsigned copies except they prefix the data with zero or
24692469
non--zero byte depending on the sign. If the sign is \texttt{MP\_ZPOS} (e.g. not negative) the

mp_from_sbin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/* SPDX-License-Identifier: Unlicense */
55

66
/* read signed bin, big endian, first byte is 0==positive or 1==negative */
7-
mp_err mp_from_sbin(mp_int *a, const unsigned char *buf, size_t size)
7+
mp_err mp_from_sbin(mp_int *a, const uint8_t *buf, size_t size)
88
{
99
mp_err err;
1010

@@ -14,7 +14,7 @@ mp_err mp_from_sbin(mp_int *a, const unsigned char *buf, size_t size)
1414
}
1515

1616
/* first byte is 0 for positive, non-zero for negative */
17-
if (buf[0] == (unsigned char)0) {
17+
if (buf[0] == (uint8_t)0) {
1818
a->sign = MP_ZPOS;
1919
} else {
2020
a->sign = MP_NEG;

mp_from_ubin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
44
/* SPDX-License-Identifier: Unlicense */
55

6-
/* reads a unsigned char array, assumes the msb is stored first [big endian] */
7-
mp_err mp_from_ubin(mp_int *a, const unsigned char *buf, size_t size)
6+
/* reads a uint8_t array, assumes the msb is stored first [big endian] */
7+
mp_err mp_from_ubin(mp_int *a, const uint8_t *buf, size_t size)
88
{
99
mp_err err;
1010

mp_pack.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mp_err mp_pack(void *rop, size_t maxcount, size_t *written, mp_order order, size
1111
{
1212
mp_err err;
1313
size_t odd_nails, nail_bytes, i, j, count;
14-
unsigned char odd_nail_mask;
14+
uint8_t odd_nail_mask;
1515

1616
mp_int t;
1717

@@ -32,22 +32,22 @@ mp_err mp_pack(void *rop, size_t maxcount, size_t *written, mp_order order, size
3232
odd_nails = (nails % 8u);
3333
odd_nail_mask = 0xff;
3434
for (i = 0u; i < odd_nails; ++i) {
35-
odd_nail_mask ^= (unsigned char)(1u << (7u - i));
35+
odd_nail_mask ^= (uint8_t)(1u << (7u - i));
3636
}
3737
nail_bytes = nails / 8u;
3838

3939
for (i = 0u; i < count; ++i) {
4040
for (j = 0u; j < size; ++j) {
41-
unsigned char *byte = (unsigned char *)rop +
42-
(((order == MP_LSB_FIRST) ? i : ((count - 1u) - i)) * size) +
43-
((endian == MP_LITTLE_ENDIAN) ? j : ((size - 1u) - j));
41+
uint8_t *byte = (uint8_t *)rop +
42+
(((order == MP_LSB_FIRST) ? i : ((count - 1u) - i)) * size) +
43+
((endian == MP_LITTLE_ENDIAN) ? j : ((size - 1u) - j));
4444

4545
if (j >= (size - nail_bytes)) {
4646
*byte = 0;
4747
continue;
4848
}
4949

50-
*byte = (unsigned char)((j == ((size - nail_bytes) - 1u)) ? (t.dp[0] & odd_nail_mask) : (t.dp[0] & 0xFFuL));
50+
*byte = (uint8_t)((j == ((size - nail_bytes) - 1u)) ? (t.dp[0] & odd_nail_mask) : (t.dp[0] & 0xFFuL));
5151

5252
if ((err = mp_div_2d(&t, (j == ((size - nail_bytes) - 1u)) ? (int)(8u - odd_nails) : 8, &t, NULL)) != MP_OKAY) {
5353
goto LBL_ERR;

mp_prime_rand.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/* This is possibly the mother of all prime generation functions, muahahahahaha! */
2121
mp_err mp_prime_rand(mp_int *a, int t, int size, int flags)
2222
{
23-
unsigned char *tmp, maskAND, maskOR_msb, maskOR_lsb;
23+
uint8_t *tmp, maskAND, maskOR_msb, maskOR_lsb;
2424
int bsize, maskOR_msb_offset;
2525
bool res;
2626
mp_err err;
@@ -39,19 +39,19 @@ mp_err mp_prime_rand(mp_int *a, int t, int size, int flags)
3939
bsize = (size>>3) + ((size&7)?1:0);
4040

4141
/* we need a buffer of bsize bytes */
42-
tmp = (unsigned char *) MP_MALLOC((size_t)bsize);
42+
tmp = (uint8_t *) MP_MALLOC((size_t)bsize);
4343
if (tmp == NULL) {
4444
return MP_MEM;
4545
}
4646

4747
/* calc the maskAND value for the MSbyte*/
48-
maskAND = ((size&7) == 0) ? 0xFFu : (unsigned char)(0xFFu >> (8 - (size & 7)));
48+
maskAND = ((size&7) == 0) ? 0xFFu : (uint8_t)(0xFFu >> (8 - (size & 7)));
4949

5050
/* calc the maskOR_msb */
5151
maskOR_msb = 0;
5252
maskOR_msb_offset = ((size & 7) == 1) ? 1 : 0;
5353
if ((flags & MP_PRIME_2MSB_ON) != 0) {
54-
maskOR_msb |= (unsigned char)(0x80 >> ((9 - size) & 7));
54+
maskOR_msb |= (uint8_t)(0x80 >> ((9 - size) & 7));
5555
}
5656

5757
/* get the maskOR_lsb */
@@ -68,7 +68,7 @@ mp_err mp_prime_rand(mp_int *a, int t, int size, int flags)
6868

6969
/* work over the MSbyte */
7070
tmp[0] &= maskAND;
71-
tmp[0] |= (unsigned char)(1 << ((size - 1) & 7));
71+
tmp[0] |= (uint8_t)(1 << ((size - 1) & 7));
7272

7373
/* mix in the maskORs */
7474
tmp[maskOR_msb_offset] |= maskOR_msb;

mp_to_radix.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
/* SPDX-License-Identifier: Unlicense */
55

66
/* reverse an array, used for radix code */
7-
static void s_mp_reverse(unsigned char *s, size_t len)
7+
static void s_mp_reverse(uint8_t *s, size_t len)
88
{
99
size_t ix, iy;
10-
unsigned char t;
10+
uint8_t t;
1111

1212
ix = 0u;
1313
iy = len - 1u;
@@ -83,7 +83,7 @@ mp_err mp_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *written, i
8383
/* reverse the digits of the string. In this case _s points
8484
* to the first digit [exluding the sign] of the number
8585
*/
86-
s_mp_reverse((unsigned char *)_s, digs);
86+
s_mp_reverse((uint8_t *)_s, digs);
8787

8888
/* append a NULL so the string is properly terminated */
8989
*str = '\0';

mp_to_sbin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/* SPDX-License-Identifier: Unlicense */
55

66
/* store in signed [big endian] format */
7-
mp_err mp_to_sbin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
7+
mp_err mp_to_sbin(const mp_int *a, uint8_t *buf, size_t maxlen, size_t *written)
88
{
99
mp_err err;
1010
if (maxlen == 0u) {
@@ -16,7 +16,7 @@ mp_err mp_to_sbin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *wr
1616
if (written != NULL) {
1717
(*written)++;
1818
}
19-
buf[0] = (a->sign == MP_ZPOS) ? (unsigned char)0 : (unsigned char)1;
19+
buf[0] = (a->sign == MP_ZPOS) ? (uint8_t)0 : (uint8_t)1;
2020
return MP_OKAY;
2121
}
2222
#endif

mp_to_ubin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/* SPDX-License-Identifier: Unlicense */
55

66
/* store in unsigned [big endian] format */
7-
mp_err mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
7+
mp_err mp_to_ubin(const mp_int *a, uint8_t *buf, size_t maxlen, size_t *written)
88
{
99
size_t x, count;
1010
mp_err err;
@@ -20,7 +20,7 @@ mp_err mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *wr
2020
}
2121

2222
for (x = count; x --> 0u;) {
23-
buf[x] = (unsigned char)(t.dp[0] & 255u);
23+
buf[x] = (uint8_t)(t.dp[0] & 255u);
2424
if ((err = mp_div_2d(&t, 8, &t, NULL)) != MP_OKAY) {
2525
goto LBL_ERR;
2626
}

mp_unpack.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mp_err mp_unpack(mp_int *rop, size_t count, mp_order order, size_t size,
1111
{
1212
mp_err err;
1313
size_t odd_nails, nail_bytes, i, j;
14-
unsigned char odd_nail_mask;
14+
uint8_t odd_nail_mask;
1515

1616
mp_zero(rop);
1717

@@ -22,15 +22,15 @@ mp_err mp_unpack(mp_int *rop, size_t count, mp_order order, size_t size,
2222
odd_nails = (nails % 8u);
2323
odd_nail_mask = 0xff;
2424
for (i = 0; i < odd_nails; ++i) {
25-
odd_nail_mask ^= (unsigned char)(1u << (7u - i));
25+
odd_nail_mask ^= (uint8_t)(1u << (7u - i));
2626
}
2727
nail_bytes = nails / 8u;
2828

2929
for (i = 0; i < count; ++i) {
3030
for (j = 0; j < (size - nail_bytes); ++j) {
31-
unsigned char byte = *((const unsigned char *)op +
32-
(((order == MP_MSB_FIRST) ? i : ((count - 1u) - i)) * size) +
33-
((endian == MP_BIG_ENDIAN) ? (j + nail_bytes) : (((size - 1u) - j) - nail_bytes)));
31+
uint8_t byte = *((const uint8_t *)op +
32+
(((order == MP_MSB_FIRST) ? i : ((count - 1u) - i)) * size) +
33+
((endian == MP_BIG_ENDIAN) ? (j + nail_bytes) : (((size - 1u) - j) - nail_bytes)));
3434

3535
if ((err = mp_mul_2d(rop, (j == 0u) ? (int)(8u - odd_nails) : 8, rop)) != MP_OKAY) {
3636
return err;

tommath.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,12 @@ mp_err mp_expt_u32(const mp_int *a, uint32_t b, mp_int *c) MP_WUR;
570570
int mp_count_bits(const mp_int *a) MP_WUR;
571571

572572
size_t mp_ubin_size(const mp_int *a) MP_WUR;
573-
mp_err mp_from_ubin(mp_int *a, const unsigned char *buf, size_t size) MP_WUR;
574-
mp_err mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written) MP_WUR;
573+
mp_err mp_from_ubin(mp_int *a, const uint8_t *buf, size_t size) MP_WUR;
574+
mp_err mp_to_ubin(const mp_int *a, uint8_t *buf, size_t maxlen, size_t *written) MP_WUR;
575575

576576
size_t mp_sbin_size(const mp_int *a) MP_WUR;
577-
mp_err mp_from_sbin(mp_int *a, const unsigned char *buf, size_t size) MP_WUR;
578-
mp_err mp_to_sbin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written) MP_WUR;
577+
mp_err mp_from_sbin(mp_int *a, const uint8_t *buf, size_t size) MP_WUR;
578+
mp_err mp_to_sbin(const mp_int *a, uint8_t *buf, size_t maxlen, size_t *written) MP_WUR;
579579

580580
mp_err mp_read_radix(mp_int *a, const char *str, int radix) MP_WUR;
581581
mp_err mp_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *written, int radix) MP_WUR;

0 commit comments

Comments
 (0)