1 ;;; hmac-md5.el --- Compute HMAC-MD5.
3 ;; Copyright (C) 1999 Shuhei KOBAYASHI
5 ;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
6 ;; Kenichi OKADA <okada@opaopa.org>
7 ;; Maintainer: Kenichi OKADA <okada@opaopa.org>
8 ;; Keywords: HMAC, RFC 2104, HMAC-MD5, MD5, KEYED-MD5, CRAM-MD5
10 ;; This file is part of FLIM (Faithful Library about Internet Message).
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.
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.
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.
29 ;; Test cases from RFC 2202, "Test Cases for HMAC-MD5 and HMAC-SHA-1".
31 ;; (hmac-hex-string (hmac-md5 "Hi There" (make-string 16 ?\x0b)))
32 ;; => "9294727a3638bb1c13f48ef8158bfc9d"
34 ;; (hmac-hex-string (hmac-md5 "what do ya want for nothing?" "Jefe"))
35 ;; => "750c783e6ab0b503eaa86e310a5db738"
37 ;; (hmac-hex-string (hmac-md5 (make-string 50 ?\xdd) (make-string 16 ?\xaa)))
38 ;; => "56be34521d144c88dbb8c733f0e8b3f6"
42 ;; (make-string 50 ?\xcd)
43 ;; (hmac-unhex-string "0102030405060708090a0b0c0d0e0f10111213141516171819")))
44 ;; => "697eaf0aca3a3aea3a75164746ffaa79"
47 ;; (hmac-md5 "Test With Truncation" (make-string 16 ?\x0c)))
48 ;; => "56461ef2342edc00f9bab995690efd4c"
50 ;; (hmac-md5-96 "Test With Truncation" (make-string 16 ?\x0c)))
51 ;; => "56461ef2342edc00f9bab995"
55 ;; "Test Using Larger Than Block-Size Key - Hash Key First"
56 ;; (make-string 80 ?\xaa)))
57 ;; => "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd"
61 ;; "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"
62 ;; (make-string 80 ?\xaa)))
63 ;; => "6f630fad67cda0ee1fb1f562db3aa53e"
67 (eval-when-compile (require 'hmac-def))
68 (require 'md5) ; expects (md5 STRING)
71 ((and (featurep 'xemacs)
72 (>= (function-max-args 'md5) 4))
73 ;; recent XEmacs has `md5' as a built-in function.
74 ;; and default CODING is 'undecided.
76 (define-hmac-function hmac-md5
78 (object &optional start end)
79 (md5 object start end 'binary)) 64 16)
82 (define-hmac-function hmac-md5 md5 64 16)
84 ; => (hmac-md5 TEXT KEY)
86 ;; (define-hmac-function hmac-md5-96 md5 64 16 96)
87 ;; => (hmac-md5-96 TEXT KEY)
91 ;;; hmac-md5.el ends here.