~dave-terei/libmemcached/sasl-fixes

« back to all changes in this revision

Viewing changes to libhashkit/md5.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
/* POINTER defines a generic pointer type */
38
38
typedef unsigned char *POINTER;
 
39
typedef const unsigned char *CONST_POINTER;
39
40
 
40
41
 
41
42
/* UINT4 defines a four byte word */
77
78
 
78
79
 
79
80
static void MD5Transform (UINT4 state[4],
80
 
                          unsigned char block[64]);
 
81
                          const unsigned char block[64]);
81
82
static void Encode (unsigned char *output,
82
83
                    UINT4 *input,
83
84
                    unsigned int len);
84
 
static void Decode(UINT4 *output, unsigned char *input, unsigned int len);
 
85
static void Decode(UINT4 *output, const unsigned char *input, unsigned int len);
85
86
 
86
87
static unsigned char PADDING[64] = {
87
88
  0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
178
179
  /* Transform as many times as possible.
179
180
*/
180
181
  if (inputLen >= partLen) {
181
 
 memcpy((POINTER)&context->buffer[idx], (POINTER)input, partLen);
182
 
 MD5Transform(context->state, context->buffer);
183
 
 
184
 
 for (i = partLen; i + 63 < inputLen; i += 64)
185
 
   MD5Transform (context->state, (unsigned char *)&input[i]);
186
 
 
187
 
 idx = 0;
 
182
    memcpy((POINTER)&context->buffer[idx], (CONST_POINTER)input, partLen);
 
183
    MD5Transform(context->state, context->buffer);
 
184
 
 
185
    for (i = partLen; i + 63 < inputLen; i += 64)
 
186
      MD5Transform (context->state, (CONST_POINTER)&input[i]);
 
187
 
 
188
    idx = 0;
188
189
  }
189
190
  else
190
 
 i = 0;
 
191
    i = 0;
191
192
 
192
193
  /* Buffer remaining input */
193
 
  memcpy((POINTER)&context->buffer[idx], (POINTER)&input[i],
194
 
             inputLen-i);
 
194
  memcpy((POINTER)&context->buffer[idx], (CONST_POINTER)&input[i],
 
195
         inputLen-i);
195
196
}
196
197
 
197
198
/* MD5 finalization. Ends an MD5 message-digest operation, writing the
229
230
 */
230
231
static void MD5Transform (
231
232
                          UINT4 state[4],
232
 
                          unsigned char block[64])
 
233
                          const unsigned char block[64])
233
234
{
234
235
  UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
235
236
 
341
342
  a multiple of 4.
342
343
 */
343
344
static void Decode (
344
 
UINT4 *output,
345
 
unsigned char *input,
346
 
unsigned int len)
 
345
                    UINT4 *output,
 
346
                    const unsigned char *input,
 
347
                    unsigned int len)
347
348
{
348
349
  unsigned int i, j;
349
350
 
350
351
  for (i = 0, j = 0; j < len; i++, j += 4)
351
 
 output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
352
 
   (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
 
352
    output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
 
353
      (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
353
354
}
354
355
 
355
356
uint32_t hashkit_md5(const char *key, size_t key_length, void *context)