Skip to content

Commit b5ec204

Browse files
committed
SP non-block ECC: correct mont_inv_order
Was not doing last bit but result still worked (likely because it was the square root).
1 parent 86db2d4 commit b5ec204

7 files changed

Lines changed: 24 additions & 24 deletions

File tree

wolfcrypt/src/sp_arm32.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79156,7 +79156,7 @@ static int sp_256_mont_inv_order_8_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
7915679156
sp_256_mont_mul_order_8(t, t, a);
7915779157
}
7915879158
ctx->i--;
79159-
ctx->state = (ctx->i == 0) ? 3 : 1;
79159+
ctx->state = (ctx->i >= 0) ? 1 : 3;
7916079160
break;
7916179161
case 3:
7916279162
XMEMCPY(r, t, sizeof(sp_digit) * 8U);
@@ -97352,7 +97352,7 @@ static int sp_384_mont_inv_order_12_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const
9735297352
sp_384_mont_mul_order_12(t, t, a);
9735397353
}
9735497354
ctx->i--;
97355-
ctx->state = (ctx->i == 0) ? 3 : 1;
97355+
ctx->state = (ctx->i >= 0) ? 1 : 3;
9735697356
break;
9735797357
case 3:
9735897358
XMEMCPY(r, t, sizeof(sp_digit) * 12U);
@@ -125751,7 +125751,7 @@ static int sp_521_mont_inv_order_17_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const
125751125751
sp_521_mont_mul_order_17(t, t, a);
125752125752
}
125753125753
ctx->i--;
125754-
ctx->state = (ctx->i == 0) ? 3 : 1;
125754+
ctx->state = (ctx->i >= 0) ? 1 : 3;
125755125755
break;
125756125756
case 3:
125757125757
XMEMCPY(r, t, sizeof(sp_digit) * 17U);

wolfcrypt/src/sp_arm64.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40410,7 +40410,7 @@ static int sp_256_mont_inv_order_4_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
4041040410
sp_256_mont_mul_order_4(t, t, a);
4041140411
}
4041240412
ctx->i--;
40413-
ctx->state = (ctx->i == 0) ? 3 : 1;
40413+
ctx->state = (ctx->i >= 0) ? 1 : 3;
4041440414
break;
4041540415
case 3:
4041640416
XMEMCPY(r, t, sizeof(sp_digit) * 4U);
@@ -66248,7 +66248,7 @@ static int sp_384_mont_inv_order_6_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
6624866248
sp_384_mont_mul_order_6(t, t, a);
6624966249
}
6625066250
ctx->i--;
66251-
ctx->state = (ctx->i == 0) ? 3 : 1;
66251+
ctx->state = (ctx->i >= 0) ? 1 : 3;
6625266252
break;
6625366253
case 3:
6625466254
XMEMCPY(r, t, sizeof(sp_digit) * 6U);
@@ -110714,7 +110714,7 @@ static int sp_521_mont_inv_order_9_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
110714110714
sp_521_mont_mul_order_9(t, t, a);
110715110715
}
110716110716
ctx->i--;
110717-
ctx->state = (ctx->i == 0) ? 3 : 1;
110717+
ctx->state = (ctx->i >= 0) ? 1 : 3;
110718110718
break;
110719110719
case 3:
110720110720
XMEMCPY(r, t, sizeof(sp_digit) * 9U);

wolfcrypt/src/sp_armthumb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104906,7 +104906,7 @@ static int sp_256_mont_inv_order_8_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
104906104906
sp_256_mont_mul_order_8(t, t, a);
104907104907
}
104908104908
ctx->i--;
104909-
ctx->state = (ctx->i == 0) ? 3 : 1;
104909+
ctx->state = (ctx->i >= 0) ? 1 : 3;
104910104910
break;
104911104911
case 3:
104912104912
XMEMCPY(r, t, sizeof(sp_digit) * 8U);
@@ -115433,7 +115433,7 @@ static int sp_384_mont_inv_order_12_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const
115433115433
sp_384_mont_mul_order_12(t, t, a);
115434115434
}
115435115435
ctx->i--;
115436-
ctx->state = (ctx->i == 0) ? 3 : 1;
115436+
ctx->state = (ctx->i >= 0) ? 1 : 3;
115437115437
break;
115438115438
case 3:
115439115439
XMEMCPY(r, t, sizeof(sp_digit) * 12U);
@@ -130970,7 +130970,7 @@ static int sp_521_mont_inv_order_17_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const
130970130970
sp_521_mont_mul_order_17(t, t, a);
130971130971
}
130972130972
ctx->i--;
130973-
ctx->state = (ctx->i == 0) ? 3 : 1;
130973+
ctx->state = (ctx->i >= 0) ? 1 : 3;
130974130974
break;
130975130975
case 3:
130976130976
XMEMCPY(r, t, sizeof(sp_digit) * 17U);

