Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Modules/md5.c

    r2 r388  
    2828  This code implements the MD5 Algorithm defined in RFC 1321, whose
    2929  text is available at
    30         http://www.ietf.org/rfc/rfc1321.txt
     30        http://www.ietf.org/rfc/rfc1321.txt
    3131  The code is derived from the text of the RFC, including the test suite
    3232  (section A.5) but excluding the rest of Appendix A.  It does not include
     
    3939
    4040  2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order
    41         either statically or dynamically; added missing #include <string.h>
    42         in library.
     41        either statically or dynamically; added missing #include <string.h>
     42        in library.
    4343  2002-03-11 lpd Corrected argument list for main(), and added int return
    44         type, in test program and T value program.
     44        type, in test program and T value program.
    4545  2002-02-21 lpd Added missing #include <stdio.h> in test program.
    4646  2000-07-03 lpd Patched to eliminate warnings about "constant is
    47         unsigned in ANSI C, signed in traditional"; made test program
    48         self-checking.
     47        unsigned in ANSI C, signed in traditional"; made test program
     48        self-checking.
    4949  1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
    5050  1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
     
    5656#include <limits.h>
    5757
    58 #undef BYTE_ORDER       /* 1 = big-endian, -1 = little-endian, 0 = unknown */
     58#undef BYTE_ORDER       /* 1 = big-endian, -1 = little-endian, 0 = unknown */
    5959#ifdef ARCH_IS_BIG_ENDIAN
    6060#  define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
     
    134134{
    135135    md5_word_t
    136         a = pms->abcd[0], b = pms->abcd[1],
    137         c = pms->abcd[2], d = pms->abcd[3];
     136        a = pms->abcd[0], b = pms->abcd[1],
     137        c = pms->abcd[2], d = pms->abcd[3];
    138138    md5_word_t t;
    139139#if BYTE_ORDER > 0
     
    148148    {
    149149#if BYTE_ORDER == 0
    150         /*
    151         * Determine dynamically whether this is a big-endian or
    152         * little-endian machine, since we can use a more efficient
    153         * algorithm on the latter.
    154         */
    155         static const int w = 1;
    156 
    157         if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
    158 #endif
    159 #if BYTE_ORDER <= 0             /* little-endian */
    160         {
    161             /*
    162              * On little-endian machines, we can process properly aligned
    163              * data without copying it.
    164              */
    165             if (!((data - (const md5_byte_t *)0) & 3)) {
    166                 /* data are properly aligned */
    167                 X = (const md5_word_t *)data;
    168             } else {
    169                 /* not aligned */
    170                 memcpy(xbuf, data, 64);
    171                 X = xbuf;
    172             }
    173         }
     150        /*
     151        * Determine dynamically whether this is a big-endian or
     152        * little-endian machine, since we can use a more efficient
     153        * algorithm on the latter.
     154        */
     155        static const int w = 1;
     156
     157        if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
     158#endif
     159#if BYTE_ORDER <= 0             /* little-endian */
     160        {
     161            /*
     162             * On little-endian machines, we can process properly aligned
     163             * data without copying it.
     164             */
     165            if (!((data - (const md5_byte_t *)0) & 3)) {
     166                /* data are properly aligned */
     167                X = (const md5_word_t *)data;
     168            } else {
     169                /* not aligned */
     170                memcpy(xbuf, data, 64);
     171                X = xbuf;
     172            }
     173        }
    174174#endif
    175175#if BYTE_ORDER == 0
    176         else                    /* dynamic big-endian */
    177 #endif
    178 #if BYTE_ORDER >= 0             /* big-endian */
    179         {
    180             /*
    181              * On big-endian machines, we must arrange the bytes in the
    182              * right order.
    183              */
    184             const md5_byte_t *xp = data;
    185             int i;
     176        else                    /* dynamic big-endian */
     177#endif
     178#if BYTE_ORDER >= 0             /* big-endian */
     179        {
     180            /*
     181             * On big-endian machines, we must arrange the bytes in the
     182             * right order.
     183             */
     184            const md5_byte_t *xp = data;
     185            int i;
    186186
    187187#  if BYTE_ORDER == 0
    188             X = xbuf;           /* (dynamic only) */
     188            X = xbuf;           /* (dynamic only) */
    189189#  else
    190 #    define xbuf X              /* (static only) */
     190#    define xbuf X              /* (static only) */
    191191#  endif
    192             for (i = 0; i < 16; ++i, xp += 4)
    193                 xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
    194         }
     192            for (i = 0; i < 16; ++i, xp += 4)
     193                xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
     194        }
    195195#endif
    196196    }
     
    322322
    323323void
    324 md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
     324md5_append(md5_state_t *pms, const md5_byte_t *data, unsigned int nbytes)
    325325{
    326326    const md5_byte_t *p = data;
    327     int left = nbytes;
    328     int offset = (pms->count[0] >> 3) & 63;
     327    unsigned int left = nbytes;
     328    unsigned int offset = (pms->count[0] >> 3) & 63;
    329329    md5_word_t nbits = (md5_word_t)(nbytes << 3);
    330330
    331331    if (nbytes <= 0)
    332         return;
     332        return;
    333333
    334334    /* this special case is handled recursively */
    335335    if (nbytes > INT_MAX - offset) {
    336         int overlap;
     336        unsigned int overlap;
    337337
    338338        /* handle the append in two steps to prevent overflow */
     
    340340
    341341        md5_append(pms, data, overlap);
    342         md5_append(pms, data + overlap, nbytes - overlap); 
     342        md5_append(pms, data + overlap, nbytes - overlap);
    343343        return;
    344344    }
     
    348348    pms->count[0] += nbits;
    349349    if (pms->count[0] < nbits)
    350         pms->count[1]++;
     350        pms->count[1]++;
    351351
    352352    /* Process an initial partial block. */
    353353    if (offset) {
    354         int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
    355 
    356         memcpy(pms->buf + offset, p, copy);
    357         if (offset + copy < 64)
    358             return;
    359         p += copy;
    360         left -= copy;
    361         md5_process(pms, pms->buf);
     354        unsigned int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
     355
     356        memcpy(pms->buf + offset, p, copy);
     357        if (offset + copy < 64)
     358            return;
     359        p += copy;
     360        left -= copy;
     361        md5_process(pms, pms->buf);
    362362    }
    363363
    364364    /* Process full blocks. */
    365365    for (; left >= 64; p += 64, left -= 64)
    366         md5_process(pms, p);
     366        md5_process(pms, p);
    367367
    368368    /* Process a final partial block. */
    369369    if (left)
    370         memcpy(pms->buf, p, left);
     370        memcpy(pms->buf, p, left);
    371371}
    372372
     
    375375{
    376376    static const md5_byte_t pad[64] = {
    377         0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    378         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    379         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    380         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
     377        0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     378        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     379        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     380        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    381381    };
    382382    md5_byte_t data[8];
     
    385385    /* Save the length before padding. */
    386386    for (i = 0; i < 8; ++i)
    387         data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
     387        data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
    388388    /* Pad to 56 bytes mod 64. */
    389389    md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
     
    391391    md5_append(pms, data, 8);
    392392    for (i = 0; i < 16; ++i)
    393         digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
     393        digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
    394394}
Note: See TracChangeset for help on using the changeset viewer.