1 ;;; hmac-md5.el --- Compute HMAC-MD5.
3 ;; Copyright (C) 1999 Shuhei KOBAYASHI
5 ;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
6 ;; Keywords: HMAC, RFC 2104, HMAC-MD5, MD5, KEYED-MD5, CRAM-MD5
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.
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.
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.
25 ;; Test cases from RFC 2202, "Test Cases for HMAC-MD5 and HMAC-SHA-1".
27 ;; (hmac-hex-string (hmac-md5 "Hi There" (make-string 16 ?\x0b)))
28 ;; => "9294727a3638bb1c13f48ef8158bfc9d"
30 ;; (hmac-hex-string (hmac-md5 "what do ya want for nothing?" "Jefe"))
31 ;; => "750c783e6ab0b503eaa86e310a5db738"
33 ;; (hmac-hex-string (hmac-md5 (make-string 50 ?\xdd) (make-string 16 ?\xaa)))
34 ;; => "56be34521d144c88dbb8c733f0e8b3f6"
38 ;; (make-string 50 ?\xcd)
39 ;; (hmac-unhex-string "0102030405060708090a0b0c0d0e0f10111213141516171819")))
40 ;; => "697eaf0aca3a3aea3a75164746ffaa79"
43 ;; (hmac-md5 "Test With Truncation" (make-string 16 ?\x0c)))
44 ;; => "56461ef2342edc00f9bab995690efd4c"
46 ;; (hmac-md5-96 "Test With Truncation" (make-string 16 ?\x0c)))
47 ;; => "56461ef2342edc00f9bab995"
51 ;; "Test Using Larger Than Block-Size Key - Hash Key First"
52 ;; (make-string 80 ?\xaa)))
53 ;; => "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd"
57 ;; "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"
58 ;; (make-string 80 ?\xaa)))
59 ;; => "6f630fad67cda0ee1fb1f562db3aa53e"
63 (eval-when-compile (require 'hmac-def))
64 (require 'md5) ; expects (md5 STRING)
68 (subrp (symbol-function 'md5)))
69 ;; recent XEmacs has `md5' as a built-in function.
70 ;; and default CODING is 'undecided.
72 (define-hmac-function hmac-md5
74 (object &optional start end)
75 (md5 object start end 'binary)) 64 16)
78 (define-hmac-function hmac-md5 md5 64 16)
80 ; => (hmac-md5 TEXT KEY)
82 ;; (define-hmac-function hmac-md5-96 md5 64 16 96)
83 ;; => (hmac-md5-96 TEXT KEY)
87 ;;; hmac-md5.el ends here.