mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 09:58:01 +00:00
Enhance Diffie-Hellman implementation to use bignum_cmp
[originally from svn r762]
This commit is contained in:
parent
809bd81d5c
commit
38e7de3372
27
sshdh.c
27
sshdh.c
@ -68,33 +68,14 @@ Bignum dh_create_e(void) {
|
|||||||
|
|
||||||
x = newbn(Q[0]);
|
x = newbn(Q[0]);
|
||||||
|
|
||||||
tryagain:
|
do {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a potential x, by ANDing a string of random bytes
|
* Create a potential x, by ANDing a string of random bytes
|
||||||
* with Qmask.
|
* with Qmask.
|
||||||
*/
|
*/
|
||||||
for (i = 1; i <= x[0]; i++)
|
for (i = 1; i <= x[0]; i++)
|
||||||
x[i] = ((random_byte() << 8) + random_byte()) & Qmask[i];
|
x[i] = ((random_byte() << 8) + random_byte()) & Qmask[i];
|
||||||
|
} while (bignum_cmp(x, One) <= 0 || bignum_cmp(x, Q) >= 0);
|
||||||
/*
|
|
||||||
* If x <= 1, go round again.
|
|
||||||
*/
|
|
||||||
for (i = 2; i <= x[0]; i++)
|
|
||||||
if (x[i] != 0)
|
|
||||||
break;
|
|
||||||
if (i > x[0] && x[1] <= 1)
|
|
||||||
goto tryagain;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If x >= q, go round again.
|
|
||||||
*/
|
|
||||||
for (i = x[0]; i > 0; i--) {
|
|
||||||
if (x[i] > Q[i])
|
|
||||||
goto tryagain;
|
|
||||||
if (x[i] < Q[i])
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Done. Now compute e = g^x mod p.
|
* Done. Now compute e = g^x mod p.
|
||||||
@ -108,7 +89,5 @@ Bignum dh_create_e(void) {
|
|||||||
* DH stage 2: given a number f, compute K = f^x mod p.
|
* DH stage 2: given a number f, compute K = f^x mod p.
|
||||||
*/
|
*/
|
||||||
Bignum dh_find_K(Bignum f) {
|
Bignum dh_find_K(Bignum f) {
|
||||||
Bignum K = newbn(P[0]);
|
return modpow(f, x, P);
|
||||||
K = modpow(f, x, P);
|
|
||||||
return K;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user