VirtualBox

Ignore:
Timestamp:
Mar 30, 2012 10:10:34 AM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
77187
Message:

Runtime/md5: Clear the whole state and replace tabs with spaces

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/checksum/md5.cpp

    r28800 r40722  
    9494/* This is the central step in the MD5 algorithm. */
    9595#define MD5STEP(f, w, x, y, z, data, s) \
    96         ( w += f(x, y, z) + data,  w = w<<s | w>>(32-s),  w += x )
     96    ( w += f(x, y, z) + data,  w = w<<s | w>>(32-s),  w += x )
    9797
    9898
     
    194194{
    195195    uint32_t t;
    196     do {
    197         t = *buf;
     196    do
     197    {
     198        t = *buf;
    198199        t = RT_LE2H_U32(t);
    199         *buf = t;
    200         buf++;
     200        *buf = t;
     201        buf++;
    201202    } while (--longs);
    202203}
     
    236237    t = ctx->bits[0];
    237238    if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t)
    238         ctx->bits[1]++;         /* Carry from low to high */
     239    ctx->bits[1]++; /* Carry from low to high */
    239240    ctx->bits[1] += (uint32_t)(len >> 29);
    240241
     
    242243
    243244    /* Handle any leading odd-sized chunks */
    244     if (t) {
    245         uint8_t *p = (uint8_t *) ctx->in + t;
    246 
    247         t = 64 - t;
    248         if (len < t) {
    249             memcpy(p, buf, len);
    250             return;
    251         }
    252         memcpy(p, buf, t);
    253         rtMd5ByteReverse(ctx->in, 16);
    254         rtMd5Transform(ctx->buf, ctx->in);
    255         buf += t;
    256         len -= t;
     245    if (t)
     246    {
     247        uint8_t *p = (uint8_t *) ctx->in + t;
     248
     249        t = 64 - t;
     250        if (len < t)
     251        {
     252            memcpy(p, buf, len);
     253            return;
     254        }
     255        memcpy(p, buf, t);
     256        rtMd5ByteReverse(ctx->in, 16);
     257        rtMd5Transform(ctx->buf, ctx->in);
     258        buf += t;
     259        len -= t;
    257260    }
    258261
     
    306309
    307310    /* Pad out to 56 mod 64 */
    308     if (count < 8) {
    309         /* Two lots of padding:  Pad the first block to 64 bytes */
    310         memset(p, 0, count);
    311         rtMd5ByteReverse(ctx->in, 16);
    312         rtMd5Transform(ctx->buf, ctx->in);
    313 
    314         /* Now fill the next block with 56 bytes */
    315         memset(ctx->in, 0, 56);
    316     } else {
    317         /* Pad block to 56 bytes */
    318         memset(p, 0, count - 8);
     311    if (count < 8)
     312    {
     313        /* Two lots of padding:  Pad the first block to 64 bytes */
     314        memset(p, 0, count);
     315        rtMd5ByteReverse(ctx->in, 16);
     316        rtMd5Transform(ctx->buf, ctx->in);
     317
     318        /* Now fill the next block with 56 bytes */
     319        memset(ctx->in, 0, 56);
     320    }
     321    else
     322    {
     323        /* Pad block to 56 bytes */
     324        memset(p, 0, count - 8);
    319325    }
    320326    rtMd5ByteReverse(ctx->in, 14);
     
    327333    rtMd5ByteReverse(ctx->buf, 4);
    328334    memcpy(digest, ctx->buf, 16);
    329     memset(ctx, 0, sizeof(ctx));        /* In case it's sensitive */
     335    memset(ctx, 0, sizeof(*ctx));        /* In case it's sensitive */
    330336}
    331337RT_EXPORT_SYMBOL(RTMd5Final);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette