src/test/SDL_test_md5.c
changeset 7191 75360622e65f
parent 6885 700f1b25f77f
child 8149 681eb46b8ac4
     1.1 --- a/src/test/SDL_test_md5.c	Sat May 18 12:48:50 2013 -0700
     1.2 +++ b/src/test/SDL_test_md5.c	Sat May 18 14:17:52 2013 -0700
     1.3 @@ -102,7 +102,7 @@
     1.4     (a) += (b); \
     1.5    }
     1.6  
     1.7 -/* 
     1.8 +/*
     1.9    The routine MD5Init initializes the message-digest context
    1.10    mdContext. All fields are set to zero.
    1.11  */
    1.12 @@ -122,14 +122,14 @@
    1.13    mdContext->buf[3] = (MD5UINT4) 0x10325476;
    1.14  }
    1.15  
    1.16 -/* 
    1.17 +/*
    1.18   The routine MD5Update updates the message-digest context to
    1.19   account for the presence of each of the characters inBuf[0..inLen-1]
    1.20   in the message whose digest is being computed.
    1.21  */
    1.22  
    1.23  void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf,
    1.24 -		  unsigned int inLen)
    1.25 +          unsigned int inLen)
    1.26  {
    1.27    MD5UINT4  in[16];
    1.28    int       mdi;
    1.29 @@ -139,12 +139,12 @@
    1.30    if (inBuf == NULL || inLen < 1) return;
    1.31  
    1.32    /*
    1.33 -   * compute number of bytes mod 64 
    1.34 +   * compute number of bytes mod 64
    1.35     */
    1.36    mdi = (int) ((mdContext->i[0] >> 3) & 0x3F);
    1.37  
    1.38    /*
    1.39 -   * update number of bits 
    1.40 +   * update number of bits
    1.41     */
    1.42    if ((mdContext->i[0] + ((MD5UINT4) inLen << 3)) < mdContext->i[0])
    1.43      mdContext->i[1]++;
    1.44 @@ -153,26 +153,26 @@
    1.45  
    1.46    while (inLen--) {
    1.47      /*
    1.48 -     * add new character to buffer, increment mdi 
    1.49 +     * add new character to buffer, increment mdi
    1.50       */
    1.51      mdContext->in[mdi++] = *inBuf++;
    1.52  
    1.53      /*
    1.54 -     * transform if necessary 
    1.55 +     * transform if necessary
    1.56       */
    1.57      if (mdi == 0x40) {
    1.58        for (i = 0, ii = 0; i < 16; i++, ii += 4)
    1.59 -	in[i] = (((MD5UINT4) mdContext->in[ii + 3]) << 24) |
    1.60 -	  (((MD5UINT4) mdContext->in[ii + 2]) << 16) |
    1.61 -	  (((MD5UINT4) mdContext->in[ii + 1]) << 8) |
    1.62 -	  ((MD5UINT4) mdContext->in[ii]);
    1.63 +    in[i] = (((MD5UINT4) mdContext->in[ii + 3]) << 24) |
    1.64 +      (((MD5UINT4) mdContext->in[ii + 2]) << 16) |
    1.65 +      (((MD5UINT4) mdContext->in[ii + 1]) << 8) |
    1.66 +      ((MD5UINT4) mdContext->in[ii]);
    1.67        SDLTest_Md5Transform(mdContext->buf, in);
    1.68        mdi = 0;
    1.69      }
    1.70    }
    1.71  }
    1.72  
    1.73 -/* 
    1.74 +/*
    1.75   The routine MD5Final terminates the message-digest computation and
    1.76   ends with the desired message digest in mdContext->digest[0...15].
    1.77  */
    1.78 @@ -187,24 +187,24 @@
    1.79    if (mdContext == NULL) return;
    1.80  
    1.81    /*
    1.82 -   * save number of bits 
    1.83 +   * save number of bits
    1.84     */
    1.85    in[14] = mdContext->i[0];
    1.86    in[15] = mdContext->i[1];
    1.87  
    1.88    /*
    1.89 -   * compute number of bytes mod 64 
    1.90 +   * compute number of bytes mod 64
    1.91     */
    1.92    mdi = (int) ((mdContext->i[0] >> 3) & 0x3F);
    1.93  
    1.94    /*
    1.95 -   * pad out to 56 mod 64 
    1.96 +   * pad out to 56 mod 64
    1.97     */
    1.98    padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
    1.99    SDLTest_Md5Update(mdContext, MD5PADDING, padLen);
   1.100  
   1.101    /*
   1.102 -   * append length in bits and transform 
   1.103 +   * append length in bits and transform
   1.104     */
   1.105    for (i = 0, ii = 0; i < 14; i++, ii += 4)
   1.106      in[i] = (((MD5UINT4) mdContext->in[ii + 3]) << 24) |
   1.107 @@ -214,7 +214,7 @@
   1.108    SDLTest_Md5Transform(mdContext->buf, in);
   1.109  
   1.110    /*
   1.111 -   * store buffer in digest 
   1.112 +   * store buffer in digest
   1.113     */
   1.114    for (i = 0, ii = 0; i < 4; i++, ii += 4) {
   1.115      mdContext->digest[ii] = (unsigned char) (mdContext->buf[i] & 0xFF);
   1.116 @@ -234,100 +234,100 @@
   1.117    MD5UINT4  a = buf[0], b = buf[1], c = buf[2], d = buf[3];
   1.118  
   1.119    /*
   1.120 -   * Round 1 
   1.121 +   * Round 1
   1.122     */
   1.123  #define S11 7
   1.124  #define S12 12
   1.125  #define S13 17
   1.126  #define S14 22
   1.127 -  FF(a, b, c, d, in[0], S11, 3614090360u);	/* 1 */
   1.128 -  FF(d, a, b, c, in[1], S12, 3905402710u);	/* 2 */
   1.129 -  FF(c, d, a, b, in[2], S13, 606105819u);	/* 3 */
   1.130 -  FF(b, c, d, a, in[3], S14, 3250441966u);	/* 4 */
   1.131 -  FF(a, b, c, d, in[4], S11, 4118548399u);	/* 5 */
   1.132 -  FF(d, a, b, c, in[5], S12, 1200080426u);	/* 6 */
   1.133 -  FF(c, d, a, b, in[6], S13, 2821735955u);	/* 7 */
   1.134 -  FF(b, c, d, a, in[7], S14, 4249261313u);	/* 8 */
   1.135 -  FF(a, b, c, d, in[8], S11, 1770035416u);	/* 9 */
   1.136 -  FF(d, a, b, c, in[9], S12, 2336552879u);	/* 10 */
   1.137 -  FF(c, d, a, b, in[10], S13, 4294925233u);	/* 11 */
   1.138 -  FF(b, c, d, a, in[11], S14, 2304563134u);	/* 12 */
   1.139 -  FF(a, b, c, d, in[12], S11, 1804603682u);	/* 13 */
   1.140 -  FF(d, a, b, c, in[13], S12, 4254626195u);	/* 14 */
   1.141 -  FF(c, d, a, b, in[14], S13, 2792965006u);	/* 15 */
   1.142 -  FF(b, c, d, a, in[15], S14, 1236535329u);	/* 16 */
   1.143 +  FF(a, b, c, d, in[0], S11, 3614090360u);  /* 1 */
   1.144 +  FF(d, a, b, c, in[1], S12, 3905402710u);  /* 2 */
   1.145 +  FF(c, d, a, b, in[2], S13, 606105819u);   /* 3 */
   1.146 +  FF(b, c, d, a, in[3], S14, 3250441966u);  /* 4 */
   1.147 +  FF(a, b, c, d, in[4], S11, 4118548399u);  /* 5 */
   1.148 +  FF(d, a, b, c, in[5], S12, 1200080426u);  /* 6 */
   1.149 +  FF(c, d, a, b, in[6], S13, 2821735955u);  /* 7 */
   1.150 +  FF(b, c, d, a, in[7], S14, 4249261313u);  /* 8 */
   1.151 +  FF(a, b, c, d, in[8], S11, 1770035416u);  /* 9 */
   1.152 +  FF(d, a, b, c, in[9], S12, 2336552879u);  /* 10 */
   1.153 +  FF(c, d, a, b, in[10], S13, 4294925233u); /* 11 */
   1.154 +  FF(b, c, d, a, in[11], S14, 2304563134u); /* 12 */
   1.155 +  FF(a, b, c, d, in[12], S11, 1804603682u); /* 13 */
   1.156 +  FF(d, a, b, c, in[13], S12, 4254626195u); /* 14 */
   1.157 +  FF(c, d, a, b, in[14], S13, 2792965006u); /* 15 */
   1.158 +  FF(b, c, d, a, in[15], S14, 1236535329u); /* 16 */
   1.159  
   1.160    /*
   1.161 -   * Round 2 
   1.162 +   * Round 2
   1.163     */
   1.164  #define S21 5
   1.165  #define S22 9
   1.166  #define S23 14
   1.167  #define S24 20
   1.168 -  GG(a, b, c, d, in[1], S21, 4129170786u);	/* 17 */
   1.169 -  GG(d, a, b, c, in[6], S22, 3225465664u);	/* 18 */
   1.170 -  GG(c, d, a, b, in[11], S23, 643717713u);	/* 19 */
   1.171 -  GG(b, c, d, a, in[0], S24, 3921069994u);	/* 20 */
   1.172 -  GG(a, b, c, d, in[5], S21, 3593408605u);	/* 21 */
   1.173 -  GG(d, a, b, c, in[10], S22, 38016083u);	/* 22 */
   1.174 -  GG(c, d, a, b, in[15], S23, 3634488961u);	/* 23 */
   1.175 -  GG(b, c, d, a, in[4], S24, 3889429448u);	/* 24 */
   1.176 -  GG(a, b, c, d, in[9], S21, 568446438u);	/* 25 */
   1.177 -  GG(d, a, b, c, in[14], S22, 3275163606u);	/* 26 */
   1.178 -  GG(c, d, a, b, in[3], S23, 4107603335u);	/* 27 */
   1.179 -  GG(b, c, d, a, in[8], S24, 1163531501u);	/* 28 */
   1.180 -  GG(a, b, c, d, in[13], S21, 2850285829u);	/* 29 */
   1.181 -  GG(d, a, b, c, in[2], S22, 4243563512u);	/* 30 */
   1.182 -  GG(c, d, a, b, in[7], S23, 1735328473u);	/* 31 */
   1.183 -  GG(b, c, d, a, in[12], S24, 2368359562u);	/* 32 */
   1.184 +  GG(a, b, c, d, in[1], S21, 4129170786u);  /* 17 */
   1.185 +  GG(d, a, b, c, in[6], S22, 3225465664u);  /* 18 */
   1.186 +  GG(c, d, a, b, in[11], S23, 643717713u);  /* 19 */
   1.187 +  GG(b, c, d, a, in[0], S24, 3921069994u);  /* 20 */
   1.188 +  GG(a, b, c, d, in[5], S21, 3593408605u);  /* 21 */
   1.189 +  GG(d, a, b, c, in[10], S22, 38016083u);   /* 22 */
   1.190 +  GG(c, d, a, b, in[15], S23, 3634488961u); /* 23 */
   1.191 +  GG(b, c, d, a, in[4], S24, 3889429448u);  /* 24 */
   1.192 +  GG(a, b, c, d, in[9], S21, 568446438u);   /* 25 */
   1.193 +  GG(d, a, b, c, in[14], S22, 3275163606u); /* 26 */
   1.194 +  GG(c, d, a, b, in[3], S23, 4107603335u);  /* 27 */
   1.195 +  GG(b, c, d, a, in[8], S24, 1163531501u);  /* 28 */
   1.196 +  GG(a, b, c, d, in[13], S21, 2850285829u); /* 29 */
   1.197 +  GG(d, a, b, c, in[2], S22, 4243563512u);  /* 30 */
   1.198 +  GG(c, d, a, b, in[7], S23, 1735328473u);  /* 31 */
   1.199 +  GG(b, c, d, a, in[12], S24, 2368359562u); /* 32 */
   1.200  
   1.201    /*
   1.202 -   * Round 3 
   1.203 +   * Round 3
   1.204     */
   1.205  #define S31 4
   1.206  #define S32 11
   1.207  #define S33 16
   1.208  #define S34 23
   1.209 -  HH(a, b, c, d, in[5], S31, 4294588738u);	/* 33 */
   1.210 -  HH(d, a, b, c, in[8], S32, 2272392833u);	/* 34 */
   1.211 -  HH(c, d, a, b, in[11], S33, 1839030562u);	/* 35 */
   1.212 -  HH(b, c, d, a, in[14], S34, 4259657740u);	/* 36 */
   1.213 -  HH(a, b, c, d, in[1], S31, 2763975236u);	/* 37 */
   1.214 -  HH(d, a, b, c, in[4], S32, 1272893353u);	/* 38 */
   1.215 -  HH(c, d, a, b, in[7], S33, 4139469664u);	/* 39 */
   1.216 -  HH(b, c, d, a, in[10], S34, 3200236656u);	/* 40 */
   1.217 -  HH(a, b, c, d, in[13], S31, 681279174u);	/* 41 */
   1.218 -  HH(d, a, b, c, in[0], S32, 3936430074u);	/* 42 */
   1.219 -  HH(c, d, a, b, in[3], S33, 3572445317u);	/* 43 */
   1.220 -  HH(b, c, d, a, in[6], S34, 76029189u);	/* 44 */
   1.221 -  HH(a, b, c, d, in[9], S31, 3654602809u);	/* 45 */
   1.222 -  HH(d, a, b, c, in[12], S32, 3873151461u);	/* 46 */
   1.223 -  HH(c, d, a, b, in[15], S33, 530742520u);	/* 47 */
   1.224 -  HH(b, c, d, a, in[2], S34, 3299628645u);	/* 48 */
   1.225 +  HH(a, b, c, d, in[5], S31, 4294588738u);  /* 33 */
   1.226 +  HH(d, a, b, c, in[8], S32, 2272392833u);  /* 34 */
   1.227 +  HH(c, d, a, b, in[11], S33, 1839030562u); /* 35 */
   1.228 +  HH(b, c, d, a, in[14], S34, 4259657740u); /* 36 */
   1.229 +  HH(a, b, c, d, in[1], S31, 2763975236u);  /* 37 */
   1.230 +  HH(d, a, b, c, in[4], S32, 1272893353u);  /* 38 */
   1.231 +  HH(c, d, a, b, in[7], S33, 4139469664u);  /* 39 */
   1.232 +  HH(b, c, d, a, in[10], S34, 3200236656u); /* 40 */
   1.233 +  HH(a, b, c, d, in[13], S31, 681279174u);  /* 41 */
   1.234 +  HH(d, a, b, c, in[0], S32, 3936430074u);  /* 42 */
   1.235 +  HH(c, d, a, b, in[3], S33, 3572445317u);  /* 43 */
   1.236 +  HH(b, c, d, a, in[6], S34, 76029189u);    /* 44 */
   1.237 +  HH(a, b, c, d, in[9], S31, 3654602809u);  /* 45 */
   1.238 +  HH(d, a, b, c, in[12], S32, 3873151461u); /* 46 */
   1.239 +  HH(c, d, a, b, in[15], S33, 530742520u);  /* 47 */
   1.240 +  HH(b, c, d, a, in[2], S34, 3299628645u);  /* 48 */
   1.241  
   1.242    /*
   1.243 -   * Round 4 
   1.244 +   * Round 4
   1.245     */
   1.246  #define S41 6
   1.247  #define S42 10
   1.248  #define S43 15
   1.249  #define S44 21
   1.250 -  II(a, b, c, d, in[0], S41, 4096336452u);	/* 49 */
   1.251 -  II(d, a, b, c, in[7], S42, 1126891415u);	/* 50 */
   1.252 -  II(c, d, a, b, in[14], S43, 2878612391u);	/* 51 */
   1.253 -  II(b, c, d, a, in[5], S44, 4237533241u);	/* 52 */
   1.254 -  II(a, b, c, d, in[12], S41, 1700485571u);	/* 53 */
   1.255 -  II(d, a, b, c, in[3], S42, 2399980690u);	/* 54 */
   1.256 -  II(c, d, a, b, in[10], S43, 4293915773u);	/* 55 */
   1.257 -  II(b, c, d, a, in[1], S44, 2240044497u);	/* 56 */
   1.258 -  II(a, b, c, d, in[8], S41, 1873313359u);	/* 57 */
   1.259 -  II(d, a, b, c, in[15], S42, 4264355552u);	/* 58 */
   1.260 -  II(c, d, a, b, in[6], S43, 2734768916u);	/* 59 */
   1.261 -  II(b, c, d, a, in[13], S44, 1309151649u);	/* 60 */
   1.262 -  II(a, b, c, d, in[4], S41, 4149444226u);	/* 61 */
   1.263 -  II(d, a, b, c, in[11], S42, 3174756917u);	/* 62 */
   1.264 -  II(c, d, a, b, in[2], S43, 718787259u);	/* 63 */
   1.265 -  II(b, c, d, a, in[9], S44, 3951481745u);	/* 64 */
   1.266 +  II(a, b, c, d, in[0], S41, 4096336452u);  /* 49 */
   1.267 +  II(d, a, b, c, in[7], S42, 1126891415u);  /* 50 */
   1.268 +  II(c, d, a, b, in[14], S43, 2878612391u); /* 51 */
   1.269 +  II(b, c, d, a, in[5], S44, 4237533241u);  /* 52 */
   1.270 +  II(a, b, c, d, in[12], S41, 1700485571u); /* 53 */
   1.271 +  II(d, a, b, c, in[3], S42, 2399980690u);  /* 54 */
   1.272 +  II(c, d, a, b, in[10], S43, 4293915773u); /* 55 */
   1.273 +  II(b, c, d, a, in[1], S44, 2240044497u);  /* 56 */
   1.274 +  II(a, b, c, d, in[8], S41, 1873313359u);  /* 57 */
   1.275 +  II(d, a, b, c, in[15], S42, 4264355552u); /* 58 */
   1.276 +  II(c, d, a, b, in[6], S43, 2734768916u);  /* 59 */
   1.277 +  II(b, c, d, a, in[13], S44, 1309151649u); /* 60 */
   1.278 +  II(a, b, c, d, in[4], S41, 4149444226u);  /* 61 */
   1.279 +  II(d, a, b, c, in[11], S42, 3174756917u); /* 62 */
   1.280 +  II(c, d, a, b, in[2], S43, 718787259u);   /* 63 */
   1.281 +  II(b, c, d, a, in[9], S44, 3951481745u);  /* 64 */
   1.282  
   1.283    buf[0] += a;
   1.284    buf[1] += b;