diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 9 | ||||
| -rw-r--r-- | src/deps.mk | 3 | ||||
| -rw-r--r-- | src/fns.c | 129 | ||||
| -rw-r--r-- | src/makefile.w32-in | 1 |
4 files changed, 104 insertions, 38 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index c5594b8555d..b3b561a9370 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2011-05-24 Leo Liu <sdl.web@gmail.com> | ||
| 2 | |||
| 3 | * deps.mk (fns.o): | ||
| 4 | * makefile.w32-in ($(BLD)/fns.$(O)): Include sha1.h. | ||
| 5 | |||
| 6 | * fns.c (crypto_hash_function, Fsha1): New function. | ||
| 7 | (Fmd5): Use crypto_hash_function. | ||
| 8 | (syms_of_fns): Add Ssha1. | ||
| 9 | |||
| 1 | 2011-05-22 Paul Eggert <eggert@cs.ucla.edu> | 10 | 2011-05-22 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 11 | ||
| 3 | * gnutls.c: Remove unused macros. | 12 | * gnutls.c: Remove unused macros. |
diff --git a/src/deps.mk b/src/deps.mk index 8d0e0e69589..6c677f0e6c6 100644 --- a/src/deps.mk +++ b/src/deps.mk | |||
| @@ -284,7 +284,8 @@ eval.o: eval.c commands.h keyboard.h blockinput.h atimer.h systime.h frame.h \ | |||
| 284 | floatfns.o: floatfns.c syssignal.h lisp.h globals.h $(config_h) | 284 | floatfns.o: floatfns.c syssignal.h lisp.h globals.h $(config_h) |
| 285 | fns.o: fns.c commands.h lisp.h $(config_h) frame.h buffer.h character.h \ | 285 | fns.o: fns.c commands.h lisp.h $(config_h) frame.h buffer.h character.h \ |
| 286 | keyboard.h keymap.h window.h $(INTERVALS_H) coding.h ../lib/md5.h \ | 286 | keyboard.h keymap.h window.h $(INTERVALS_H) coding.h ../lib/md5.h \ |
| 287 | blockinput.h atimer.h systime.h xterm.h ../lib/unistd.h globals.h | 287 | ../lib/sha1.h blockinput.h atimer.h systime.h xterm.h ../lib/unistd.h \ |
| 288 | globals.h | ||
| 288 | print.o: print.c process.h frame.h window.h buffer.h keyboard.h character.h \ | 289 | print.o: print.c process.h frame.h window.h buffer.h keyboard.h character.h \ |
| 289 | lisp.h globals.h $(config_h) termchar.h $(INTERVALS_H) msdos.h termhooks.h \ | 290 | lisp.h globals.h $(config_h) termchar.h $(INTERVALS_H) msdos.h termhooks.h \ |
| 290 | blockinput.h atimer.h systime.h font.h charset.h coding.h ccl.h \ | 291 | blockinput.h atimer.h systime.h font.h charset.h coding.h ccl.h \ |
| @@ -4514,42 +4514,17 @@ including negative integers. */) | |||
| 4514 | 4514 | ||
| 4515 | 4515 | ||
| 4516 | /************************************************************************ | 4516 | /************************************************************************ |
| 4517 | MD5 | 4517 | MD5 and SHA1 |
| 4518 | ************************************************************************/ | 4518 | ************************************************************************/ |
| 4519 | 4519 | ||
| 4520 | #include "md5.h" | 4520 | #include "md5.h" |
| 4521 | #include "sha1.h" | ||
| 4521 | 4522 | ||
| 4522 | DEFUN ("md5", Fmd5, Smd5, 1, 5, 0, | 4523 | /* TYPE: 0 for md5, 1 for sha1. */ |
| 4523 | doc: /* Return MD5 message digest of OBJECT, a buffer or string. | ||
| 4524 | |||
| 4525 | A message digest is a cryptographic checksum of a document, and the | ||
| 4526 | algorithm to calculate it is defined in RFC 1321. | ||
| 4527 | |||
| 4528 | The two optional arguments START and END are character positions | ||
| 4529 | specifying for which part of OBJECT the message digest should be | ||
| 4530 | computed. If nil or omitted, the digest is computed for the whole | ||
| 4531 | OBJECT. | ||
| 4532 | 4524 | ||
| 4533 | The MD5 message digest is computed from the result of encoding the | 4525 | Lisp_Object |
| 4534 | text in a coding system, not directly from the internal Emacs form of | 4526 | crypto_hash_function (int type, Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror, Lisp_Object binary) |
| 4535 | the text. The optional fourth argument CODING-SYSTEM specifies which | ||
| 4536 | coding system to encode the text with. It should be the same coding | ||
| 4537 | system that you used or will use when actually writing the text into a | ||
| 4538 | file. | ||
| 4539 | |||
| 4540 | If CODING-SYSTEM is nil or omitted, the default depends on OBJECT. If | ||
| 4541 | OBJECT is a buffer, the default for CODING-SYSTEM is whatever coding | ||
| 4542 | system would be chosen by default for writing this text into a file. | ||
| 4543 | |||
| 4544 | If OBJECT is a string, the most preferred coding system (see the | ||
| 4545 | command `prefer-coding-system') is used. | ||
| 4546 | |||
| 4547 | If NOERROR is non-nil, silently assume the `raw-text' coding if the | ||
| 4548 | guesswork fails. Normally, an error is signaled in such case. */) | ||
| 4549 | (Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror) | ||
| 4550 | { | 4527 | { |
| 4551 | unsigned char digest[16]; | ||
| 4552 | char value[33]; | ||
| 4553 | int i; | 4528 | int i; |
| 4554 | EMACS_INT size; | 4529 | EMACS_INT size; |
| 4555 | EMACS_INT size_byte = 0; | 4530 | EMACS_INT size_byte = 0; |
| @@ -4558,6 +4533,7 @@ guesswork fails. Normally, an error is signaled in such case. */) | |||
| 4558 | register EMACS_INT b, e; | 4533 | register EMACS_INT b, e; |
| 4559 | register struct buffer *bp; | 4534 | register struct buffer *bp; |
| 4560 | EMACS_INT temp; | 4535 | EMACS_INT temp; |
| 4536 | Lisp_Object res=Qnil; | ||
| 4561 | 4537 | ||
| 4562 | if (STRINGP (object)) | 4538 | if (STRINGP (object)) |
| 4563 | { | 4539 | { |
| @@ -4728,15 +4704,93 @@ guesswork fails. Normally, an error is signaled in such case. */) | |||
| 4728 | object = code_convert_string (object, coding_system, Qnil, 1, 0, 0); | 4704 | object = code_convert_string (object, coding_system, Qnil, 1, 0, 0); |
| 4729 | } | 4705 | } |
| 4730 | 4706 | ||
| 4731 | md5_buffer (SSDATA (object) + start_byte, | 4707 | switch (type) |
| 4732 | SBYTES (object) - (size_byte - end_byte), | 4708 | { |
| 4733 | digest); | 4709 | case 0: /* MD5 */ |
| 4710 | { | ||
| 4711 | unsigned char digest[16]; | ||
| 4712 | md5_buffer (SSDATA (object) + start_byte, | ||
| 4713 | SBYTES (object) - (size_byte - end_byte), | ||
| 4714 | digest); | ||
| 4734 | 4715 | ||
| 4735 | for (i = 0; i < 16; i++) | 4716 | if (NILP(binary)) |
| 4736 | sprintf (&value[2 * i], "%02x", digest[i]); | 4717 | { |
| 4737 | value[32] = '\0'; | 4718 | unsigned char value[33]; |
| 4719 | for (i = 0; i < 16; i++) | ||
| 4720 | sprintf (&value[2 * i], "%02x", digest[i]); | ||
| 4721 | value[32] = '\0'; | ||
| 4722 | res = make_string (value, 32); | ||
| 4723 | } | ||
| 4724 | else | ||
| 4725 | res = make_string (digest, 16); | ||
| 4726 | break; | ||
| 4727 | } | ||
| 4738 | 4728 | ||
| 4739 | return make_string (value, 32); | 4729 | case 1: /* SHA1 */ |
| 4730 | { | ||
| 4731 | unsigned char digest[20]; | ||
| 4732 | sha1_buffer (SDATA (object) + start_byte, | ||
| 4733 | SBYTES (object) - (size_byte - end_byte), | ||
| 4734 | digest); | ||
| 4735 | if (NILP(binary)) | ||
| 4736 | { | ||
| 4737 | unsigned char value[41]; | ||
| 4738 | for (i = 0; i < 20; i++) | ||
| 4739 | sprintf (&value[2 * i], "%02x", digest[i]); | ||
| 4740 | value[40] = '\0'; | ||
| 4741 | res = make_string (value, 40); | ||
| 4742 | } | ||
| 4743 | else | ||
| 4744 | res = make_string (digest, 20); | ||
| 4745 | break; | ||
| 4746 | } | ||
| 4747 | } | ||
| 4748 | |||
| 4749 | return res; | ||
| 4750 | } | ||
| 4751 | |||
| 4752 | DEFUN ("md5", Fmd5, Smd5, 1, 5, 0, | ||
| 4753 | doc: /* Return MD5 message digest of OBJECT, a buffer or string. | ||
| 4754 | |||
| 4755 | A message digest is a cryptographic checksum of a document, and the | ||
| 4756 | algorithm to calculate it is defined in RFC 1321. | ||
| 4757 | |||
| 4758 | The two optional arguments START and END are character positions | ||
| 4759 | specifying for which part of OBJECT the message digest should be | ||
| 4760 | computed. If nil or omitted, the digest is computed for the whole | ||
| 4761 | OBJECT. | ||
| 4762 | |||
| 4763 | The MD5 message digest is computed from the result of encoding the | ||
| 4764 | text in a coding system, not directly from the internal Emacs form of | ||
| 4765 | the text. The optional fourth argument CODING-SYSTEM specifies which | ||
| 4766 | coding system to encode the text with. It should be the same coding | ||
| 4767 | system that you used or will use when actually writing the text into a | ||
| 4768 | file. | ||
| 4769 | |||
| 4770 | If CODING-SYSTEM is nil or omitted, the default depends on OBJECT. If | ||
| 4771 | OBJECT is a buffer, the default for CODING-SYSTEM is whatever coding | ||
| 4772 | system would be chosen by default for writing this text into a file. | ||
| 4773 | |||
| 4774 | If OBJECT is a string, the most preferred coding system (see the | ||
| 4775 | command `prefer-coding-system') is used. | ||
| 4776 | |||
| 4777 | If NOERROR is non-nil, silently assume the `raw-text' coding if the | ||
| 4778 | guesswork fails. Normally, an error is signaled in such case. */) | ||
| 4779 | (Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror) | ||
| 4780 | { | ||
| 4781 | return crypto_hash_function (0, object, start, end, coding_system, noerror, Qnil); | ||
| 4782 | } | ||
| 4783 | |||
| 4784 | DEFUN ("sha1", Fsha1, Ssha1, 1, 4, 0, | ||
| 4785 | doc: /* Return the SHA-1 (Secure Hash Algorithm) of an OBJECT. | ||
| 4786 | |||
| 4787 | OBJECT is either a string or a buffer. Optional arguments START and | ||
| 4788 | END are character positions specifying which portion of OBJECT for | ||
| 4789 | computing the hash. If BINARY is non-nil, return a string in binary | ||
| 4790 | form. */) | ||
| 4791 | (Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object binary) | ||
| 4792 | { | ||
| 4793 | return crypto_hash_function (1, object, start, end, Qnil, Qnil, binary); | ||
| 4740 | } | 4794 | } |
| 4741 | 4795 | ||
| 4742 | 4796 | ||
| @@ -4911,6 +4965,7 @@ this variable. */); | |||
| 4911 | defsubr (&Sbase64_encode_string); | 4965 | defsubr (&Sbase64_encode_string); |
| 4912 | defsubr (&Sbase64_decode_string); | 4966 | defsubr (&Sbase64_decode_string); |
| 4913 | defsubr (&Smd5); | 4967 | defsubr (&Smd5); |
| 4968 | defsubr (&Ssha1); | ||
| 4914 | defsubr (&Slocale_info); | 4969 | defsubr (&Slocale_info); |
| 4915 | } | 4970 | } |
| 4916 | 4971 | ||
diff --git a/src/makefile.w32-in b/src/makefile.w32-in index 71c4fa4c0ac..060b565b308 100644 --- a/src/makefile.w32-in +++ b/src/makefile.w32-in | |||
| @@ -866,6 +866,7 @@ $(BLD)/fns.$(O) : \ | |||
| 866 | $(EMACS_ROOT)/nt/inc/unistd.h \ | 866 | $(EMACS_ROOT)/nt/inc/unistd.h \ |
| 867 | $(EMACS_ROOT)/nt/inc/sys/time.h \ | 867 | $(EMACS_ROOT)/nt/inc/sys/time.h \ |
| 868 | $(EMACS_ROOT)/lib/md5.h \ | 868 | $(EMACS_ROOT)/lib/md5.h \ |
| 869 | $(EMACS_ROOT)/lib/sha1.h \ | ||
| 869 | $(LISP_H) \ | 870 | $(LISP_H) \ |
| 870 | $(SRC)/atimer.h \ | 871 | $(SRC)/atimer.h \ |
| 871 | $(SRC)/blockinput.h \ | 872 | $(SRC)/blockinput.h \ |