run `make astyle` [skip ci]
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 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
diff --git a/bn_mp_fwrite.c b/bn_mp_fwrite.c
index 8f236ab..3bcb445 100644
--- a/bn_mp_fwrite.c
+++ b/bn_mp_fwrite.c
@@ -22,7 +22,7 @@ int mp_fwrite(const mp_int *a, int radix, FILE *stream)
return err;
}
- buf = (char*) XMALLOC((size_t)len);
+ buf = (char *) XMALLOC((size_t)len);
if (buf == NULL) {
return MP_MEM;
}
diff --git a/bn_mp_grow.c b/bn_mp_grow.c
index fe36d3d..255335d 100644
--- a/bn_mp_grow.c
+++ b/bn_mp_grow.c
@@ -29,7 +29,7 @@ int mp_grow(mp_int *a, int size)
* in case the operation failed we don't want
* to overwrite the dp member of a.
*/
- tmp = (mp_digit*) XREALLOC(a->dp, sizeof(mp_digit) * (size_t)size);
+ tmp = (mp_digit *) XREALLOC(a->dp, sizeof(mp_digit) * (size_t)size);
if (tmp == NULL) {
/* reallocation failed but "a" is still valid [can be freed] */
return MP_MEM;
diff --git a/bn_mp_init.c b/bn_mp_init.c
index c66c46c..0be909c 100644
--- a/bn_mp_init.c
+++ b/bn_mp_init.c
@@ -18,7 +18,7 @@ int mp_init(mp_int *a)
int i;
/* allocate memory required and clear it */
- a->dp = (mp_digit*) XMALLOC(sizeof(mp_digit) * (size_t)MP_PREC);
+ a->dp = (mp_digit *) XMALLOC(sizeof(mp_digit) * (size_t)MP_PREC);
if (a->dp == NULL) {
return MP_MEM;
}
diff --git a/bn_mp_init_size.c b/bn_mp_init_size.c
index 8f5f642..b692f5b 100644
--- a/bn_mp_init_size.c
+++ b/bn_mp_init_size.c
@@ -21,7 +21,7 @@ int mp_init_size(mp_int *a, int size)
size += (MP_PREC * 2) - (size % MP_PREC);
/* alloc mem */
- a->dp = (mp_digit*) XMALLOC(sizeof(mp_digit) * (size_t)size);
+ a->dp = (mp_digit *) XMALLOC(sizeof(mp_digit) * (size_t)size);
if (a->dp == NULL) {
return MP_MEM;
}
diff --git a/bn_mp_prime_random_ex.c b/bn_mp_prime_random_ex.c
index 5909085..929c72e 100644
--- a/bn_mp_prime_random_ex.c
+++ b/bn_mp_prime_random_ex.c
@@ -46,7 +46,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
bsize = (size>>3) + ((size&7)?1:0);
/* we need a buffer of bsize bytes */
- tmp = (unsigned char*) XMALLOC((size_t)bsize);
+ tmp = (unsigned char *) XMALLOC((size_t)bsize);
if (tmp == NULL) {
return MP_MEM;
}
diff --git a/bn_mp_set_long.c b/bn_mp_set_long.c
index 404ae97..223c0e3 100644
--- a/bn_mp_set_long.c
+++ b/bn_mp_set_long.c
@@ -21,11 +21,11 @@ int mp_set_long(mp_int *a, unsigned long b)
int x = 0;
int res = mp_grow(a, (CHAR_BIT * sizeof(unsigned long) + DIGIT_BIT - 1) / DIGIT_BIT);
if (res == MP_OKAY) {
- mp_zero(a);
- if (b) {
- a->dp[x++] = (mp_digit)b;
- }
- a->used = x;
+ mp_zero(a);
+ if (b) {
+ a->dp[x++] = (mp_digit)b;
+ }
+ a->used = x;
}
return res;
}
diff --git a/bn_mp_shrink.c b/bn_mp_shrink.c
index e033fcc..de15e12 100644
--- a/bn_mp_shrink.c
+++ b/bn_mp_shrink.c
@@ -23,7 +23,7 @@ int mp_shrink(mp_int *a)
}
if (a->alloc != used) {
- if ((tmp = (mp_digit*) XREALLOC(a->dp, sizeof(mp_digit) * (size_t)used)) == NULL) {
+ if ((tmp = (mp_digit *) XREALLOC(a->dp, sizeof(mp_digit) * (size_t)used)) == NULL) {
return MP_MEM;
}
a->dp = tmp;
diff --git a/demo/main.c b/demo/main.c
index 561a3d2..fafb61d 100644
--- a/demo/main.c
+++ b/demo/main.c
@@ -3,7 +3,7 @@
int mtest_opponent(void);
int unit_tests(void);
-void ndraw(mp_int* a, const char* name)
+void ndraw(mp_int *a, const char *name)
{
char *buf;
int size;
diff --git a/demo/opponent.c b/demo/opponent.c
index b52ff72..d701325 100644
--- a/demo/opponent.c
+++ b/demo/opponent.c
@@ -379,7 +379,7 @@ int mtest_opponent(void)
printf("\n");
return 0;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, &c, &d, &e, &f, NULL);
printf("\n");
return EXIT_FAILURE;
diff --git a/demo/test.c b/demo/test.c
index e316ef3..751142c 100644
--- a/demo/test.c
+++ b/demo/test.c
@@ -1,6 +1,7 @@
#include "shared.h"
-static int test_trivial_stuff(void) {
+static int test_trivial_stuff(void)
+{
mp_int a, b, c, d;
if (mp_init_multi(&a, &b, &c, &d, NULL)!= MP_OKAY) {
return EXIT_FAILURE;
@@ -11,7 +12,7 @@ static int test_trivial_stuff(void) {
/* a: 5-> b: -5 */
mp_neg(&a, &b);
if (mp_cmp(&a, &b) != MP_GT) {
- goto LBL_ERR;
+ goto LBL_ERR;
}
if (mp_cmp(&b, &a) != MP_LT) {
goto LBL_ERR;
@@ -62,12 +63,13 @@ static int test_trivial_stuff(void) {
mp_clear_multi(&a, &b, &c, &d, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, &c, &d, NULL);
return EXIT_FAILURE;
}
-static int test_mp_jacobi(void) {
+static int test_mp_jacobi(void)
+{
struct mp_jacobi_st {
unsigned long n;
int c[16];
@@ -121,12 +123,13 @@ static int test_mp_jacobi(void) {
mp_clear_multi(&a, &b, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, NULL);
return EXIT_FAILURE;
}
-static int test_mp_kronecker(void) {
+static int test_mp_kronecker(void)
+{
struct mp_kronecker_st {
long n;
int c[21];
@@ -203,12 +206,13 @@ static int test_mp_kronecker(void) {
mp_clear_multi(&a, &b, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, NULL);
return EXIT_FAILURE;
}
-static int test_mp_complement(void) {
+static int test_mp_complement(void)
+{
int i;
mp_int a, b, c;
@@ -236,12 +240,13 @@ static int test_mp_complement(void) {
mp_clear_multi(&a, &b, &c, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, &c, NULL);
return EXIT_FAILURE;
}
-static int test_mp_tc_div_2d(void) {
+static int test_mp_tc_div_2d(void)
+{
int i;
mp_int a, b, d;
@@ -272,13 +277,14 @@ static int test_mp_tc_div_2d(void) {
mp_clear_multi(&a, &b, &d, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, &d, NULL);
return EXIT_FAILURE;
}
-static int test_mp_tc_xor(void) {
+static int test_mp_tc_xor(void)
+{
int i;
mp_int a, b, c, d;
@@ -312,13 +318,14 @@ static int test_mp_tc_xor(void) {
mp_clear_multi(&a, &b, &c, &d, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, &c, &d, NULL);
return EXIT_FAILURE;
}
-static int test_mp_tc_or(void) {
+static int test_mp_tc_or(void)
+{
int i;
mp_int a, b, c, d;
@@ -352,12 +359,13 @@ static int test_mp_tc_or(void) {
mp_clear_multi(&a, &b, &c, &d, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, &c, &d, NULL);
return EXIT_FAILURE;
}
-static int test_mp_tc_and(void) {
+static int test_mp_tc_and(void)
+{
int i;
mp_int a, b, c, d;
@@ -391,12 +399,13 @@ static int test_mp_tc_and(void) {
mp_clear_multi(&a, &b, &c, &d, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, &c, &d, NULL);
return EXIT_FAILURE;
}
-static int test_mp_invmod(void) {
+static int test_mp_invmod(void)
+{
mp_int a, b, c, d;
if (mp_init_multi(&a, &b, &c, &d, NULL)!= MP_OKAY) {
return EXIT_FAILURE;
@@ -434,13 +443,14 @@ static int test_mp_invmod(void) {
mp_clear_multi(&a, &b, &c, &d, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, &c, &d, NULL);
return EXIT_FAILURE;
}
-static int test_mp_set_double(void) {
+static int test_mp_set_double(void)
+{
int i;
mp_int a, b;
@@ -491,13 +501,14 @@ static int test_mp_set_double(void) {
mp_clear_multi(&a, &b, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, NULL);
return EXIT_FAILURE;
}
-static int test_mp_get_int(void) {
+static int test_mp_get_int(void)
+{
unsigned long t;
int i;
@@ -527,12 +538,13 @@ static int test_mp_get_int(void) {
mp_clear_multi(&a, &b, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, NULL);
return EXIT_FAILURE;
}
-static int test_mp_get_long(void) {
+static int test_mp_get_long(void)
+{
unsigned long s, t;
int i;
@@ -562,12 +574,13 @@ static int test_mp_get_long(void) {
mp_clear_multi(&a, &b, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, NULL);
return EXIT_FAILURE;
}
-static int test_mp_get_long_long(void) {
+static int test_mp_get_long_long(void)
+{
unsigned long long q, r;
int i;
@@ -597,13 +610,14 @@ static int test_mp_get_long_long(void) {
mp_clear_multi(&a, &b, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, NULL);
return EXIT_FAILURE;
}
-static int test_mp_sqrt(void) {
+static int test_mp_sqrt(void)
+{
int i, n;
mp_int a, b, c, d;
@@ -634,12 +648,13 @@ static int test_mp_sqrt(void) {
mp_clear_multi(&a, &b, &c, &d, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, &c, &d, NULL);
return EXIT_FAILURE;
}
-static int test_mp_is_square(void) {
+static int test_mp_is_square(void)
+{
int i, n;
mp_int a, b;
@@ -680,12 +695,13 @@ static int test_mp_is_square(void) {
mp_clear_multi(&a, &b, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, NULL);
return EXIT_FAILURE;
}
-static int test_mp_sqrtmod_prime(void) {
+static int test_mp_sqrtmod_prime(void)
+{
struct mp_sqrtmod_prime_st {
unsigned long p;
unsigned long n;
@@ -721,7 +737,7 @@ static int test_mp_sqrtmod_prime(void) {
mp_clear_multi(&a, &b, &c, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, &c, NULL);
return EXIT_FAILURE;
}
@@ -751,7 +767,8 @@ static int myrng(unsigned char *dst, int len, void *dat)
return len;
}
-static int test_mp_prime_random_ex(void) {
+static int test_mp_prime_random_ex(void)
+{
int ix, err;
mp_int a, b;
@@ -779,12 +796,13 @@ static int test_mp_prime_random_ex(void) {
mp_clear_multi(&a, &b, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, NULL);
return EXIT_FAILURE;
}
-static int test_mp_prime_is_prime(void) {
+static int test_mp_prime_is_prime(void)
+{
int ix, err, cnt;
mp_int a, b;
@@ -885,13 +903,14 @@ static int test_mp_prime_is_prime(void) {
mp_clear_multi(&a, &b, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, NULL);
return EXIT_FAILURE;
}
-static int test_mp_montgomery_reduce(void) {
+static int test_mp_montgomery_reduce(void)
+{
mp_digit mp;
int ix, i, n;
char buf[4096];
@@ -948,13 +967,14 @@ static int test_mp_montgomery_reduce(void) {
mp_clear_multi(&a, &b, &c, &d, &e, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, &c, &d, &e, NULL);
return EXIT_FAILURE;
}
-static int test_mp_read_radix(void) {
+static int test_mp_read_radix(void)
+{
char buf[4096];
mp_int a;
@@ -984,7 +1004,8 @@ static int test_mp_read_radix(void) {
return EXIT_SUCCESS;
}
-static int test_mp_cnt_lsb(void) {
+static int test_mp_cnt_lsb(void)
+{
int ix;
mp_int a, b;
@@ -1003,13 +1024,14 @@ static int test_mp_cnt_lsb(void) {
mp_clear_multi(&a, &b, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, NULL);
return EXIT_FAILURE;
}
-static int test_mp_reduce_2k(void) {
+static int test_mp_reduce_2k(void)
+{
int ix, cnt;
mp_int a, b, c, d;
@@ -1046,12 +1068,13 @@ static int test_mp_reduce_2k(void) {
mp_clear_multi(&a, &b, &c, &d, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, &c, &d, NULL);
return EXIT_FAILURE;
}
-static int test_mp_div_3(void) {
+static int test_mp_div_3(void)
+{
int cnt;
mp_int a, b, c, d, e;
@@ -1081,12 +1104,13 @@ static int test_mp_div_3(void) {
mp_clear_multi(&a, &b, &c, &d, &e, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, &c, &d, &e, NULL);
return EXIT_FAILURE;
}
-static int test_mp_dr_reduce(void) {
+static int test_mp_dr_reduce(void)
+{
mp_digit mp;
int cnt;
unsigned rr;
@@ -1136,12 +1160,13 @@ static int test_mp_dr_reduce(void) {
mp_clear_multi(&a, &b, &c, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, &c, NULL);
return EXIT_FAILURE;
}
-static int test_mp_reduce_2k_l(void) {
+static int test_mp_reduce_2k_l(void)
+{
# if LTM_DEMO_TEST_REDUCE_2K_L
mp_int a, b;
if (mp_init_multi(&a, &b, NULL)!= MP_OKAY) {
@@ -1197,7 +1222,7 @@ static int test_mp_reduce_2k_l(void) {
mp_clear_multi(&a, &b, NULL);
return EXIT_SUCCESS;
- LBL_ERR:
+LBL_ERR:
mp_clear_multi(&a, &b, NULL);
return EXIT_FAILURE;
#else
@@ -1205,9 +1230,10 @@ static int test_mp_reduce_2k_l(void) {
# endif /* LTM_DEMO_TEST_REDUCE_2K_L */
}
-int unit_tests(void) {
+int unit_tests(void)
+{
static const struct {
- const char* name;
+ const char *name;
int (*fn)(void);
} test[] = {
#define T(n) { #n, test_##n }
@@ -1248,7 +1274,7 @@ int unit_tests(void) {
}
#endif
- for (i = 0; i < sizeof (test) / sizeof (test[0]); ++i) {
+ for (i = 0; i < sizeof(test) / sizeof(test[0]); ++i) {
printf("TEST %s\n\n", test[i].name);
if (test[i].fn() != EXIT_SUCCESS) {
printf("\n\nFAIL %s\n\n", test[i].name);