wolfcrypt/src/sp_c32.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23764,7 +23764,7 @@ static int sp_256_mont_inv_order_9_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
2376423764
sp_256_mont_mul_order_9(t, t, a);
2376523765
}
2376623766
ctx->i--;
23767-
ctx->state = (ctx->i == 0) ? 3 : 1;
23767+
ctx->state = (ctx->i >= 0) ? 1 : 3;
2376823768
break;
2376923769
case 3:
2377023770
XMEMCPY(r, t, sizeof(sp_digit) * 9U);
@@ -31437,7 +31437,7 @@ static int sp_384_mont_inv_order_15_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const
3143731437
sp_384_mont_mul_order_15(t, t, a);
3143831438
}
3143931439
ctx->i--;
31440-
ctx->state = (ctx->i == 0) ? 3 : 1;
31440+
ctx->state = (ctx->i >= 0) ? 1 : 3;
3144131441
break;
3144231442
case 3:
3144331443
XMEMCPY(r, t, sizeof(sp_digit) * 15U);
@@ -39151,7 +39151,7 @@ static int sp_521_mont_inv_order_21_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const
3915139151
sp_521_mont_mul_order_21(t, t, a);
3915239152
}
3915339153
ctx->i--;
39154-
ctx->state = (ctx->i == 0) ? 3 : 1;
39154+
ctx->state = (ctx->i >= 0) ? 1 : 3;
3915539155
break;
3915639156
case 3:
3915739157
XMEMCPY(r, t, sizeof(sp_digit) * 21U);

wolfcrypt/src/sp_c64.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24243,7 +24243,7 @@ static int sp_256_mont_inv_order_5_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
2424324243
sp_256_mont_mul_order_5(t, t, a);
2424424244
}
2424524245
ctx->i--;
24246-
ctx->state = (ctx->i == 0) ? 3 : 1;
24246+
ctx->state = (ctx->i >= 0) ? 1 : 3;
2424724247
break;
2424824248
case 3:
2424924249
XMEMCPY(r, t, sizeof(sp_digit) * 5U);
@@ -31307,7 +31307,7 @@ static int sp_384_mont_inv_order_7_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
3130731307
sp_384_mont_mul_order_7(t, t, a);
3130831308
}
3130931309
ctx->i--;
31310-
ctx->state = (ctx->i == 0) ? 3 : 1;
31310+
ctx->state = (ctx->i >= 0) ? 1 : 3;
3131131311
break;
3131231312
case 3:
3131331313
XMEMCPY(r, t, sizeof(sp_digit) * 7U);
@@ -38335,7 +38335,7 @@ static int sp_521_mont_inv_order_9_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
3833538335
sp_521_mont_mul_order_9(t, t, a);
3833638336
}
3833738337
ctx->i--;
38338-
ctx->state = (ctx->i == 0) ? 3 : 1;
38338+
ctx->state = (ctx->i >= 0) ? 1 : 3;
3833938339
break;
3834038340
case 3:
3834138341
XMEMCPY(r, t, sizeof(sp_digit) * 9U);

