annotate lisp/net/hmac-md5.el @ 94357:5f0e2d26daed

(fortran-mode-syntax-table): Change `;' to punctuation now it's not needed for abbrevs. (fortran-mode-abbrev-table): Remove defvar, make use of new define-abbrev-table :regexp feature.
author Glenn Morris <rgm@gnu.org>
date Sat, 26 Apr 2008 02:33:47 +0000
parents 1e3a407766b9
children 91e5880a36c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
86795
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1 ;;; hmac-md5.el --- Compute HMAC-MD5.
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
2
87665
b9e8ab94c460 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86795
diff changeset
3 ;; Copyright (C) 1999, 2001, 2007, 2008 Free Software Foundation, Inc.
86795
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
4
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
5 ;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
6 ;; Keywords: HMAC, RFC 2104, HMAC-MD5, MD5, KEYED-MD5, CRAM-MD5
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
7
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
9
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 3, or (at your option)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
13 ;; any later version.
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
14
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
19
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02110-1301, USA.
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
24
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
26
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27 ;; Test cases from RFC 2202, "Test Cases for HMAC-MD5 and HMAC-SHA-1".
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
29 ;; (encode-hex-string (hmac-md5 "Hi There" (make-string 16 ?\x0b)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
30 ;; => "9294727a3638bb1c13f48ef8158bfc9d"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
31 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
32 ;; (encode-hex-string (hmac-md5 "what do ya want for nothing?" "Jefe"))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
33 ;; => "750c783e6ab0b503eaa86e310a5db738"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
34 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
35 ;; (encode-hex-string (hmac-md5 (make-string 50 ?\xdd) (make-string 16 ?\xaa)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
36 ;; => "56be34521d144c88dbb8c733f0e8b3f6"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
37 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
38 ;; (encode-hex-string
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
39 ;; (hmac-md5
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40 ;; (make-string 50 ?\xcd)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
41 ;; (decode-hex-string "0102030405060708090a0b0c0d0e0f10111213141516171819")))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
42 ;; => "697eaf0aca3a3aea3a75164746ffaa79"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
43 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
44 ;; (encode-hex-string
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
45 ;; (hmac-md5 "Test With Truncation" (make-string 16 ?\x0c)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 ;; => "56461ef2342edc00f9bab995690efd4c"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48 ;; (encode-hex-string
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 ;; (hmac-md5-96 "Test With Truncation" (make-string 16 ?\x0c)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 ;; => "56461ef2342edc00f9bab995"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
51 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52 ;; (encode-hex-string
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 ;; (hmac-md5
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54 ;; "Test Using Larger Than Block-Size Key - Hash Key First"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55 ;; (make-string 80 ?\xaa)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 ;; => "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58 ;; (encode-hex-string
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
59 ;; (hmac-md5
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 ;; "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61 ;; (make-string 80 ?\xaa)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62 ;; => "6f630fad67cda0ee1fb1f562db3aa53e"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64 ;;; Code:
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 (eval-when-compile (require 'hmac-def))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67 (require 'hex-util) ; (decode-hex-string STRING)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68 (require 'md5) ; expects (md5 STRING)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70 (defun md5-binary (string)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 "Return the MD5 of STRING in binary form."
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72 (if (condition-case nil
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73 ;; `md5' of v21 takes 4th arg CODING (and 5th arg NOERROR).
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
74 (md5 "" nil nil 'binary) ; => "d41d8cd98f00b204e9800998ecf8427e"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 (wrong-number-of-arguments nil))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76 (decode-hex-string (md5 string nil nil 'binary))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77 (decode-hex-string (md5 string))))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
78
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79 (define-hmac-function hmac-md5 md5-binary 64 16) ; => (hmac-md5 TEXT KEY)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80 (define-hmac-function hmac-md5-96 md5-binary 64 16 96)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
82 (provide 'hmac-md5)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
83
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87665
diff changeset
84 ;; arch-tag: 0ab3f4f6-3d4b-4167-a9fa-635b7fed7f27
86795
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
85 ;;; hmac-md5.el ends here