1 ;;; hmac-md5.el --- Compute HMAC-MD5.
3 ;; Copyright (C) 1999, 2001 Free Software Foundation, Inc.
5 ;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
6 ;; Keywords: HMAC, RFC 2104, HMAC-MD5, MD5, KEYED-MD5, CRAM-MD5
8 ;; This file is part of FLIM (Faithful Library about Internet Message).
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or
13 ;; (at your option) any later version.
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; Test cases from RFC 2202, "Test Cases for HMAC-MD5 and HMAC-SHA-1".
29 ;; (encode-hex-string (hmac-md5 "Hi There" (make-string 16 ?\x0b)))
30 ;; => "9294727a3638bb1c13f48ef8158bfc9d"
32 ;; (encode-hex-string (hmac-md5 "what do ya want for nothing?" "Jefe"))
33 ;; => "750c783e6ab0b503eaa86e310a5db738"
35 ;; (encode-hex-string (hmac-md5 (make-string 50 ?\xdd) (make-string 16 ?\xaa)))
36 ;; => "56be34521d144c88dbb8c733f0e8b3f6"
40 ;; (make-string 50 ?\xcd)
41 ;; (decode-hex-string "0102030405060708090a0b0c0d0e0f10111213141516171819")))
42 ;; => "697eaf0aca3a3aea3a75164746ffaa79"
45 ;; (hmac-md5 "Test With Truncation" (make-string 16 ?\x0c)))
46 ;; => "56461ef2342edc00f9bab995690efd4c"
49 ;; (hmac-md5-96 "Test With Truncation" (make-string 16 ?\x0c)))
50 ;; => "56461ef2342edc00f9bab995"
54 ;; "Test Using Larger Than Block-Size Key - Hash Key First"
55 ;; (make-string 80 ?\xaa)))
56 ;; => "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd"
60 ;; "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"
61 ;; (make-string 80 ?\xaa)))
62 ;; => "6f630fad67cda0ee1fb1f562db3aa53e"
66 (eval-when-compile (require 'hmac-def))
67 (require 'hex-util) ; (decode-hex-string STRING)
68 (require 'md5) ; expects (md5 STRING)
70 ;; To share *.elc files between Emacs w/ and w/o DL patch,
71 ;; this check must be done at load-time.
73 ((fboundp 'md5-binary)
77 ;; `md5' of v21 takes 4th arg CODING (and 5th arg NOERROR).
78 (md5 "" nil nil 'binary) ; => "d41d8cd98f00b204e9800998ecf8427e"
79 (wrong-number-of-arguments nil))
80 (defun md5-binary (string)
81 "Return the MD5 of STRING in binary form."
82 (decode-hex-string (md5 string nil nil 'binary))))
84 (defun md5-binary (string)
85 "Return the MD5 of STRING in binary form."
86 (decode-hex-string (md5 string)))))
88 (define-hmac-function hmac-md5 md5-binary 64 16) ; => (hmac-md5 TEXT KEY)
89 (define-hmac-function hmac-md5-96 md5-binary 64 16 96)
93 ;;; hmac-md5.el ends here