From: Richard Basch Date: Tue, 28 Nov 1995 19:50:53 +0000 (+0000) Subject: Corrected bit rotation to match documented algorithm X-Git-Tag: krb5-1.0-beta6~768 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7d339153b49875a6a3fc28705bb9c393fc420eb9;p=krb5.git Corrected bit rotation to match documented algorithm git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@7139 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/crypto/des/u_nfold.c b/src/lib/crypto/des/u_nfold.c index e35edd480..4311b9185 100644 --- a/src/lib/crypto/des/u_nfold.c +++ b/src/lib/crypto/des/u_nfold.c @@ -73,10 +73,11 @@ mit_des_n_fold(inbuf, inlen, outbuf, outlen) /* Rotate input */ k = ((bytes/inlen) * ROTATE_VALUE) % (inlen*8); - for (j = (k+7)/8; j < inlen + (k/7)/8; j++) + for (j = (k+7)/8; j < inlen + (k+7)/8; j++) tempbuf[j % inlen] = - (inbuf[((8*j-k)/8)%inlen] & (((1<<(8-(k&7)))-1) <<(k&7))) + - (inbuf[((8*j-k)/8 + 1)%inlen] >> (8-(k&7))); + ((inbuf[((8*j-k)/8)%inlen] << ((8-(k&7))&7)) + + ((k&7) ? (inbuf[((8*j-k)/8 +1)%inlen] >> (k&7)) : 0)) + & 0xff; } @@ -85,7 +86,7 @@ mit_des_n_fold(inbuf, inlen, outbuf, outlen) j = i; k = 0; while (j--) { - k = outbuf[(bytes+j) % outlen] + tempbuf[(bytes+j) % inlen] + k; + k += outbuf[(bytes+j) % outlen] + tempbuf[(bytes+j) % inlen]; outbuf[(bytes+j) % outlen] = k & 0xff; k >>= 8; } @@ -98,7 +99,7 @@ mit_des_n_fold(inbuf, inlen, outbuf, outlen) } bytes += i; - } while (((bytes % inlen) == 0) && ((bytes % outlen) == 0)); + } while (((bytes % inlen) != 0) || ((bytes % outlen) != 0)); return 0; }