ref: bbce9c0566da28911f0ce444d0fdca0fe4eb77b9
parent: 5256f4063e381bb7a6f175ea397202e93f8be4b1
author: cinap_lenrek <[email protected]>
date: Sun Feb 5 23:25:38 EST 2017
rsagen: prefer 65537 as the default exponent when elen == 0, otherwise pick randomly
--- a/sys/src/cmd/auth/rsagen.c
+++ b/sys/src/cmd/auth/rsagen.c
@@ -42,7 +42,7 @@
do{
if(key)
rsaprivfree(key);
- key = rsagen(bits, 6, 0);
+ key = rsagen(bits, 0, 0);
}while(mpsignif(key->pub.n) != bits);
s = smprint("key proto=rsa %s%ssize=%d ek=%B !dk=%B n=%B !p=%B !q=%B !kp=%B !kq=%B !c2=%B\n",
--- a/sys/src/libsec/port/rsagen.c
+++ b/sys/src/libsec/port/rsagen.c
@@ -26,9 +26,13 @@
// find an e relatively prime to phi
t1 = mpnew(0);
t2 = mpnew(0);
- mprand(elen, genrandom, e);
- if(mpcmp(e,mptwo) <= 0)
- itomp(3, e);
+ if(elen == 0)
+ itomp(65537, e);
+ else {
+ mprand(elen, genrandom, e);
+ if(mpcmp(e,mptwo) <= 0)
+ itomp(3, e);
+ }
// See Menezes et al. p.291 "8.8 Note (selecting primes)" for discussion
// of the merits of various choices of primes and exponents. e=3 is a
// common and recommended exponent, but doesn't necessarily work here