Mercurial > hg > xemacs-beta
comparison src/md5.c @ 173:8eaf7971accc r20-3b13
Import from CVS: tag r20-3b13
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:49:09 +0200 |
parents | 7d55a9ba150c |
children | 83b3d10dcba9 |
comparison
equal
deleted
inserted
replaced
172:a38aed19690b | 173:8eaf7971accc |
---|---|
141 context. | 141 context. |
142 */ | 142 */ |
143 void | 143 void |
144 MD5Update (MD5_CTX *context, CONST unsigned char *input, unsigned int inputLen) | 144 MD5Update (MD5_CTX *context, CONST unsigned char *input, unsigned int inputLen) |
145 { | 145 { |
146 unsigned int i, indecks, partLen; | 146 unsigned int i, indice, partLen; |
147 | 147 |
148 /* Compute number of bytes mod 64 */ | 148 /* Compute number of bytes mod 64 */ |
149 indecks = (unsigned int)((context->count[0] >> 3) & 0x3F); | 149 indice = (unsigned int)((context->count[0] >> 3) & 0x3F); |
150 | 150 |
151 /* Update number of bits */ | 151 /* Update number of bits */ |
152 if ((context->count[0] += ((UINT4)inputLen << 3)) | 152 if ((context->count[0] += ((UINT4)inputLen << 3)) |
153 < ((UINT4)inputLen << 3)) | 153 < ((UINT4)inputLen << 3)) |
154 context->count[1]++; | 154 context->count[1]++; |
155 context->count[1] += ((UINT4)inputLen >> 29); | 155 context->count[1] += ((UINT4)inputLen >> 29); |
156 | 156 |
157 partLen = 64 - indecks; | 157 partLen = 64 - indice; |
158 | 158 |
159 /* Transform as many times as possible. */ | 159 /* Transform as many times as possible. */ |
160 if (inputLen >= partLen) | 160 if (inputLen >= partLen) |
161 { | 161 { |
162 MD5_memcpy ((POINTER)&context->buffer[indecks], (CONST POINTER)input, | 162 MD5_memcpy ((POINTER)&context->buffer[indice], (CONST POINTER)input, |
163 partLen); | 163 partLen); |
164 MD5Transform (context->state, context->buffer); | 164 MD5Transform (context->state, context->buffer); |
165 | 165 |
166 for (i = partLen; i + 63 < inputLen; i += 64) | 166 for (i = partLen; i + 63 < inputLen; i += 64) |
167 MD5Transform (context->state, &input[i]); | 167 MD5Transform (context->state, &input[i]); |
168 | 168 |
169 indecks = 0; | 169 indice = 0; |
170 } | 170 } |
171 else | 171 else |
172 i = 0; | 172 i = 0; |
173 | 173 |
174 /* Buffer remaining input */ | 174 /* Buffer remaining input */ |
175 MD5_memcpy ((POINTER)&context->buffer[indecks], (CONST POINTER)&input[i], | 175 MD5_memcpy ((POINTER)&context->buffer[indice], (CONST POINTER)&input[i], |
176 inputLen-i); | 176 inputLen-i); |
177 } | 177 } |
178 | 178 |
179 /* MD5 finalization. Ends an MD5 message-digest operation, writing the | 179 /* MD5 finalization. Ends an MD5 message-digest operation, writing the |
180 message digest and zeroizing the context. */ | 180 message digest and zeroizing the context. */ |
181 void | 181 void |
182 MD5Final (unsigned char digest[16], MD5_CTX *context) | 182 MD5Final (unsigned char digest[16], MD5_CTX *context) |
183 { | 183 { |
184 unsigned char bits[8]; | 184 unsigned char bits[8]; |
185 unsigned int indecks, padLen; | 185 unsigned int indice, padLen; |
186 | 186 |
187 /* Save number of bits */ | 187 /* Save number of bits */ |
188 Encode (bits, context->count, 8); | 188 Encode (bits, context->count, 8); |
189 | 189 |
190 /* Pad out to 56 mod 64. | 190 /* Pad out to 56 mod 64. |
191 */ | 191 */ |
192 indecks = (unsigned int)((context->count[0] >> 3) & 0x3f); | 192 indice = (unsigned int)((context->count[0] >> 3) & 0x3f); |
193 padLen = (indecks < 56) ? (56 - indecks) : (120 - indecks); | 193 padLen = (indice < 56) ? (56 - indice) : (120 - indice); |
194 MD5Update (context, PADDING, padLen); | 194 MD5Update (context, PADDING, padLen); |
195 | 195 |
196 /* Append length (before padding) */ | 196 /* Append length (before padding) */ |
197 MD5Update (context, bits, 8); | 197 MD5Update (context, bits, 8); |
198 /* Store state in digest */ | 198 /* Store state in digest */ |
362 of the buffer; this would likely cause problems if the string | 362 of the buffer; this would likely cause problems if the string |
363 contains extended characters, because the extended characters | 363 contains extended characters, because the extended characters |
364 will get sent over the wire in an external form that is different | 364 will get sent over the wire in an external form that is different |
365 from their internal representation, and thus their MD5 hash would | 365 from their internal representation, and thus their MD5 hash would |
366 be different. */ | 366 be different. */ |
367 | 367 |
368 DEFUN ("md5", Fmd5, 1, 3, 0, /* | 368 DEFUN ("md5", Fmd5, 1, 3, 0, /* |
369 Return the MD5 (a secure message digest algorithm) of an object. | 369 Return the MD5 (a secure message digest algorithm) of an object. |
370 OBJECT is either a string or a buffer. | 370 OBJECT is either a string or a buffer. |
371 Optional arguments START and END denote buffer positions for computing the | 371 Optional arguments START and END denote buffer positions for computing the |
372 hash of a portion of OBJECT. | 372 hash of a portion of OBJECT. |
375 { | 375 { |
376 MD_CTX context; | 376 MD_CTX context; |
377 unsigned char digest[16]; | 377 unsigned char digest[16]; |
378 unsigned char thehash[32]; | 378 unsigned char thehash[32]; |
379 int i; | 379 int i; |
380 | 380 |
381 MDInit (&context); | 381 MDInit (&context); |
382 | 382 |
383 if (NILP (object)) | 383 if (NILP (object)) |
384 { | 384 { |
385 MDUpdate (&context, (CONST unsigned char *) "", 0); | 385 MDUpdate (&context, (CONST unsigned char *) "", 0); |