24a3af5e01c52b885f2319dd55cf6ba42e75680a
[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   (or (fboundp 'sha1-string)
47       (defun sha1-string (a))))
48
49 (defvar sha1-dl-module
50   (if (and (fboundp 'sha1-string)
51            (subrp (symbol-function 'sha1-string)))
52       nil
53     (if (fboundp 'dynamic-link)
54         (let ((path (expand-file-name "sha1.so" exec-directory)))
55           (and (file-exists-p path)
56                path)))))
57
58 (cond
59  (sha1-dl-module
60   ;; Emacs with DL patch.
61   (require 'sha1-dl))
62  (t
63   (require 'sha1-el)))
64
65 ;; compatibility for another sha1.el by Keiichi Suzuki.
66 (defun sha1-encode (string)
67   (decode-hex-string 
68    (sha1-string string)))
69 (defun sha1-encode-binary (string)
70   (decode-hex-string
71    (sha1-string string)))
72
73 (make-obsolete 'sha1-encode "It's old API.")
74 (make-obsolete 'sha1-encode-binary "It's old API.")
75
76 (provide 'sha1)
77
78 ;;; sha1.el ends here