aboutsummaryrefslogtreecommitdiff
path: root/rsa.cpp
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-10-09 10:34:25 +0200
committertomsmeding <tom.smeding@gmail.com>2016-10-09 10:34:25 +0200
commit30c143c1d037b1a01ce69edd1b533878a959e8ff (patch)
tree0acd2a4c7f4bd8f8decaa8efe2d0926f7e2cc9e3 /rsa.cpp
parentfc236266f7931cde83c5c136a0a4e0246ab018e0 (diff)
Bugfixes and debugging
Diffstat (limited to 'rsa.cpp')
-rw-r--r--rsa.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/rsa.cpp b/rsa.cpp
index 09ea1bc..94c9782 100644
--- a/rsa.cpp
+++ b/rsa.cpp
@@ -1,4 +1,5 @@
#include <algorithm>
+#include <stdexcept>
#include <cstdint>
#include <cassert>
#include "base64.h"
@@ -26,7 +27,11 @@ namespace RSA{
pubkey.mod=privkey.mod=pq.first*pq.second;
pubkey.exp=65537;
Bigint x;
- assert(egcd((pq.first-Bigint::one)*(pq.second-Bigint::one),pubkey.exp,x,privkey.exp)==1);
+ 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 = {"<<pubkey.mod<<" , "<<pubkey.exp<<'}'<<endl;
+ // cerr<<"privkey = {"<<privkey.mod<<" , "<<privkey.exp<<'}'<<endl;
return make_pair(pubkey,privkey);
}