merge hmac package
[elisp/flim.git] / sha1.el
1 ;;; sha1.el --- SHA1 Secure Hash Algorithm.
2
3 ;; Copyright (C) 1999 Shuhei KOBAYASHI
4
5 ;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
6 ;; Keywords: SHA1, FIPS 180-1
7
8 ;; This program is free software; you can redistribute it and/or
9 ;; modify it under the terms of the GNU General Public License as
10 ;; published by the Free Software Foundation; either version 2, or
11 ;; (at your option) any later version.
12
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program; see the file COPYING.  If not, write to
20 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
22
23 ;;; Commentary:
24
25 ;; Examples from FIPS PUB 180-1.
26 ;; <URL:http://www.itl.nist.gov/div897/pubs/fip180-1.htm>
27 ;;
28 ;; (sha1 "abc")
29 ;; => a9993e364706816aba3e25717850c26c9cd0d89d
30 ;;
31 ;; (sha1 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
32 ;; => 84983e441c3bd26ebaae4aa1f95129e5e54670f1
33 ;;
34 ;; (sha1 (make-string 1000000 ?a))
35 ;; => 34aa973cd4c4daa4f61eeb2bdbad27316534016f
36
37 ;;; Code:
38
39 (cond
40  ((and (fboundp 'dynamic-link)
41        (file-exists-p (expand-file-name "sha1.so" exec-directory)))
42   ;; Emacs with DL patch.
43   (require 'sha1 "sha1-dl"))
44  (t
45   (require 'sha1 "sha1-el")
46   (defun sha1 (object &optional beg end)
47     "Return the SHA1 (Secure Hash Algorithm) of an object.
48 OBJECT is either a string or a buffer.
49 Optional arguments BEG and END denote buffer positions for computing the
50 hash of a portion of OBJECT."
51     (if (stringp object)
52         (sha1-encode object)
53       (save-excursion
54         (set-buffer object)
55         (sha1-encode
56          (buffer-substring-no-properties
57            (or beg (point-min)) (or end (point-max)))))))
58   ))
59
60 ;;; sha1.el ends here.