From 3b25b6fb719bcbaf8a75d9959b5334662dcb2700 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 12 Oct 2016 21:59:03 +0200 Subject: Make modlen prefix big-endian --- rsa.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rsa.cpp b/rsa.cpp index 94c9782..34b47f9 100644 --- a/rsa.cpp +++ b/rsa.cpp @@ -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))); -- cgit v1.2.3-70-g09d2