From 30c143c1d037b1a01ce69edd1b533878a959e8ff Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sun, 9 Oct 2016 10:34:25 +0200 Subject: Bugfixes and debugging --- envelope.cpp | 60 +++++++++++++++++++++++++++++++++++++------------- envelope/.gitignore | 1 + envelope/Makefile | 7 ++++-- envelope/envelope | Bin 116616 -> 116616 bytes envelope/main.cpp | 1 + envelope/testsuite.sh | 30 +++++++++++++++++++++++++ rsa.cpp | 7 +++++- 7 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 envelope/.gitignore create mode 100755 envelope/testsuite.sh diff --git a/envelope.cpp b/envelope.cpp index 5270dae..c881815 100644 --- a/envelope.cpp +++ b/envelope.cpp @@ -1,9 +1,12 @@ +#include #include #include "aes.h" #include "base64.h" //TODO: remove #include "envelope.h" #include "rng.h" +#undef DEBUG + using namespace std; namespace Envelope{ @@ -24,28 +27,39 @@ namespace Envelope{ do { for(int i=0;i"$fname" + keys="$(./envelope -k "$keylen")" + pubkey="$(echo "$keys" | head -1 | tr -d $'\n')" + privkey="$(echo "$keys" | tail -1 | tr -d $'\n')" + if ! diff "$fname" <(./envelope -e "$pubkey" <"$fname" | ./envelope -d "$privkey"); then + printf "\x1B[31;1m -- ERROR --\x1B[0m\n" + echo "pubkey = $pubkey" + echo "privkey = $privkey" + echo "data = $(base64 <"$fname")" + exit 1 + fi +} + +for keylen in 512 1024 2048; do + for len in 1 10 15 16 17 12345; do + dotest "$len" "$keylen" + done +done diff --git a/rsa.cpp b/rsa.cpp index 09ea1bc..94c9782 100644 --- a/rsa.cpp +++ b/rsa.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #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 = {"<