Merge `deisui-1_14_0-1'.
[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 ;;      Kenichi OKADA <okada@opaopa.org>
7 ;; Maintainer: Kenichi OKADA <okada@opaopa.org>
8 ;; Keywords: SHA1, FIPS 180-1
9
10 ;; This file is part of FLIM (Faithful Library about Internet Message).
11
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or
15 ;; (at your option) any later version.
16
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with this program; see the file COPYING.  If not, write to
24 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;; Examples from FIPS PUB 180-1.
30 ;; <URL:http://www.itl.nist.gov/div897/pubs/fip180-1.htm>
31 ;;
32 ;; (sha1 "abc")
33 ;; => a9993e364706816aba3e25717850c26c9cd0d89d
34 ;;
35 ;; (sha1 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
36 ;; => 84983e441c3bd26ebaae4aa1f95129e5e54670f1
37 ;;
38 ;; (sha1 (make-string 1000000 ?a))
39 ;; => 34aa973cd4c4daa4f61eeb2bdbad27316534016f
40
41 ;;; Code:
42
43 (require 'hex-util)
44
45 (eval-when-compile
46   (defun-maybe sha1-string (a)))
47
48 (defvar sha1-dl-module
49   (if (and (fboundp 'sha1-string)
50            (subrp (symbol-function 'sha1-string)))
51       nil
52     (if (fboundp 'dynamic-link)
53         (let ((path (expand-file-name "sha1.so" exec-directory)))
54           (and (file-exists-p path)
55                path)))))
56
57 (cond
58  (sha1-dl-module
59   ;; Emacs with DL patch.
60   (require 'sha1-dl))
61  (t
62   (require 'sha1-el)))
63
64 ;; compatibility for another sha1.el by Keiichi Suzuki.
65 (defun sha1-encode (string)
66   (decode-hex-string 
67    (sha1-string string)))
68 (defun sha1-encode-binary (string)
69   (decode-hex-string
70    (sha1-string string)))
71
72 (make-obsolete 'sha1-encode "It's old API.")
73 (make-obsolete 'sha1-encode-binary "It's old API.")
74
75 (provide 'sha1)
76
77 ;;; sha1.el ends here