diff options
author | tomsmeding <tom.smeding@gmail.com> | 2016-10-12 21:59:03 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2016-10-12 21:59:03 +0200 |
commit | 3b25b6fb719bcbaf8a75d9959b5334662dcb2700 (patch) | |
tree | ac802378a4140d74eecac37a274a46694f6f1afd | |
parent | 2b7538c114e982f0d0af545e0f9796d2cfec33fc (diff) |
Make modlen prefix big-endian
-rw-r--r-- | rsa.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -48,15 +48,15 @@ namespace RSA{ string exportKey(const Key &key){ string modser=key.mod.serialiseMantissa(); int32_t modlen=modser.size(); - string modlenstr{(char)(modlen&0xff),(char)((modlen>>8)&0xff),(char)((modlen>>16)&0xff),(char)((modlen>>24)&0xff)}; + string modlenstr{(char)((modlen>>24)&0xff),(char)((modlen>>16)&0xff),(char)((modlen>>8)&0xff),(char)(modlen&0xff)}; return Base64::encode(modlenstr + modser + key.exp.serialiseMantissa()); } Key importKey(const string &repr){ string deser=Base64::decode(repr); if(deser.size()<=4)throw invalid_argument("Invalid key string length"); - int modlen=(uint8_t)deser[0]+((uint8_t)deser[1]<<8)+ - ((uint8_t)deser[2]<<16)+((uint8_t)deser[3]<<24); + int modlen=((uint8_t)deser[0]<<24)+((uint8_t)deser[1]<<16)+ + ((uint8_t)deser[2]<<8)+(uint8_t)deser[3]; if((int)deser.size()-4-modlen<=0)throw invalid_argument("Key string incomplete"); Key key; key.mod.deserialiseMantissa(string(deser.begin()+4,deser.begin()+(4+modlen))); |