]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - crypto/sha1.c
h63xx: tsc2101 alsa sound support
[linux-2.6-omap-h63xx.git] / crypto / sha1.c
index 292dcc13ff9273f0bd6f3be2b1a565aa227f3c1b..21571ed35b7ee7f90792a5f8b83ea2b42ff6cac6 100644 (file)
@@ -49,32 +49,33 @@ static void sha1_init(void *ctx)
 static void sha1_update(void *ctx, const u8 *data, unsigned int len)
 {
        struct sha1_ctx *sctx = ctx;
-       unsigned int i, j;
+       unsigned int partial, done;
        const u8 *src;
 
-       j = (sctx->count >> 3) & 0x3f;
-       sctx->count += len << 3;
-       i = 0;
+       partial = sctx->count & 0x3f;
+       sctx->count += len;
+       done = 0;
        src = data;
 
-       if ((j + len) > 63) {
+       if ((partial + len) > 63) {
                u32 temp[SHA_WORKSPACE_WORDS];
 
-               if (j) {
-                       memcpy(&sctx->buffer[j], data, (i = 64-j));
+               if (partial) {
+                       done = -partial;
+                       memcpy(sctx->buffer + partial, data, done + 64);
                        src = sctx->buffer;
                }
 
                do {
                        sha_transform(sctx->state, src, temp);
-                       i += 64;
-                       src = &data[i];
-               } while (i + 63 < len);
+                       done += 64;
+                       src = data + done;
+               } while (done + 63 < len);
 
                memset(temp, 0, sizeof(temp));
-               j = 0;
+               partial = 0;
        }
-       memcpy(&sctx->buffer[j], src, len - i);
+       memcpy(sctx->buffer + partial, src, len - done);
 }
 
 
@@ -87,10 +88,10 @@ static void sha1_final(void* ctx, u8 *out)
        __be64 bits;
        static const u8 padding[64] = { 0x80, };
 
-       bits = cpu_to_be64(sctx->count);
+       bits = cpu_to_be64(sctx->count << 3);
 
        /* Pad out to 56 mod 64 */
-       index = (sctx->count >> 3) & 0x3f;
+       index = sctx->count & 0x3f;
        padlen = (index < 56) ? (56 - index) : ((64+56) - index);
        sha1_update(sctx, padding, padlen);