diff --git a/src/p25519/arch_ref64/f_impl.h b/src/p25519/arch_ref64/f_impl.h index 639826d..535abd4 100644 --- a/src/p25519/arch_ref64/f_impl.h +++ b/src/p25519/arch_ref64/f_impl.h @@ -19,17 +19,15 @@ extern "C" { /* -------------- Inline functions begin here -------------- */ void gf_add_RAW (gf out, const gf a, const gf b) { - unsigned int i; - for (i=0; i<5; i++) { + for (unsigned int i=0; i<5; i++) { out->limb[i] = a->limb[i] + b->limb[i]; } gf_weak_reduce(out); } void gf_sub_RAW (gf out, const gf a, const gf b) { - unsigned int i; uint64_t co1 = ((1ull<<51)-1)*2, co2 = co1-36; - for (i=0; i<5; i++) { + for (unsigned int i=0; i<5; i++) { out->limb[i] = a->limb[i] - b->limb[i] + ((i==0) ? co2 : co1); } gf_weak_reduce(out); @@ -43,8 +41,7 @@ void gf_bias (gf a, int amt) { void gf_weak_reduce (gf a) { uint64_t mask = (1ull<<51) - 1; uint64_t tmp = a->limb[4] >> 51; - int i; - for (i=4; i>0; i--) { + for (unsigned int i=4; i>0; i--) { a->limb[i] = (a->limb[i] & mask) + (a->limb[i-1]>>51); } a->limb[0] = (a->limb[0] & mask) + tmp*19; diff --git a/src/p25519/arch_x86_64/f_impl.h b/src/p25519/arch_x86_64/f_impl.h index 1b89171..5f093c6 100644 --- a/src/p25519/arch_x86_64/f_impl.h +++ b/src/p25519/arch_x86_64/f_impl.h @@ -15,24 +15,20 @@ /* -------------- Inline functions begin here -------------- */ void gf_add_RAW (gf out, const gf a, const gf b) { - unsigned int i; - for (i=0; i<5; i++) { + for (unsigned int i=0; i<5; i++) { out->limb[i] = a->limb[i] + b->limb[i]; } } void gf_sub_RAW (gf out, const gf a, const gf b) { - unsigned int i; - uint64_t co1 = ((1ull<<51)-1)*2, co2 = co1-36; - for (i=0; i<5; i++) { - out->limb[i] = a->limb[i] - b->limb[i] + ((i==0) ? co2 : co1); + for (unsigned int i=0; i<5; i++) { + out->limb[i] = a->limb[i] - b->limb[i]; } } void gf_bias (gf a, int amt) { a->limb[0] += ((uint64_t)(amt)<<52) - 38*amt; - int i; - for (i=1; i<5; i++) { + for (unsigned int i=1; i<5; i++) { a->limb[i] += ((uint64_t)(amt)<<52)-2*amt; } } @@ -40,8 +36,7 @@ void gf_bias (gf a, int amt) { void gf_weak_reduce (gf a) { uint64_t mask = (1ull<<51) - 1; uint64_t tmp = a->limb[4] >> 51; - int i; - for (i=4; i>0; i--) { + for (unsigned int i=4; i>0; i--) { a->limb[i] = (a->limb[i] & mask) + (a->limb[i-1]>>51); } a->limb[0] = (a->limb[0] & mask) + tmp*19; diff --git a/src/p448/arch_32/f_impl.h b/src/p448/arch_32/f_impl.h index d6abb12..1c4d182 100644 --- a/src/p448/arch_32/f_impl.h +++ b/src/p448/arch_32/f_impl.h @@ -20,8 +20,7 @@ extern "C" { /* -------------- Inline functions begin here -------------- */ void gf_add_RAW (gf out, const gf a, const gf b) { - unsigned int i; - for (i=0; ilimb[15] >> 28; - int i; a->limb[8] += tmp; - for (i=15; i>0; i--) { + for (unsigned int i=15; i>0; i--) { a->limb[i] = (a->limb[i] & mask) + (a->limb[i-1]>>28); } a->limb[0] = (a->limb[0] & mask) + tmp; diff --git a/src/p448/arch_arm_32/f_impl.h b/src/p448/arch_arm_32/f_impl.h index d6abb12..37d8d94 100644 --- a/src/p448/arch_arm_32/f_impl.h +++ b/src/p448/arch_arm_32/f_impl.h @@ -20,26 +20,22 @@ extern "C" { /* -------------- Inline functions begin here -------------- */ void gf_add_RAW (gf out, const gf a, const gf b) { - unsigned int i; - for (i=0; ilimb[0]); i++) { + for (unsigned int i=0; ilimb[0]); i++) { out->limb[i] = a->limb[i] + b->limb[i]; } */ } void gf_sub_RAW (gf out, const gf a, const gf b) { - unsigned int i; - for (i=0; ilimb[0]); i++) { + for (unsigned int i=0; ilimb[0]); i++) { out->limb[i] = a->limb[i] - b->limb[i]; } */ @@ -58,9 +54,8 @@ void gf_bias (gf a, int amt) { void gf_weak_reduce (gf a) { uint64_t mask = (1ull<<28) - 1; uint64_t tmp = a->limb[15] >> 28; - int i; a->limb[8] += tmp; - for (i=15; i>0; i--) { + for (unsigned int i=15; i>0; i--) { a->limb[i] = (a->limb[i] & mask) + (a->limb[i-1]>>28); } a->limb[0] = (a->limb[0] & mask) + tmp; diff --git a/src/p448/arch_neon_experimental/f_impl.h b/src/p448/arch_neon_experimental/f_impl.h index 2ed616b..ca99cbb 100644 --- a/src/p448/arch_neon_experimental/f_impl.h +++ b/src/p448/arch_neon_experimental/f_impl.h @@ -26,15 +26,13 @@ extern "C" { /* -------------- Inline functions begin here -------------- */ void gf_add_RAW (gf out, const gf a, const gf b) { - unsigned int i; - for (i=0; i=1; i--) { + for (unsigned int i=7; i>=1; i--) { aa[i] = vsra_n_u32(aa[i] & vmask, aa[i-1], 28); } aa[0] = (aa[0] & vmask) + vrev64_u32(tmp) + (tmp&vm2); diff --git a/src/p448/arch_ref64/f_impl.h b/src/p448/arch_ref64/f_impl.h index 0f9af8b..228df96 100644 --- a/src/p448/arch_ref64/f_impl.h +++ b/src/p448/arch_ref64/f_impl.h @@ -19,17 +19,15 @@ extern "C" { /* -------------- Inline functions begin here -------------- */ void gf_add_RAW (gf out, const gf a, const gf b) { - unsigned int i; - for (i=0; i<8; i++) { + for (unsigned int i=0; i<8; i++) { out->limb[i] = a->limb[i] + b->limb[i]; } gf_weak_reduce(out); } void gf_sub_RAW (gf out, const gf a, const gf b) { - unsigned int i; uint64_t co1 = ((1ull<<56)-1)*2, co2 = co1-2; - for (i=0; i<8; i++) { + for (unsigned int i=0; i<8; i++) { out->limb[i] = a->limb[i] - b->limb[i] + ((i==4) ? co2 : co1); } gf_weak_reduce(out); @@ -43,9 +41,8 @@ void gf_bias (gf a, int amt) { void gf_weak_reduce (gf a) { uint64_t mask = (1ull<<56) - 1; uint64_t tmp = a->limb[7] >> 56; - int i; a->limb[4] += tmp; - for (i=7; i>0; i--) { + for (unsigned int i=7; i>0; i--) { a->limb[i] = (a->limb[i] & mask) + (a->limb[i-1]>>56); } a->limb[0] = (a->limb[0] & mask) + tmp; diff --git a/src/p448/arch_x86_64/f_impl.h b/src/p448/arch_x86_64/f_impl.h index 8f1b40c..12f8118 100644 --- a/src/p448/arch_x86_64/f_impl.h +++ b/src/p448/arch_x86_64/f_impl.h @@ -18,8 +18,7 @@ extern "C" { /* -------------- Inline functions begin here -------------- */ void gf_add_RAW (gf out, const gf a, const gf b) { - unsigned int i; - for (i=0; ilimb[i] += (i==4) ? co2 : co1; } #endif @@ -70,9 +67,8 @@ void gf_weak_reduce (gf a) { /* PERF: use pshufb/palignr if anyone cares about speed of this */ uint64_t mask = (1ull<<56) - 1; uint64_t tmp = a->limb[7] >> 56; - int i; a->limb[4] += tmp; - for (i=7; i>0; i--) { + for (unsigned int i=7; i>0; i--) { a->limb[i] = (a->limb[i] & mask) + (a->limb[i-1]>>56); } a->limb[0] = (a->limb[0] & mask) + tmp; diff --git a/src/p480/arch_x86_64/f_impl.h b/src/p480/arch_x86_64/f_impl.h index 7c1867c..ef94c3b 100644 --- a/src/p480/arch_x86_64/f_impl.h +++ b/src/p480/arch_x86_64/f_impl.h @@ -18,8 +18,7 @@ extern "C" { /* -------------- Inline functions begin here -------------- */ void gf_add_RAW (gf *out, const gf *a, const gf *b) { - unsigned int i; - for (i=0; ilimb[i] += (i==4) ? co2 : co1; } #endif @@ -79,9 +75,8 @@ void gf_weak_reduce (gf *a) { /* PERF: use pshufb/palignr if anyone cares about speed of this */ uint64_t mask = (1ull<<60) - 1; uint64_t tmp = a->limb[7] >> 60; - int i; a->limb[4] += tmp; - for (i=7; i>0; i--) { + for (unsigned int i=7; i>0; i--) { a->limb[i] = (a->limb[i] & mask) + (a->limb[i-1]>>60); } a->limb[0] = (a->limb[0] & mask) + tmp; diff --git a/src/p521/arch_ref64/f_impl.h b/src/p521/arch_ref64/f_impl.h index ddb784f..679b6fa 100644 --- a/src/p521/arch_ref64/f_impl.h +++ b/src/p521/arch_ref64/f_impl.h @@ -17,17 +17,15 @@ extern "C" { /* -------------- Inline functions begin here -------------- */ void gf_add_RAW (gf *out, const gf *a, const gf *b) { - unsigned int i; - for (i=0; i<9; i++) { + for (unsigned int i=0; i<9; i++) { out->limb[i] = a->limb[i] + b->limb[i]; } gf_weak_reduce(out); } void gf_sub_RAW (gf *out, const gf *a, const gf *b) { - unsigned int i; uint64_t co1 = ((1ull<<58)-1)*4, co2 = ((1ull<<57)-1)*4; - for (i=0; i<9; i++) { + for (unsigned int i=0; i<9; i++) { out->limb[i] = a->limb[i] - b->limb[i] + ((i==8) ? co2 : co1); } gf_weak_reduce(out); @@ -41,8 +39,7 @@ void gf_bias (gf *a, int amt) { void gf_weak_reduce (gf *a) { uint64_t mask = (1ull<<58) - 1; uint64_t tmp = a->limb[8] >> 57; - int i; - for (i=8; i>0; i--) { + for (unsigned int i=8; i>0; i--) { a->limb[i] = (a->limb[i] & ((i==8) ? mask>>1 : mask)) + (a->limb[i-1]>>58); } a->limb[0] = (a->limb[0] & mask) + tmp; diff --git a/src/p521/arch_x86_64_r12/f_impl.h b/src/p521/arch_x86_64_r12/f_impl.h index 6dce421..c5883aa 100644 --- a/src/p521/arch_x86_64_r12/f_impl.h +++ b/src/p521/arch_x86_64_r12/f_impl.h @@ -32,15 +32,13 @@ static inline uint64x3_t timesW (uint64x3_t u) { } void gf_add_RAW (gf *out, const gf *a, const gf *b) { - unsigned int i; - for (i=0; i