Mercurial > hg > xemacs-beta
comparison src/md5.c @ 771:943eaba38521
[xemacs-hg @ 2002-03-13 08:51:24 by ben]
The big ben-mule-21-5 check-in!
Various files were added and deleted. See CHANGES-ben-mule.
There are still some test suite failures. No crashes, though.
Many of the failures have to do with problems in the test suite itself
rather than in the actual code. I'll be addressing these in the next
day or so -- none of the test suite failures are at all critical.
Meanwhile I'll be trying to address the biggest issues -- i.e. build
or run failures, which will almost certainly happen on various platforms.
All comments should be sent to ben@xemacs.org -- use a Cc: if necessary
when sending to mailing lists. There will be pre- and post- tags,
something like
pre-ben-mule-21-5-merge-in, and
post-ben-mule-21-5-merge-in.
author | ben |
---|---|
date | Wed, 13 Mar 2002 08:54:06 +0000 |
parents | fdefd0186b75 |
children | a5954632b187 |
comparison
equal
deleted
inserted
replaced
770:336a418893b5 | 771:943eaba38521 |
---|---|
1 /* md5.c - Functions to compute MD5 message digest of files or memory blocks | 1 /* md5.c - Functions to compute MD5 message digest of files or memory blocks |
2 according to the definition of MD5 in RFC 1321 from April 1992. | 2 according to the definition of MD5 in RFC 1321 from April 1992. |
3 Copyright (C) 1995, 1996 Free Software Foundation, Inc. | 3 Copyright (C) 1995, 1996 Free Software Foundation, Inc. |
4 Copyright (C) 2001 Ben Wing. | |
4 NOTE: The canonical source of this file is maintained with the GNU C | 5 NOTE: The canonical source of this file is maintained with the GNU C |
5 Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu. | 6 Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu. |
6 | 7 |
7 This program is free software; you can redistribute it and/or modify it | 8 This program is free software; you can redistribute it and/or modify it |
8 under the terms of the GNU General Public License as published by the | 9 under the terms of the GNU General Public License as published by the |
75 #endif | 76 #endif |
76 | 77 |
77 #include "lisp.h" | 78 #include "lisp.h" |
78 #include "buffer.h" | 79 #include "buffer.h" |
79 #include "lstream.h" | 80 #include "lstream.h" |
80 #ifdef FILE_CODING | |
81 # include "file-coding.h" | 81 # include "file-coding.h" |
82 #endif | |
83 | 82 |
84 /* Structure to save state of computation between the single steps. */ | 83 /* Structure to save state of computation between the single steps. */ |
85 struct md5_ctx | 84 struct md5_ctx |
86 { | 85 { |
87 md5_uint32 A; | 86 md5_uint32 A; |
197 sum = 0; | 196 sum = 0; |
198 | 197 |
199 /* Read block. Take care for partial reads. */ | 198 /* Read block. Take care for partial reads. */ |
200 do | 199 do |
201 { | 200 { |
202 n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); | 201 n = retry_fread (buffer + sum, 1, BLOCKSIZE - sum, stream); |
203 | 202 |
204 sum += n; | 203 sum += n; |
205 } | 204 } |
206 while (sum < BLOCKSIZE && n != 0); | 205 while (sum < BLOCKSIZE && n != 0); |
207 if (n == 0 && ferror (stream)) | 206 if (n == 0 && ferror (stream)) |
457 ctx->D = D; | 456 ctx->D = D; |
458 } | 457 } |
459 | 458 |
460 | 459 |
461 #ifdef emacs | 460 #ifdef emacs |
462 #ifdef FILE_CODING | |
463 /* Find out what format the buffer will be saved in, so we can make | 461 /* Find out what format the buffer will be saved in, so we can make |
464 the digest based on what it will look like on disk. */ | 462 the digest based on what it will look like on disk. */ |
465 static Lisp_Object | 463 static Lisp_Object |
466 md5_coding_system (Lisp_Object object, Lisp_Object coding, Lisp_Object istream, | 464 md5_coding_system (Lisp_Object object, Lisp_Object coding, Lisp_Object istream, |
467 int error_me_not) | 465 int error_me_not) |
469 Lisp_Object coding_system; | 467 Lisp_Object coding_system; |
470 | 468 |
471 if (NILP (coding)) | 469 if (NILP (coding)) |
472 { | 470 { |
473 if (BUFFERP (object)) | 471 if (BUFFERP (object)) |
474 { | 472 /* Use the file coding for this buffer by default. */ |
475 /* Use the file coding for this buffer by default. */ | 473 coding = XBUFFER (object)->buffer_file_coding_system; |
476 coding_system = XBUFFER (object)->buffer_file_coding_system; | |
477 } | |
478 else | 474 else |
479 { | 475 /* Attempt to autodetect the coding of the string. This is |
480 /* Attempt to autodetect the coding of the string. This is | 476 VERY hit-and-miss. #### It shouldn't be. */ |
481 VERY hit-and-miss. */ | 477 coding = detect_coding_stream (istream); |
482 eol_type_t eol = EOL_AUTODETECT; | 478 } |
483 coding_system = Fget_coding_system (Qundecided); | 479 |
484 determine_real_coding_system (XLSTREAM (istream), | 480 if (error_me_not) |
485 &coding_system, &eol); | 481 { |
486 } | 482 coding_system = find_coding_system_for_text_file (coding, 0); |
487 if (NILP (coding_system)) | 483 if (NILP (coding_system)) |
484 /* Default to binary. */ | |
488 coding_system = Fget_coding_system (Qbinary); | 485 coding_system = Fget_coding_system (Qbinary); |
489 else | |
490 { | |
491 coding_system = Ffind_coding_system (coding_system); | |
492 if (NILP (coding_system)) | |
493 coding_system = Fget_coding_system (Qbinary); | |
494 } | |
495 } | 486 } |
496 else | 487 else |
497 { | 488 coding_system = get_coding_system_for_text_file (coding, 0); |
498 coding_system = Ffind_coding_system (coding); | 489 |
499 if (NILP (coding_system)) | |
500 { | |
501 if (error_me_not) | |
502 /* Default to binary. */ | |
503 coding_system = Fget_coding_system (Qbinary); | |
504 else | |
505 invalid_argument ("No such coding system", coding); | |
506 } | |
507 } | |
508 return coding_system; | 490 return coding_system; |
509 } | 491 } |
510 #endif /* FILE_CODING */ | |
511 | |
512 | 492 |
513 DEFUN ("md5", Fmd5, 1, 5, 0, /* | 493 DEFUN ("md5", Fmd5, 1, 5, 0, /* |
514 Return the MD5 message digest of OBJECT, a buffer or string. | 494 Return the MD5 message digest of OBJECT, a buffer or string. |
515 | 495 |
516 Optional arguments START and END denote positions for computing the | 496 Optional arguments START and END denote positions for computing the |
535 unsigned char thehash[33]; | 515 unsigned char thehash[33]; |
536 int i; | 516 int i; |
537 | 517 |
538 Lisp_Object instream; | 518 Lisp_Object instream; |
539 struct gcpro gcpro1; | 519 struct gcpro gcpro1; |
540 #ifdef FILE_CODING | |
541 Lisp_Object raw_instream; | 520 Lisp_Object raw_instream; |
542 struct gcpro ngcpro1; | 521 struct gcpro ngcpro1; |
543 #endif | |
544 | 522 |
545 /* Set up the input stream. */ | 523 /* Set up the input stream. */ |
546 if (BUFFERP (object)) | 524 if (BUFFERP (object)) |
547 { | 525 { |
548 struct buffer *b; | 526 struct buffer *b; |
562 GB_HISTORICAL_STRING_BEHAVIOR); | 540 GB_HISTORICAL_STRING_BEHAVIOR); |
563 instream = make_lisp_string_input_stream (object, bstart, bend - bstart); | 541 instream = make_lisp_string_input_stream (object, bstart, bend - bstart); |
564 } | 542 } |
565 GCPRO1 (instream); | 543 GCPRO1 (instream); |
566 | 544 |
567 #ifdef FILE_CODING | |
568 /* Determine the coding and set up the conversion stream. */ | 545 /* Determine the coding and set up the conversion stream. */ |
569 coding = md5_coding_system (object, coding, instream, !NILP (noerror)); | 546 coding = md5_coding_system (object, coding, instream, !NILP (noerror)); |
570 raw_instream = instream; | 547 raw_instream = instream; |
571 instream = make_encoding_input_stream (XLSTREAM (instream), coding); | 548 instream = make_coding_input_stream (XLSTREAM (instream), coding, CODING_ENCODE); |
572 NGCPRO1 (raw_instream); | 549 NGCPRO1 (raw_instream); |
573 #endif | |
574 | 550 |
575 /* Initialize MD5 context. */ | 551 /* Initialize MD5 context. */ |
576 md5_init_ctx (&ctx); | 552 md5_init_ctx (&ctx); |
577 | 553 |
578 /* Get the data while doing the conversion. */ | 554 /* Get the data while doing the conversion. */ |
586 | 562 |
587 /* Process the bytes. */ | 563 /* Process the bytes. */ |
588 md5_process_bytes (tempbuf, size_in_bytes, &ctx); | 564 md5_process_bytes (tempbuf, size_in_bytes, &ctx); |
589 } | 565 } |
590 Lstream_delete (XLSTREAM (instream)); | 566 Lstream_delete (XLSTREAM (instream)); |
591 #ifdef FILE_CODING | |
592 Lstream_delete (XLSTREAM (raw_instream)); | 567 Lstream_delete (XLSTREAM (raw_instream)); |
593 NUNGCPRO; | 568 NUNGCPRO; |
594 #endif | |
595 UNGCPRO; | 569 UNGCPRO; |
596 | 570 |
597 md5_finish_ctx (&ctx, digest); | 571 md5_finish_ctx (&ctx, digest); |
598 for (i = 0; i < 16; i++) | 572 for (i = 0; i < 16; i++) |
599 sprintf ((char *) (thehash + (i * 2)), "%02x", digest[i]); | 573 sprintf ((char *) (thehash + (i * 2)), "%02x", digest[i]); |