aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-10-08 11:56:47 +0200
committertomsmeding <tom.smeding@gmail.com>2016-10-08 11:56:47 +0200
commitf49e2058ad2c6d7eedded27fa41bd30405db5aaa (patch)
tree30dc9842617c58ffc9313c8a9c1b254fdc1e8176
parent2fe3a5f06bf4423fbb881238b30f6f592b5c0127 (diff)
Make parameter order a bit more consistent
-rw-r--r--aes.cpp12
-rw-r--r--aes.h4
-rw-r--r--main.cpp4
-rw-r--r--rsa.cpp6
-rw-r--r--rsa.h4
5 files changed, 16 insertions, 14 deletions
diff --git a/aes.cpp b/aes.cpp
index e226a3c..7048b17 100644
--- a/aes.cpp
+++ b/aes.cpp
@@ -174,7 +174,7 @@ namespace AES{
addRoundKey(state,keysched);
}
- string encryptCBC(const string &key,const string &data,int numrounds){
+ string encryptCBC(const string &data,const string &key,int numrounds){
if(roundconstant[0]==0)initTables();
int sz=data.size();
@@ -211,7 +211,7 @@ namespace AES{
return res;
}
- string decryptCBC(const string &key,const string &data,int numrounds){
+ string decryptCBC(const string &data,const string &key,int numrounds){
if(roundconstant[0]==0)initTables();
if(data.size()==0)return {};
@@ -232,7 +232,7 @@ namespace AES{
return res;
}
- string encrypt(const string &key,const string &data,Algorithm algo){
+ string encrypt(const string &data,const string &key,Algorithm algo){
int increment;
switch(algo){
case AES_128_CBC: increment=0; break;
@@ -241,10 +241,10 @@ namespace AES{
default: assert(false);
}
assert((int)key.size()==4*(4+2*increment));
- return encryptCBC(key,data,10+2*increment);
+ return encryptCBC(data,key,10+2*increment);
}
- string decrypt(const string &key,const string &data,Algorithm algo){
+ string decrypt(const string &data,const string &key,Algorithm algo){
int increment;
switch(algo){
case AES_128_CBC: increment=0; break;
@@ -253,7 +253,7 @@ namespace AES{
default: assert(false);
}
assert((int)key.size()==4*(4+2*increment));
- return decryptCBC(key,data,10+2*increment);
+ return decryptCBC(data,key,10+2*increment);
}
void test(){
diff --git a/aes.h b/aes.h
index b2064f2..0532a62 100644
--- a/aes.h
+++ b/aes.h
@@ -10,10 +10,10 @@ namespace AES{
AES_256_CBC,
};
- std::string encrypt(const std::string &key,const std::string &data,Algorithm algo);
+ std::string encrypt(const std::string &data,const std::string &key,Algorithm algo);
//throws invalid_argument for an invalid ciphertext (length not a multiple of block size, or padding malformed)
- std::string decrypt(const std::string &key,const std::string &data,Algorithm algo);
+ std::string decrypt(const std::string &data,const std::string &key,Algorithm algo);
void test();
diff --git a/main.cpp b/main.cpp
index 0481f6c..60198f7 100644
--- a/main.cpp
+++ b/main.cpp
@@ -143,9 +143,9 @@ void performrsa(){
cout<<"d = "<<privkey.pexp<<endl;
Bigint msg(123456789);
cout<<"msg = "<<msg<<endl;
- Bigint encr=RSA::encrypt(privkey.pub,msg);
+ Bigint encr=RSA::encrypt(msg,privkey.pub);
cout<<"encr = "<<encr<<endl;
- Bigint msg2=RSA::decrypt(privkey,encr);
+ Bigint msg2=RSA::decrypt(encr,privkey);
cout<<"msg = "<<msg2<<endl;
}
diff --git a/rsa.cpp b/rsa.cpp
index b6ad5ed..cfa1fee 100644
--- a/rsa.cpp
+++ b/rsa.cpp
@@ -10,12 +10,14 @@ using namespace std;
namespace RSA{
- Bigint encrypt(const PublicKey &pubkey,Bigint msg){
+ Bigint encrypt(Bigint msg,const PublicKey &pubkey){
+ // cerr<<"msg="<<msg<<endl;
+ // cerr<<"mod="<<pubkey.mod<<endl;
assert(msg>1&&msg<pubkey.mod);
return expmod(msg,pubkey.exp,pubkey.mod);
}
- Bigint decrypt(const PrivateKey &privkey,Bigint encr){
+ Bigint decrypt(Bigint encr,const PrivateKey &privkey){
return expmod(encr,privkey.pexp,privkey.pub.mod);
}
diff --git a/rsa.h b/rsa.h
index abedf84..f931ab3 100644
--- a/rsa.h
+++ b/rsa.h
@@ -15,8 +15,8 @@ namespace RSA{
Bigint pexp;
};
- Bigint encrypt(const PublicKey &key,Bigint msg);
- Bigint decrypt(const PrivateKey &key,Bigint msg);
+ Bigint encrypt(Bigint msg,const PublicKey &key);
+ Bigint decrypt(Bigint msg,const PrivateKey &key);
PrivateKey genkey(int nbits); //nbits is target number of bits of modulus
PrivateKey genkey(int nbits,const std::string &password); //generates key seeded by password