wolfcrypt/src/sp_cortexm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40196,7 +40196,7 @@ static int sp_256_mont_inv_order_8_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
4019640196
sp_256_mont_mul_order_8(t, t, a);
4019740197
}
4019840198
ctx->i--;
40199-
ctx->state = (ctx->i == 0) ? 3 : 1;
40199+
ctx->state = (ctx->i >= 0) ? 1 : 3;
4020040200
break;
4020140201
case 3:
4020240202
XMEMCPY(r, t, sizeof(sp_digit) * 8U);
@@ -50204,7 +50204,7 @@ static int sp_384_mont_inv_order_12_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const
5020450204
sp_384_mont_mul_order_12(t, t, a);
5020550205
}
5020650206
ctx->i--;
50207-
ctx->state = (ctx->i == 0) ? 3 : 1;
50207+
ctx->state = (ctx->i >= 0) ? 1 : 3;
5020850208
break;
5020950209
case 3:
5021050210
XMEMCPY(r, t, sizeof(sp_digit) * 12U);
@@ -63152,7 +63152,7 @@ static int sp_521_mont_inv_order_17_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const
6315263152
sp_521_mont_mul_order_17(t, t, a);
6315363153
}
6315463154
ctx->i--;
63155-
ctx->state = (ctx->i == 0) ? 3 : 1;
63155+
ctx->state = (ctx->i >= 0) ? 1 : 3;
6315663156
break;
6315763157
case 3:
6315863158
XMEMCPY(r, t, sizeof(sp_digit) * 17U);

wolfcrypt/src/sp_x86_64.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24382,7 +24382,7 @@ static int sp_256_mont_inv_order_4_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
2438224382
sp_256_mont_mul_order_4(t, t, a);
2438324383
}
2438424384
ctx->i--;
24385-
ctx->state = (ctx->i == 0) ? 3 : 1;
24385+
ctx->state = (ctx->i >= 0) ? 1 : 3;
2438624386
break;
2438724387
case 3:
2438824388
XMEMCPY(r, t, sizeof(sp_digit) * 4U);
@@ -24605,7 +24605,7 @@ static int sp_256_mont_inv_order_avx2_4_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, co
2460524605
sp_256_mont_mul_order_avx2_4(t, t, a);
2460624606
}
2460724607
ctx->i--;
24608-
ctx->state = (ctx->i == 0) ? 3 : 1;
24608+
ctx->state = (ctx->i >= 0) ? 1 : 3;
2460924609
break;
2461024610
case 3:
2461124611
XMEMCPY(r, t, sizeof(sp_digit) * 4U);
@@ -48945,7 +48945,7 @@ static int sp_384_mont_inv_order_6_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
4894548945
sp_384_mont_mul_order_6(t, t, a);
4894648946
}
4894748947
ctx->i--;
48948-
ctx->state = (ctx->i == 0) ? 3 : 1;
48948+
ctx->state = (ctx->i >= 0) ? 1 : 3;
4894948949
break;
4895048950
case 3:
4895148951
XMEMCPY(r, t, sizeof(sp_digit) * 6U);
@@ -49101,7 +49101,7 @@ static int sp_384_mont_inv_order_avx2_6_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, co
4910149101
sp_384_mont_mul_order_avx2_6(t, t, a);
4910249102
}
4910349103
ctx->i--;
49104-
ctx->state = (ctx->i == 0) ? 3 : 1;
49104+
ctx->state = (ctx->i >= 0) ? 1 : 3;
4910549105
break;
4910649106
case 3:
4910749107
XMEMCPY(r, t, sizeof(sp_digit) * 6U);
@@ -89615,7 +89615,7 @@ static int sp_521_mont_inv_order_9_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
8961589615
sp_521_mont_mul_order_9(t, t, a);
8961689616
}
8961789617
ctx->i--;
89618-
ctx->state = (ctx->i == 0) ? 3 : 1;
89618+
ctx->state = (ctx->i >= 0) ? 1 : 3;
8961989619
break;
8962089620
case 3:
8962189621
XMEMCPY(r, t, sizeof(sp_digit) * 9U);
@@ -89784,7 +89784,7 @@ static int sp_521_mont_inv_order_avx2_9_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, co
8978489784
sp_521_mont_mul_order_avx2_9(t, t, a);
8978589785
}
8978689786
ctx->i--;
89787-
ctx->state = (ctx->i == 0) ? 3 : 1;
89787+
ctx->state = (ctx->i >= 0) ? 1 : 3;
8978889788
break;
8978989789
case 3:
8979089790
XMEMCPY(r, t, sizeof(sp_digit) * 9U);

0 commit comments

Comments
 (0)