summaryrefslogtreecommitdiffstats
path: root/src/lib/crypto
diff options
context:
space:
mode:
authorRichard Basch <probe@mit.edu>1995-11-29 06:08:41 +0000
committerRichard Basch <probe@mit.edu>1995-11-29 06:08:41 +0000
commit63e16138badac42aed5269456877bd67ef9b79c1 (patch)
treebd93145eb13a9824d5ad74c47bdd44d44a083c0c /src/lib/crypto
parent13c25d984cbc5c95ee73c9872fd3de6cebcc75e9 (diff)
downloadkrb5-63e16138badac42aed5269456877bd67ef9b79c1.tar.gz
krb5-63e16138badac42aed5269456877bd67ef9b79c1.tar.xz
krb5-63e16138badac42aed5269456877bd67ef9b79c1.zip
Corrected a bug in the wrap-around carry (found bug by comparing test results
with another implementation). git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@7141 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/crypto')
-rw-r--r--src/lib/crypto/des/u_nfold.c40
1 files changed, 16 insertions, 24 deletions
diff --git a/src/lib/crypto/des/u_nfold.c b/src/lib/crypto/des/u_nfold.c
index 4311b9185..63eb0e29a 100644
--- a/src/lib/crypto/des/u_nfold.c
+++ b/src/lib/crypto/des/u_nfold.c
@@ -66,40 +66,32 @@ mit_des_n_fold(inbuf, inlen, outbuf, outlen)
#endif
do {
- int i, j;
+ int j;
register unsigned int k;
- if ((bytes % inlen) == 0) {
- /* Rotate input */
- k = ((bytes/inlen) * ROTATE_VALUE) % (inlen*8);
-
- for (j = (k+7)/8; j < inlen + (k+7)/8; j++)
- tempbuf[j % inlen] =
- ((inbuf[((8*j-k)/8)%inlen] << ((8-(k&7))&7)) +
- ((k&7) ? (inbuf[((8*j-k)/8 +1)%inlen] >> (k&7)) : 0))
- & 0xff;
- }
-
+ /* Rotate input */
+ k = ((bytes/inlen) * ROTATE_VALUE) % (inlen*8);
+ for (j = (k+7)/8; j < inlen + (k+7)/8; j++)
+ tempbuf[j % inlen] =
+ ((inbuf[((8*j-k)/8)%inlen] << ((8-(k&7))&7)) +
+ ((k&7) ? (inbuf[((8*j-k)/8 +1)%inlen] >> (k&7)) : 0))
+ & 0xff;
- i = min(outlen - (bytes % outlen), inlen - (bytes % inlen));
-
- j = i;
- k = 0;
- while (j--) {
- k += outbuf[(bytes+j) % outlen] + tempbuf[(bytes+j) % inlen];
+ for (k=0, j=inlen; j--; ) {
+ k += outbuf[(bytes+j) % outlen] + tempbuf[j];
outbuf[(bytes+j) % outlen] = k & 0xff;
k >>= 8;
}
-
- j = outlen-1;
+ j = bytes % outlen;
while (k) {
+ if (j-- == 0)
+ j += outlen;
k += outbuf[j];
- outbuf[j--] = k & 0xff;
+ outbuf[j] = k & 0xff;
k >>= 8;
}
-
- bytes += i;
- } while (((bytes % inlen) != 0) || ((bytes % outlen) != 0));
+ bytes += inlen;
+ } while (bytes % outlen);
return 0;
}