From: simon Date: Fri, 24 Mar 2000 11:46:39 +0000 (+0000) Subject: Rather silly byte-string / word-string transformations in RSA key X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/commitdiff_plain/d93737294f8871743e5548e7f05ae465d28f84f4 Rather silly byte-string / word-string transformations in RSA key handling were failing when the key had an odd number of bytes. A server with an 850-bit key was suffering connection failures as a result. Now fixed. git-svn-id: svn://svn.tartarus.org/sgt/putty@426 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/sshrsa.c b/sshrsa.c index 3a017c29..d13f6cfe 100644 --- a/sshrsa.c +++ b/sshrsa.c @@ -264,12 +264,12 @@ int makekey(unsigned char *data, struct RSAKey *result, for (i=1; i<=w; i++) bn[j][i] = 0; - for (i=0; ibytes; i++) { + for (i=key->bytes; i-- ;) { unsigned char byte = *p++; - if ((key->bytes-i) & 1) - b1[w-i/2] |= byte; + if (i & 1) + b1[1+i/2] |= byte<<8; else - b1[w-i/2] |= byte<<8; + b1[1+i/2] |= byte; } debug(b1); @@ -323,12 +323,12 @@ void rsaencrypt(unsigned char *data, int length, struct RSAKey *key) { debug(b2); p = data; - for (i=0; ibytes; i++) { + for (i=key->bytes; i-- ;) { unsigned char b; if (i & 1) - b = b2[w-i/2] & 0xFF; + b = b2[1+i/2] >> 8; else - b = b2[w-i/2] >> 8; + b = b2[1+i/2] & 0xFF; *p++ = b; }