Commit e1b90ef6 authored by Leo Liu's avatar Leo Liu

Implement primitive `sha1' and remove sha1.el

parent 4ba4c54a
2011-05-24 Leo Liu <sdl.web@gmail.com>
* vc/vc-bzr.el (vc-bzr-sha1-program): Rename from sha1-program.
(vc-bzr-sha1): Adapt.
* sha1.el: Remove. Function `sha1' is now builtin.
* bindings.el: Provide sha1 feature.
2011-05-24 Kenichi Handa <handa@m17n.org>
* mail/sendmail.el: Require `rfc2047'.
......
......@@ -646,9 +646,10 @@ is okay. See `mode-line-format'.")
(make-variable-buffer-local 'indent-tabs-mode)
;; We have base64 and md5 functions built in now.
;; We have base64, md5 and sha1 functions built in now.
(provide 'base64)
(provide 'md5)
(provide 'sha1)
(provide 'overlay '(display syntax-table field))
(provide 'text-properties '(display syntax-table field point-entered))
......
This diff is collapsed.
......@@ -65,6 +65,14 @@
:group 'vc-bzr
:type 'string)
(defcustom vc-bzr-sha1-program '("sha1sum")
"Name of program to compute SHA1.
It must be a string \(program name\) or list of strings \(name and its args\)."
:type '(repeat string)
:group 'vc-bzr)
(define-obsolete-variable-alias 'sha1-program 'vc-bzr-sha1-program "24.1")
(defcustom vc-bzr-diff-switches nil
"String or list of strings specifying switches for bzr diff under VC.
If nil, use the value of `vc-diff-switches'. If t, use no switches."
......@@ -156,12 +164,10 @@ in the repository root directory of FILE."
(push (cons (match-string 1) (match-string 2)) settings)))
settings))
(require 'sha1) ;For sha1-program
(defun vc-bzr-sha1 (file)
(with-temp-buffer
(set-buffer-multibyte nil)
(let ((prog sha1-program)
(let ((prog vc-bzr-sha1-program)
(args nil)
process-file-side-effects)
(when (consp prog)
......
2011-05-24 Leo Liu <sdl.web@gmail.com>
* deps.mk (fns.o):
* makefile.w32-in ($(BLD)/fns.$(O)): Include sha1.h.
* fns.c (crypto_hash_function, Fsha1): New function.
(Fmd5): Use crypto_hash_function.
(syms_of_fns): Add Ssha1.
2011-05-22 Paul Eggert <eggert@cs.ucla.edu>
* gnutls.c: Remove unused macros.
......
......@@ -284,7 +284,8 @@ eval.o: eval.c commands.h keyboard.h blockinput.h atimer.h systime.h frame.h \
floatfns.o: floatfns.c syssignal.h lisp.h globals.h $(config_h)
fns.o: fns.c commands.h lisp.h $(config_h) frame.h buffer.h character.h \
keyboard.h keymap.h window.h $(INTERVALS_H) coding.h ../lib/md5.h \
blockinput.h atimer.h systime.h xterm.h ../lib/unistd.h globals.h
../lib/sha1.h blockinput.h atimer.h systime.h xterm.h ../lib/unistd.h \
globals.h
print.o: print.c process.h frame.h window.h buffer.h keyboard.h character.h \
lisp.h globals.h $(config_h) termchar.h $(INTERVALS_H) msdos.h termhooks.h \
blockinput.h atimer.h systime.h font.h charset.h coding.h ccl.h \
......
......@@ -4514,42 +4514,17 @@ including negative integers. */)
/************************************************************************
MD5
MD5 and SHA1
************************************************************************/
#include "md5.h"
#include "sha1.h"
DEFUN ("md5", Fmd5, Smd5, 1, 5, 0,
doc: /* Return MD5 message digest of OBJECT, a buffer or string.
A message digest is a cryptographic checksum of a document, and the
algorithm to calculate it is defined in RFC 1321.
The two optional arguments START and END are character positions
specifying for which part of OBJECT the message digest should be
computed. If nil or omitted, the digest is computed for the whole
OBJECT.
The MD5 message digest is computed from the result of encoding the
text in a coding system, not directly from the internal Emacs form of
the text. The optional fourth argument CODING-SYSTEM specifies which
coding system to encode the text with. It should be the same coding
system that you used or will use when actually writing the text into a
file.
If CODING-SYSTEM is nil or omitted, the default depends on OBJECT. If
OBJECT is a buffer, the default for CODING-SYSTEM is whatever coding
system would be chosen by default for writing this text into a file.
/* TYPE: 0 for md5, 1 for sha1. */
If OBJECT is a string, the most preferred coding system (see the
command `prefer-coding-system') is used.
If NOERROR is non-nil, silently assume the `raw-text' coding if the
guesswork fails. Normally, an error is signaled in such case. */)
(Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror)
Lisp_Object
crypto_hash_function (int type, Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror, Lisp_Object binary)
{
unsigned char digest[16];
char value[33];
int i;
EMACS_INT size;
EMACS_INT size_byte = 0;
......@@ -4558,6 +4533,7 @@ guesswork fails. Normally, an error is signaled in such case. */)
register EMACS_INT b, e;
register struct buffer *bp;
EMACS_INT temp;
Lisp_Object res=Qnil;
if (STRINGP (object))
{
......@@ -4728,15 +4704,93 @@ guesswork fails. Normally, an error is signaled in such case. */)
object = code_convert_string (object, coding_system, Qnil, 1, 0, 0);
}
switch (type)
{
case 0: /* MD5 */
{
unsigned char digest[16];
md5_buffer (SSDATA (object) + start_byte,
SBYTES (object) - (size_byte - end_byte),
digest);
if (NILP(binary))
{
unsigned char value[33];
for (i = 0; i < 16; i++)
sprintf (&value[2 * i], "%02x", digest[i]);
value[32] = '\0';
res = make_string (value, 32);
}
else
res = make_string (digest, 16);
break;
}
case 1: /* SHA1 */
{
unsigned char digest[20];
sha1_buffer (SDATA (object) + start_byte,
SBYTES (object) - (size_byte - end_byte),
digest);
if (NILP(binary))
{
unsigned char value[41];
for (i = 0; i < 20; i++)
sprintf (&value[2 * i], "%02x", digest[i]);
value[40] = '\0';
res = make_string (value, 40);
}
else
res = make_string (digest, 20);
break;
}
}
return res;
}
DEFUN ("md5", Fmd5, Smd5, 1, 5, 0,
doc: /* Return MD5 message digest of OBJECT, a buffer or string.
A message digest is a cryptographic checksum of a document, and the
algorithm to calculate it is defined in RFC 1321.
The two optional arguments START and END are character positions
specifying for which part of OBJECT the message digest should be
computed. If nil or omitted, the digest is computed for the whole
OBJECT.
The MD5 message digest is computed from the result of encoding the
text in a coding system, not directly from the internal Emacs form of
the text. The optional fourth argument CODING-SYSTEM specifies which
coding system to encode the text with. It should be the same coding
system that you used or will use when actually writing the text into a
file.
return make_string (value, 32);
If CODING-SYSTEM is nil or omitted, the default depends on OBJECT. If
OBJECT is a buffer, the default for CODING-SYSTEM is whatever coding
system would be chosen by default for writing this text into a file.
If OBJECT is a string, the most preferred coding system (see the
command `prefer-coding-system') is used.
If NOERROR is non-nil, silently assume the `raw-text' coding if the
guesswork fails. Normally, an error is signaled in such case. */)
(Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror)
{
return crypto_hash_function (0, object, start, end, coding_system, noerror, Qnil);
}
DEFUN ("sha1", Fsha1, Ssha1, 1, 4, 0,
doc: /* Return the SHA-1 (Secure Hash Algorithm) of an OBJECT.
OBJECT is either a string or a buffer. Optional arguments START and
END are character positions specifying which portion of OBJECT for
computing the hash. If BINARY is non-nil, return a string in binary
form. */)
(Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object binary)
{
return crypto_hash_function (1, object, start, end, Qnil, Qnil, binary);
}
......@@ -4911,6 +4965,7 @@ this variable. */);
defsubr (&Sbase64_encode_string);
defsubr (&Sbase64_decode_string);
defsubr (&Smd5);
defsubr (&Ssha1);
defsubr (&Slocale_info);
}
......
......@@ -866,6 +866,7 @@ $(BLD)/fns.$(O) : \
$(EMACS_ROOT)/nt/inc/unistd.h \
$(EMACS_ROOT)/nt/inc/sys/time.h \
$(EMACS_ROOT)/lib/md5.h \
$(EMACS_ROOT)/lib/sha1.h \
$(LISP_H) \
$(SRC)/atimer.h \
$(SRC)/blockinput.h \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment