From c5163d30258178ac66e05ac491935ab710913917 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sun, 23 Oct 2016 18:57:02 +0200 Subject: Don't assert out when 65537|phi --- rsa.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'rsa.cpp') diff --git a/rsa.cpp b/rsa.cpp index 34b47f9..4adfa2c 100644 --- a/rsa.cpp +++ b/rsa.cpp @@ -22,17 +22,21 @@ namespace RSA{ } pair genkeys(int nbits,Rng &rng){ - pair pq=genprimepair(rng,nbits); - Key pubkey,privkey; - pubkey.mod=privkey.mod=pq.first*pq.second; - pubkey.exp=65537; - Bigint x; - Bigint phi((pq.first-Bigint::one)*(pq.second-Bigint::one)); - assert(egcd(phi,pubkey.exp,x,privkey.exp)==1); - privkey.exp=privkey.exp.divmod(phi).second; - // cerr<<"pubkey = {"< pq=genprimepair(rng,nbits); + Key pubkey,privkey; + pubkey.mod=privkey.mod=pq.first*pq.second; + pubkey.exp=65537; + Bigint x; + Bigint phi((pq.first-Bigint::one)*(pq.second-Bigint::one)); + if(egcd(phi,pubkey.exp,x,privkey.exp)!=1){ + continue; //p-1 or q-1 is divisible by pubkey.exp=65537 + } + privkey.exp=privkey.exp.divmod(phi).second; + // cerr<<"pubkey = {"< genkeys(int nbits){ -- cgit v1.2.3-70-g09d2