use uint8_t instead of unsigned char
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
diff --git a/demo/mtest_opponent.c b/demo/mtest_opponent.c
index 6c49de2..1beab5f 100644
--- a/demo/mtest_opponent.c
+++ b/demo/mtest_opponent.c
@@ -139,9 +139,9 @@ static int mtest_opponent(void)
/* test the sign/unsigned storage functions */
rr = (unsigned)mp_sbin_size(&c);
- DO(mp_to_sbin(&c, (unsigned char *) cmd, (size_t)rr, NULL));
+ DO(mp_to_sbin(&c, (uint8_t *) cmd, (size_t)rr, NULL));
memset(cmd + rr, rand() & 0xFF, sizeof(cmd) - rr);
- DO(mp_from_sbin(&d, (unsigned char *) cmd, (size_t)rr));
+ DO(mp_from_sbin(&d, (uint8_t *) cmd, (size_t)rr));
if (mp_cmp(&c, &d) != MP_EQ) {
printf("mp_signed_bin failure!\n");
draw(&c);
@@ -150,9 +150,9 @@ static int mtest_opponent(void)
}
rr = (unsigned)mp_ubin_size(&c);
- DO(mp_to_ubin(&c, (unsigned char *) cmd, (size_t)rr, NULL));
+ DO(mp_to_ubin(&c, (uint8_t *) cmd, (size_t)rr, NULL));
memset(cmd + rr, rand() & 0xFF, sizeof(cmd) - rr);
- DO(mp_from_ubin(&d, (unsigned char *) cmd, (size_t)rr));
+ DO(mp_from_ubin(&d, (uint8_t *) cmd, (size_t)rr));
if (mp_cmp_mag(&c, &d) != MP_EQ) {
printf("mp_unsigned_bin failure!\n");
draw(&c);
diff --git a/demo/test.c b/demo/test.c
index 7a42330..8e37f71 100644
--- a/demo/test.c
+++ b/demo/test.c
@@ -2169,7 +2169,7 @@ static int test_mp_read_write_ubin(void)
{
mp_int a, b, c;
size_t size, len;
- unsigned char *buf = NULL;
+ uint8_t *buf = NULL;
DOR(mp_init_multi(&a, &b, &c, NULL));
@@ -2207,7 +2207,7 @@ static int test_mp_read_write_sbin(void)
{
mp_int a, b, c;
size_t size, len;
- unsigned char *buf = NULL;
+ uint8_t *buf = NULL;
DOR(mp_init_multi(&a, &b, &c, NULL));
@@ -2246,7 +2246,7 @@ static int test_mp_pack_unpack(void)
{
mp_int a, b;
size_t written, count;
- unsigned char *buf = NULL;
+ uint8_t *buf = NULL;
mp_order order = MP_LSB_FIRST;
mp_endian endianess = MP_NATIVE_ENDIAN;
diff --git a/doc/bn.tex b/doc/bn.tex
index 1e8ac74..b8a6404 100644
--- a/doc/bn.tex
+++ b/doc/bn.tex
@@ -2444,7 +2444,7 @@ $a$.
\index{mp\_to\_ubin}
\begin{alltt}
-mp_err mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
+mp_err mp_to_ubin(const mp_int *a, uint8_t *buf, size_t maxlen, size_t *written)
\end{alltt}
This will store $a$ into the buffer \texttt{buf} of size \texttt{maxlen} in big--endian format
storing the number of bytes written in \texttt{len}. Fortunately this is exactly what DER (or is
@@ -2452,7 +2452,7 @@ it ASN?) requires. It does not store the sign of the integer.
\index{mp\_from\_ubin}
\begin{alltt}
-mp_err mp_from_ubin(mp_int *a, unsigned char *b, size_t size);
+mp_err mp_from_ubin(mp_int *a, uint8_t *b, size_t size);
\end{alltt}
This will read in an unsigned big--endian array of bytes (octets) from \texttt{b} of length
\texttt{size} into $a$. The resulting big--integer $a$ will always be positive.
@@ -2462,8 +2462,8 @@ versions of the previous functions.
\index{mp\_sbin\_size} \index{mp\_from\_sbin} \index{mp\_to\_sbin}
\begin{alltt}
size_t mp_sbin_size(const mp_int *a);
-mp_err mp_from_sbin(mp_int *a, const unsigned char *b, size_t size);
-mp_err mp_to_sbin(const mp_int *a, unsigned char *b, size_t maxsize, size_t *len);
+mp_err mp_from_sbin(mp_int *a, const uint8_t *b, size_t size);
+mp_err mp_to_sbin(const mp_int *a, uint8_t *b, size_t maxsize, size_t *len);
\end{alltt}
They operate essentially the same as the unsigned copies except they prefix the data with zero or
non--zero byte depending on the sign. If the sign is \texttt{MP\_ZPOS} (e.g. not negative) the
diff --git a/mp_from_sbin.c b/mp_from_sbin.c
index 4335d88..c6e87d7 100644
--- a/mp_from_sbin.c
+++ b/mp_from_sbin.c
@@ -4,7 +4,7 @@
/* SPDX-License-Identifier: Unlicense */
/* read signed bin, big endian, first byte is 0==positive or 1==negative */
-mp_err mp_from_sbin(mp_int *a, const unsigned char *buf, size_t size)
+mp_err mp_from_sbin(mp_int *a, const uint8_t *buf, size_t size)
{
mp_err err;
@@ -14,7 +14,7 @@ mp_err mp_from_sbin(mp_int *a, const unsigned char *buf, size_t size)
}
/* first byte is 0 for positive, non-zero for negative */
- if (buf[0] == (unsigned char)0) {
+ if (buf[0] == (uint8_t)0) {
a->sign = MP_ZPOS;
} else {
a->sign = MP_NEG;
diff --git a/mp_from_ubin.c b/mp_from_ubin.c
index 315ff08..ae79be3 100644
--- a/mp_from_ubin.c
+++ b/mp_from_ubin.c
@@ -3,8 +3,8 @@
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
-/* reads a unsigned char array, assumes the msb is stored first [big endian] */
-mp_err mp_from_ubin(mp_int *a, const unsigned char *buf, size_t size)
+/* reads a uint8_t array, assumes the msb is stored first [big endian] */
+mp_err mp_from_ubin(mp_int *a, const uint8_t *buf, size_t size)
{
mp_err err;
diff --git a/mp_pack.c b/mp_pack.c
index ec0f62f..447f1fd 100644
--- a/mp_pack.c
+++ b/mp_pack.c
@@ -11,7 +11,7 @@ mp_err mp_pack(void *rop, size_t maxcount, size_t *written, mp_order order, size
{
mp_err err;
size_t odd_nails, nail_bytes, i, j, count;
- unsigned char odd_nail_mask;
+ uint8_t odd_nail_mask;
mp_int t;
@@ -32,22 +32,22 @@ mp_err mp_pack(void *rop, size_t maxcount, size_t *written, mp_order order, size
odd_nails = (nails % 8u);
odd_nail_mask = 0xff;
for (i = 0u; i < odd_nails; ++i) {
- odd_nail_mask ^= (unsigned char)(1u << (7u - i));
+ odd_nail_mask ^= (uint8_t)(1u << (7u - i));
}
nail_bytes = nails / 8u;
for (i = 0u; i < count; ++i) {
for (j = 0u; j < size; ++j) {
- unsigned char *byte = (unsigned char *)rop +
- (((order == MP_LSB_FIRST) ? i : ((count - 1u) - i)) * size) +
- ((endian == MP_LITTLE_ENDIAN) ? j : ((size - 1u) - j));
+ uint8_t *byte = (uint8_t *)rop +
+ (((order == MP_LSB_FIRST) ? i : ((count - 1u) - i)) * size) +
+ ((endian == MP_LITTLE_ENDIAN) ? j : ((size - 1u) - j));
if (j >= (size - nail_bytes)) {
*byte = 0;
continue;
}
- *byte = (unsigned char)((j == ((size - nail_bytes) - 1u)) ? (t.dp[0] & odd_nail_mask) : (t.dp[0] & 0xFFuL));
+ *byte = (uint8_t)((j == ((size - nail_bytes) - 1u)) ? (t.dp[0] & odd_nail_mask) : (t.dp[0] & 0xFFuL));
if ((err = mp_div_2d(&t, (j == ((size - nail_bytes) - 1u)) ? (int)(8u - odd_nails) : 8, &t, NULL)) != MP_OKAY) {
goto LBL_ERR;
diff --git a/mp_prime_rand.c b/mp_prime_rand.c
index ff6df9c..8476b4f 100644
--- a/mp_prime_rand.c
+++ b/mp_prime_rand.c
@@ -20,7 +20,7 @@
/* This is possibly the mother of all prime generation functions, muahahahahaha! */
mp_err mp_prime_rand(mp_int *a, int t, int size, int flags)
{
- unsigned char *tmp, maskAND, maskOR_msb, maskOR_lsb;
+ uint8_t *tmp, maskAND, maskOR_msb, maskOR_lsb;
int bsize, maskOR_msb_offset;
bool res;
mp_err err;
@@ -39,19 +39,19 @@ mp_err mp_prime_rand(mp_int *a, int t, int size, int flags)
bsize = (size>>3) + ((size&7)?1:0);
/* we need a buffer of bsize bytes */
- tmp = (unsigned char *) MP_MALLOC((size_t)bsize);
+ tmp = (uint8_t *) MP_MALLOC((size_t)bsize);
if (tmp == NULL) {
return MP_MEM;
}
/* calc the maskAND value for the MSbyte*/
- maskAND = ((size&7) == 0) ? 0xFFu : (unsigned char)(0xFFu >> (8 - (size & 7)));
+ maskAND = ((size&7) == 0) ? 0xFFu : (uint8_t)(0xFFu >> (8 - (size & 7)));
/* calc the maskOR_msb */
maskOR_msb = 0;
maskOR_msb_offset = ((size & 7) == 1) ? 1 : 0;
if ((flags & MP_PRIME_2MSB_ON) != 0) {
- maskOR_msb |= (unsigned char)(0x80 >> ((9 - size) & 7));
+ maskOR_msb |= (uint8_t)(0x80 >> ((9 - size) & 7));
}
/* get the maskOR_lsb */
@@ -68,7 +68,7 @@ mp_err mp_prime_rand(mp_int *a, int t, int size, int flags)
/* work over the MSbyte */
tmp[0] &= maskAND;
- tmp[0] |= (unsigned char)(1 << ((size - 1) & 7));
+ tmp[0] |= (uint8_t)(1 << ((size - 1) & 7));
/* mix in the maskORs */
tmp[maskOR_msb_offset] |= maskOR_msb;
diff --git a/mp_to_radix.c b/mp_to_radix.c
index 78ad989..c1ea233 100644
--- a/mp_to_radix.c
+++ b/mp_to_radix.c
@@ -4,10 +4,10 @@
/* SPDX-License-Identifier: Unlicense */
/* reverse an array, used for radix code */
-static void s_mp_reverse(unsigned char *s, size_t len)
+static void s_mp_reverse(uint8_t *s, size_t len)
{
size_t ix, iy;
- unsigned char t;
+ uint8_t t;
ix = 0u;
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
/* reverse the digits of the string. In this case _s points
* to the first digit [exluding the sign] of the number
*/
- s_mp_reverse((unsigned char *)_s, digs);
+ s_mp_reverse((uint8_t *)_s, digs);
/* append a NULL so the string is properly terminated */
*str = '\0';
diff --git a/mp_to_sbin.c b/mp_to_sbin.c
index ed21adc..8225d13 100644
--- a/mp_to_sbin.c
+++ b/mp_to_sbin.c
@@ -4,7 +4,7 @@
/* SPDX-License-Identifier: Unlicense */
/* store in signed [big endian] format */
-mp_err mp_to_sbin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
+mp_err mp_to_sbin(const mp_int *a, uint8_t *buf, size_t maxlen, size_t *written)
{
mp_err err;
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
if (written != NULL) {
(*written)++;
}
- buf[0] = (a->sign == MP_ZPOS) ? (unsigned char)0 : (unsigned char)1;
+ buf[0] = (a->sign == MP_ZPOS) ? (uint8_t)0 : (uint8_t)1;
return MP_OKAY;
}
#endif
diff --git a/mp_to_ubin.c b/mp_to_ubin.c
index 2583503..e8643cc 100644
--- a/mp_to_ubin.c
+++ b/mp_to_ubin.c
@@ -4,7 +4,7 @@
/* SPDX-License-Identifier: Unlicense */
/* store in unsigned [big endian] format */
-mp_err mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
+mp_err mp_to_ubin(const mp_int *a, uint8_t *buf, size_t maxlen, size_t *written)
{
size_t x, count;
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
}
for (x = count; x --> 0u;) {
- buf[x] = (unsigned char)(t.dp[0] & 255u);
+ buf[x] = (uint8_t)(t.dp[0] & 255u);
if ((err = mp_div_2d(&t, 8, &t, NULL)) != MP_OKAY) {
goto LBL_ERR;
}
diff --git a/mp_unpack.c b/mp_unpack.c
index 5305b43..f0127fa 100644
--- a/mp_unpack.c
+++ b/mp_unpack.c
@@ -11,7 +11,7 @@ mp_err mp_unpack(mp_int *rop, size_t count, mp_order order, size_t size,
{
mp_err err;
size_t odd_nails, nail_bytes, i, j;
- unsigned char odd_nail_mask;
+ uint8_t odd_nail_mask;
mp_zero(rop);
@@ -22,15 +22,15 @@ mp_err mp_unpack(mp_int *rop, size_t count, mp_order order, size_t size,
odd_nails = (nails % 8u);
odd_nail_mask = 0xff;
for (i = 0; i < odd_nails; ++i) {
- odd_nail_mask ^= (unsigned char)(1u << (7u - i));
+ odd_nail_mask ^= (uint8_t)(1u << (7u - i));
}
nail_bytes = nails / 8u;
for (i = 0; i < count; ++i) {
for (j = 0; j < (size - nail_bytes); ++j) {
- unsigned char byte = *((const unsigned char *)op +
- (((order == MP_MSB_FIRST) ? i : ((count - 1u) - i)) * size) +
- ((endian == MP_BIG_ENDIAN) ? (j + nail_bytes) : (((size - 1u) - j) - nail_bytes)));
+ uint8_t byte = *((const uint8_t *)op +
+ (((order == MP_MSB_FIRST) ? i : ((count - 1u) - i)) * size) +
+ ((endian == MP_BIG_ENDIAN) ? (j + nail_bytes) : (((size - 1u) - j) - nail_bytes)));
if ((err = mp_mul_2d(rop, (j == 0u) ? (int)(8u - odd_nails) : 8, rop)) != MP_OKAY) {
return err;
diff --git a/tommath.h b/tommath.h
index 8742126..86b19d3 100644
--- a/tommath.h
+++ b/tommath.h
@@ -570,12 +570,12 @@ mp_err mp_expt_u32(const mp_int *a, uint32_t b, mp_int *c) MP_WUR;
int mp_count_bits(const mp_int *a) MP_WUR;
size_t mp_ubin_size(const mp_int *a) MP_WUR;
-mp_err mp_from_ubin(mp_int *a, const unsigned char *buf, size_t size) MP_WUR;
-mp_err mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written) MP_WUR;
+mp_err mp_from_ubin(mp_int *a, const uint8_t *buf, size_t size) MP_WUR;
+mp_err mp_to_ubin(const mp_int *a, uint8_t *buf, size_t maxlen, size_t *written) MP_WUR;
size_t mp_sbin_size(const mp_int *a) MP_WUR;
-mp_err mp_from_sbin(mp_int *a, const unsigned char *buf, size_t size) MP_WUR;
-mp_err mp_to_sbin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written) MP_WUR;
+mp_err mp_from_sbin(mp_int *a, const uint8_t *buf, size_t size) MP_WUR;
+mp_err mp_to_sbin(const mp_int *a, uint8_t *buf, size_t maxlen, size_t *written) MP_WUR;
mp_err mp_read_radix(mp_int *a, const char *str, int radix) MP_WUR;
mp_err mp_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *written, int radix) MP_WUR;