Skip to content

Commit 1c329f3

Browse files
vil02Legrandin
authored andcommitted
Reduce scope of loop variables in ec_ws.c
1 parent da4a134 commit 1c329f3

File tree

1 file changed

+16
-35
lines changed

1 file changed

+16
-35
lines changed

src/ec_ws.c

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ FAKE_INIT(ec_ws)
4949
#ifdef MAIN
5050
STATIC void print_x(const char *s, const uint64_t *number, const MontContext *ctx)
5151
{
52-
unsigned i;
5352
size_t size;
5453
uint8_t *encoded;
5554
int res;
@@ -60,7 +59,7 @@ STATIC void print_x(const char *s, const uint64_t *number, const MontContext *ct
6059
assert(res == 0);
6160

6261
printf("%s: ", s);
63-
for (i=0; i<size; i++)
62+
for (unsigned i=0; i<size; ++i)
6463
printf("%02X", encoded[i]);
6564
printf("\n");
6665

@@ -571,32 +570,26 @@ STATIC int ec_scalar(uint64_t *x3, uint64_t *y3, uint64_t *z3,
571570

572571
STATIC void free_g_p256(ProtMemory **prot_g)
573572
{
574-
unsigned i;
575-
576573
if (prot_g) {
577-
for (i=0; i<p256_n_tables; i++)
574+
for (unsigned i=0; i<p256_n_tables; ++i)
578575
free_scattered(prot_g[i]);
579576
free(prot_g);
580577
}
581578
}
582579

583580
STATIC void free_g_p384(ProtMemory **prot_g)
584581
{
585-
unsigned i;
586-
587582
if (prot_g) {
588-
for (i=0; i<p384_n_tables; i++)
583+
for (unsigned i=0; i<p384_n_tables; ++i)
589584
free_scattered(prot_g[i]);
590585
free(prot_g);
591586
}
592587
}
593588

594589
STATIC void free_g_p521(ProtMemory **prot_g)
595590
{
596-
unsigned i;
597-
598591
if (prot_g) {
599-
for (i=0; i<p521_n_tables; i++)
592+
for (unsigned i=0; i<p521_n_tables; ++i)
600593
free_scattered(prot_g[i]);
601594
free(prot_g);
602595
}
@@ -609,7 +602,6 @@ STATIC ProtMemory** ec_scramble_g_p256(const MontContext *ctx, uint64_t seed)
609602
{
610603
const void **tables_ptrs;
611604
ProtMemory **prot_g;
612-
unsigned i;
613605
int res;
614606

615607
tables_ptrs = (const void**)calloc(p256_points_per_table, sizeof(void*));
@@ -623,7 +615,7 @@ STATIC ProtMemory** ec_scramble_g_p256(const MontContext *ctx, uint64_t seed)
623615
}
624616

625617
res = 0;
626-
for (i=0; res==0 && i<p256_n_tables; i++) {
618+
for (unsigned i=0; res==0 && i<p256_n_tables; ++i) {
627619
unsigned j;
628620

629621
for (j=0; j<p256_points_per_table; j++) {
@@ -648,7 +640,6 @@ STATIC ProtMemory** ec_scramble_g_p384(const MontContext *ctx, uint64_t seed)
648640
{
649641
const void **tables_ptrs;
650642
ProtMemory **prot_g;
651-
unsigned i;
652643
int res;
653644

654645
tables_ptrs = (const void**)calloc(p384_points_per_table, sizeof(void*));
@@ -662,7 +653,7 @@ STATIC ProtMemory** ec_scramble_g_p384(const MontContext *ctx, uint64_t seed)
662653
}
663654

664655
res = 0;
665-
for (i=0; res==0 && i<p384_n_tables; i++) {
656+
for (unsigned i=0; res==0 && i<p384_n_tables; ++i) {
666657
unsigned j;
667658

668659
for (j=0; j<p384_points_per_table; j++) {
@@ -687,7 +678,6 @@ STATIC ProtMemory** ec_scramble_g_p521(const MontContext *ctx, uint64_t seed)
687678
{
688679
const void **tables_ptrs;
689680
ProtMemory **prot_g;
690-
unsigned i;
691681
int res;
692682

693683
tables_ptrs = (const void**)calloc(p521_points_per_table, sizeof(void*));
@@ -701,7 +691,7 @@ STATIC ProtMemory** ec_scramble_g_p521(const MontContext *ctx, uint64_t seed)
701691
}
702692

703693
res = 0;
704-
for (i=0; res==0 && i<p521_n_tables; i++) {
694+
for (unsigned i=0; res==0 && i<p521_n_tables; ++i) {
705695
unsigned j;
706696

707697
for (j=0; j<p521_points_per_table; j++) {
@@ -728,7 +718,6 @@ STATIC int ec_scalar_g_p256(uint64_t *x3, uint64_t *y3, uint64_t *z3,
728718
ProtMemory **prot_g,
729719
const MontContext *ctx)
730720
{
731-
unsigned i;
732721
struct BitWindow_RL bw;
733722

734723
/** Start from PAI **/
@@ -743,7 +732,7 @@ STATIC int ec_scalar_g_p256(uint64_t *x3, uint64_t *y3, uint64_t *z3,
743732
if (bw.nr_windows > p256_n_tables)
744733
return ERR_VALUE;
745734

746-
for (i=0; i < bw.nr_windows; i++) {
735+
for (unsigned i=0; i < bw.nr_windows; ++i) {
747736
unsigned index;
748737
uint64_t buffer[4*2]; /* X and Y affine coordinates **/
749738
uint64_t *xw, *yw;
@@ -771,7 +760,6 @@ STATIC int ec_scalar_g_p384(uint64_t *x3, uint64_t *y3, uint64_t *z3,
771760
ProtMemory **prot_g,
772761
const MontContext *ctx)
773762
{
774-
unsigned i;
775763
struct BitWindow_RL bw;
776764

777765
/** Start from PAI **/
@@ -786,7 +774,7 @@ STATIC int ec_scalar_g_p384(uint64_t *x3, uint64_t *y3, uint64_t *z3,
786774
if (bw.nr_windows > p384_n_tables)
787775
return ERR_VALUE;
788776

789-
for (i=0; i < bw.nr_windows; i++) {
777+
for (unsigned i=0; i < bw.nr_windows; ++i) {
790778
unsigned index;
791779
uint64_t buffer[6*2]; /* X and Y affine coordinates **/
792780
uint64_t *xw, *yw;
@@ -815,7 +803,6 @@ STATIC int ec_scalar_g_p521(uint64_t *x3, uint64_t *y3, uint64_t *z3,
815803
ProtMemory **prot_g,
816804
const MontContext *ctx)
817805
{
818-
unsigned i;
819806
struct BitWindow_RL bw;
820807

821808
/** Start from PAI **/
@@ -848,7 +835,7 @@ STATIC int ec_scalar_g_p521(uint64_t *x3, uint64_t *y3, uint64_t *z3,
848835
if (bw.nr_windows > p521_n_tables)
849836
return ERR_VALUE;
850837

851-
for (i=0; i < bw.nr_windows; i++) {
838+
for (unsigned i=0; i < bw.nr_windows; ++i) {
852839
unsigned index;
853840
uint64_t buffer[9*2]; /* X and Y affine coordinates **/
854841
uint64_t *xw, *yw;
@@ -1273,11 +1260,9 @@ EXPORT_SYM int ec_ws_scalar(EcPoint *ecp, const uint8_t *k, size_t len, uint64_t
12731260
/** Coordinates in Montgomery form **/
12741261
const uint64_t mont_Gx[4] = { 0x79E730D418A9143CULL, 0x75BA95FC5FEDB601ULL, 0x79FB732B77622510ULL, 0x18905F76A53755C6ULL };
12751262
const uint64_t mont_Gy[4] = { 0xDDF25357CE95560AULL, 0x8B4AB8E4BA19E45CULL, 0xD2E88688DD21F325ULL, 0x8571FF1825885D85ULL };
1276-
unsigned is_generator;
1277-
unsigned i;
1263+
unsigned is_generator = 1;
12781264

1279-
is_generator = 1;
1280-
for (i=0; i<4; i++) {
1265+
for (unsigned i=0; i<4; ++i) {
12811266
is_generator &= (mont_Gx[i] == ecp->x[i]);
12821267
is_generator &= (mont_Gy[i] == ecp->y[i]);
12831268
}
@@ -1299,11 +1284,9 @@ EXPORT_SYM int ec_ws_scalar(EcPoint *ecp, const uint8_t *k, size_t len, uint64_t
12991284
/** Coordinates in Montgomery form **/
13001285
const uint64_t mont_Gx[6] = { 0x3DD0756649C0B528ULL, 0x20E378E2A0D6CE38ULL, 0x879C3AFC541B4D6EULL, 0x6454868459A30EFFULL, 0x812FF723614EDE2BULL, 0x4D3AADC2299E1513ULL };
13011286
const uint64_t mont_Gy[6] = { 0x23043DAD4B03A4FEULL, 0xA1BFA8BF7BB4A9ACULL, 0x8BADE7562E83B050ULL, 0xC6C3521968F4FFD9ULL, 0xDD8002263969A840ULL, 0x2B78ABC25A15C5E9ULL };
1302-
unsigned is_generator;
1303-
unsigned i;
1287+
unsigned is_generator = 1;
13041288

1305-
is_generator = 1;
1306-
for (i=0; i<6; i++) {
1289+
for (unsigned i=0; i<6; ++i) {
13071290
is_generator &= (mont_Gx[i] == ecp->x[i]);
13081291
is_generator &= (mont_Gy[i] == ecp->y[i]);
13091292
}
@@ -1325,11 +1308,9 @@ EXPORT_SYM int ec_ws_scalar(EcPoint *ecp, const uint8_t *k, size_t len, uint64_t
13251308
/** Coordinates in normal form **/
13261309
const uint64_t mont_Gx[9] = { 0xF97E7E31C2E5BD66ULL, 0x3348B3C1856A429BULL, 0xFE1DC127A2FFA8DEULL, 0xA14B5E77EFE75928ULL, 0xF828AF606B4D3DBAULL, 0x9C648139053FB521ULL, 0x9E3ECB662395B442ULL, 0x858E06B70404E9CDULL, 0x00000000000000C6ULL };
13271310
const uint64_t mont_Gy[9] = { 0x88BE94769FD16650ULL, 0x353C7086A272C240ULL, 0xC550B9013FAD0761ULL, 0x97EE72995EF42640ULL, 0x17AFBD17273E662CULL, 0x98F54449579B4468ULL, 0x5C8A5FB42C7D1BD9ULL, 0x39296A789A3BC004ULL, 0x0000000000000118ULL };
1328-
unsigned is_generator;
1329-
unsigned i;
1311+
unsigned is_generator = 1;
13301312

1331-
is_generator = 1;
1332-
for (i=0; i<9; i++) {
1313+
for (unsigned i=0; i<9; ++i) {
13331314
is_generator &= (mont_Gx[i] == ecp->x[i]);
13341315
is_generator &= (mont_Gy[i] == ecp->y[i]);
13351316
}

0 commit comments

Comments
 (0)