Mercurial > emacs
annotate lisp/net/hmac-md5.el @ 101406:6381c0548cdd
fix comments in last change
author | Adrian Robert <Adrian.B.Robert@gmail.com> |
---|---|
date | Fri, 23 Jan 2009 14:53:11 +0000 |
parents | a9dc0e7c3f2b |
children | 1d1d5d9bd884 |
rev | line source |
---|---|
86795 | 1 ;;; hmac-md5.el --- Compute HMAC-MD5. |
2 | |
100908 | 3 ;; Copyright (C) 1999, 2001, 2007, 2008, 2009 Free Software Foundation, Inc. |
86795 | 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 file is part of GNU Emacs. | |
9 | |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
86795 | 11 ;; it under the terms of the GNU General Public License as published by |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; (at your option) any later version. |
86795 | 14 |
15 ;; GNU Emacs 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. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
86795 | 22 |
23 ;;; Commentary: | |
24 | |
25 ;; Test cases from RFC 2202, "Test Cases for HMAC-MD5 and HMAC-SHA-1". | |
26 ;; | |
27 ;; (encode-hex-string (hmac-md5 "Hi There" (make-string 16 ?\x0b))) | |
28 ;; => "9294727a3638bb1c13f48ef8158bfc9d" | |
29 ;; | |
30 ;; (encode-hex-string (hmac-md5 "what do ya want for nothing?" "Jefe")) | |
31 ;; => "750c783e6ab0b503eaa86e310a5db738" | |
32 ;; | |
33 ;; (encode-hex-string (hmac-md5 (make-string 50 ?\xdd) (make-string 16 ?\xaa))) | |
34 ;; => "56be34521d144c88dbb8c733f0e8b3f6" | |
35 ;; | |
36 ;; (encode-hex-string | |
37 ;; (hmac-md5 | |
38 ;; (make-string 50 ?\xcd) | |
39 ;; (decode-hex-string "0102030405060708090a0b0c0d0e0f10111213141516171819"))) | |
40 ;; => "697eaf0aca3a3aea3a75164746ffaa79" | |
41 ;; | |
42 ;; (encode-hex-string | |
43 ;; (hmac-md5 "Test With Truncation" (make-string 16 ?\x0c))) | |
44 ;; => "56461ef2342edc00f9bab995690efd4c" | |
45 ;; | |
46 ;; (encode-hex-string | |
47 ;; (hmac-md5-96 "Test With Truncation" (make-string 16 ?\x0c))) | |
48 ;; => "56461ef2342edc00f9bab995" | |
49 ;; | |
50 ;; (encode-hex-string | |
51 ;; (hmac-md5 | |
52 ;; "Test Using Larger Than Block-Size Key - Hash Key First" | |
53 ;; (make-string 80 ?\xaa))) | |
54 ;; => "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd" | |
55 ;; | |
56 ;; (encode-hex-string | |
57 ;; (hmac-md5 | |
58 ;; "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data" | |
59 ;; (make-string 80 ?\xaa))) | |
60 ;; => "6f630fad67cda0ee1fb1f562db3aa53e" | |
61 | |
62 ;;; Code: | |
63 | |
64 (eval-when-compile (require 'hmac-def)) | |
65 (require 'hex-util) ; (decode-hex-string STRING) | |
66 (require 'md5) ; expects (md5 STRING) | |
67 | |
68 (defun md5-binary (string) | |
69 "Return the MD5 of STRING in binary form." | |
70 (if (condition-case nil | |
71 ;; `md5' of v21 takes 4th arg CODING (and 5th arg NOERROR). | |
72 (md5 "" nil nil 'binary) ; => "d41d8cd98f00b204e9800998ecf8427e" | |
73 (wrong-number-of-arguments nil)) | |
74 (decode-hex-string (md5 string nil nil 'binary)) | |
75 (decode-hex-string (md5 string)))) | |
76 | |
77 (define-hmac-function hmac-md5 md5-binary 64 16) ; => (hmac-md5 TEXT KEY) | |
78 (define-hmac-function hmac-md5-96 md5-binary 64 16 96) | |
79 | |
80 (provide 'hmac-md5) | |
81 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87665
diff
changeset
|
82 ;; arch-tag: 0ab3f4f6-3d4b-4167-a9fa-635b7fed7f27 |
86795 | 83 ;;; hmac-md5.el ends here |