small improvement for inversion

master
pmvr 2020-06-14 16:30:49 +02:00
parent 36be90765d
commit 7cd252c6de
2 changed files with 11 additions and 13 deletions

View File

@ -41,15 +41,15 @@ Python script `x25519.py`
Python script `ed25519.py`
Test 1: Length of message: 0 bytes
Computation time: 53 ms
Computation time: 52 ms
Test 1 passed.
Test 2: Length of message: 1 byte
Computation time: 53 ms
Computation time: 52 ms
Test 2 passed.
Test 3: Length of message: 2 bytes
Computation time: 53 ms
Computation time: 52 ms
Test 3 passed.
Test 4: Length of message: 1023 bytes

View File

@ -104,7 +104,8 @@ STEP_4:
shift_right(D);
}
sub9_zxy(u, u, v);
if ((u[8] & 0x80000000) == 0) { // u >= v
if ((u[8] & 0x80000000) == 0) {
// u >= v
sub9_zxy(B, B, D);
}
else {
@ -112,16 +113,13 @@ STEP_4:
sub9_zxy(v, v, u);
sub9_zxy(D, D, B);
}
uint32_t cmp = 0;
for (int i=0; i<9; i++) cmp |= u[i];
if (cmp == 0) {
if (D[8] & 0x80000000) {
add9_zxy(D, D, m); // D < 0
}
for (uint32_t i=0; i<8; i++) y[i] = D[i];
return;
for (uint32_t i=0; i<9; i++) {
if (u[i] != 0) goto STEP_4;
}
goto STEP_4;
if (D[8] & 0x80000000) {
add9_zxy(D, D, m); // D < 0
}
for (uint32_t i=0; i<8; i++) y[i] = D[i];
}