rename sasl-plain sasl-cram-md5
[elisp/flim.git] / hmac-md5.el
1 ;;; hmac-md5.el --- Compute HMAC-MD5.
2
3 ;; Copyright (C) 1999 Shuhei KOBAYASHI
4
5 ;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
6 ;; Keywords: HMAC, RFC 2104, HMAC-MD5, MD5, KEYED-MD5, CRAM-MD5
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 ;; Test cases from RFC 2202, "Test Cases for HMAC-MD5 and HMAC-SHA-1".
26 ;;
27 ;; (hmac-hex-string (hmac-md5 "Hi There" (make-string 16 ?\x0b)))
28 ;;  => "9294727a3638bb1c13f48ef8158bfc9d"
29 ;;
30 ;; (hmac-hex-string (hmac-md5 "what do ya want for nothing?" "Jefe"))
31 ;;  => "750c783e6ab0b503eaa86e310a5db738"
32 ;;
33 ;; (hmac-hex-string (hmac-md5 (make-string 50 ?\xdd) (make-string 16 ?\xaa)))
34 ;;  => "56be34521d144c88dbb8c733f0e8b3f6"
35 ;;
36 ;; (hmac-hex-string
37 ;;  (hmac-md5
38 ;;   (make-string 50 ?\xcd)
39 ;;   (hmac-unhex-string "0102030405060708090a0b0c0d0e0f10111213141516171819")))
40 ;;  => "697eaf0aca3a3aea3a75164746ffaa79"
41 ;;
42 ;; (hmac-hex-string
43 ;;  (hmac-md5 "Test With Truncation" (make-string 16 ?\x0c)))
44 ;;  => "56461ef2342edc00f9bab995690efd4c"
45 ;; (hmac-hex-string
46 ;;  (hmac-md5-96 "Test With Truncation" (make-string 16 ?\x0c)))
47 ;;  => "56461ef2342edc00f9bab995"
48 ;;
49 ;; (hmac-hex-string
50 ;;  (hmac-md5
51 ;;   "Test Using Larger Than Block-Size Key - Hash Key First"
52 ;;   (make-string 80 ?\xaa)))
53 ;;  => "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd"
54 ;;
55 ;; (hmac-hex-string
56 ;;  (hmac-md5
57 ;;   "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"
58 ;;   (make-string 80 ?\xaa)))
59 ;;  => "6f630fad67cda0ee1fb1f562db3aa53e"
60
61 ;;; Code:
62
63 (eval-when-compile (require 'hmac-def))
64 (require 'md5)                          ; expects (md5 STRING)
65
66 (cond
67  ((and (fboundp 'md5)
68        (subrp (symbol-function 'md5)))
69   ;; recent XEmacs has `md5' as a built-in function.
70   ;; and default CODING is 'undecided.
71   ;; 
72   (define-hmac-function hmac-md5 
73     (lambda
74       (object &optional start end)
75       (md5 object start end 'binary)) 64 16)
76   )
77  (t
78   (define-hmac-function hmac-md5 md5 64 16)
79   ))
80 ; => (hmac-md5 TEXT KEY)
81
82 ;; (define-hmac-function hmac-md5-96 md5 64 16 96)
83 ;;  => (hmac-md5-96 TEXT KEY)
84
85 (provide 'hmac-md5)
86
87 ;;; hmac-md5.el ends here.