annotate lisp/net/hmac-md5.el @ 107544:afbf4ad814c7

Call `select' for interrupted `connect' rather than creating new socket (Bug#5173).
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Thu, 25 Mar 2010 17:48:52 +0900
parents bb307bf2e752
children 8d09094063d0
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
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
3 ;; Copyright (C) 1999, 2001, 2007, 2008, 2009, 2010 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>
107390
bb307bf2e752 Fix keywords.
Juri Linkov <juri@jurta.org>
parents: 107358
diff changeset
6 ;; Keywords: HMAC, RFC2104, HMAC-MD5, MD5, KEYED-MD5, CRAM-MD5
86795
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
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
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
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
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
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
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
22
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
23 ;;; Commentary:
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 ;; 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
26 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27 ;; (encode-hex-string (hmac-md5 "Hi There" (make-string 16 ?\x0b)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28 ;; => "9294727a3638bb1c13f48ef8158bfc9d"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
29 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
30 ;; (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
31 ;; => "750c783e6ab0b503eaa86e310a5db738"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
32 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
33 ;; (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
34 ;; => "56be34521d144c88dbb8c733f0e8b3f6"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
35 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
36 ;; (encode-hex-string
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
37 ;; (hmac-md5
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
38 ;; (make-string 50 ?\xcd)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
39 ;; (decode-hex-string "0102030405060708090a0b0c0d0e0f10111213141516171819")))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40 ;; => "697eaf0aca3a3aea3a75164746ffaa79"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
41 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
42 ;; (encode-hex-string
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
43 ;; (hmac-md5 "Test With Truncation" (make-string 16 ?\x0c)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
44 ;; => "56461ef2342edc00f9bab995690efd4c"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
45 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 ;; (encode-hex-string
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 ;; (hmac-md5-96 "Test With Truncation" (make-string 16 ?\x0c)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48 ;; => "56461ef2342edc00f9bab995"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 ;; (encode-hex-string
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
51 ;; (hmac-md5
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52 ;; "Test Using Larger Than Block-Size Key - Hash Key First"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 ;; (make-string 80 ?\xaa)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54 ;; => "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 ;; (encode-hex-string
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 ;; (hmac-md5
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58 ;; "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
59 ;; (make-string 80 ?\xaa)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 ;; => "6f630fad67cda0ee1fb1f562db3aa53e"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62 ;;; Code:
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 (eval-when-compile (require 'hmac-def))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 (require 'hex-util) ; (decode-hex-string STRING)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 (require 'md5) ; expects (md5 STRING)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68 (defun md5-binary (string)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 "Return the MD5 of STRING in binary form."
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70 (if (condition-case nil
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 ;; `md5' of v21 takes 4th arg CODING (and 5th arg NOERROR).
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72 (md5 "" nil nil 'binary) ; => "d41d8cd98f00b204e9800998ecf8427e"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73 (wrong-number-of-arguments nil))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
74 (decode-hex-string (md5 string nil nil 'binary))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 (decode-hex-string (md5 string))))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77 (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
78 (define-hmac-function hmac-md5-96 md5-binary 64 16 96)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80 (provide 'hmac-md5)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
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
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
83 ;;; hmac-md5.el ends here