annotate lisp/net/hmac-def.el @ 109744:fdbd24f8d999

Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *). * b2m.c (concat, fatal): Use const char*. (main): Don't assign labels a string literal. * ebrowse.c (struct member): filename, def_filename is const. (struct sym): filename, sfilename is const. (struct kw): name is const. (add_sym, yyerror, token_string, insert_keyword, main): Use const char*. * emacsclient.c (message, sock_err_message, send_to_emacs) (quote_argument, set_local_socket) (start_daemon_and_retry_set_socket): Use const char*. * etags.c (compressor, language, Ada_suffix, Ada_help, Asm_suffixes) (Asm_help, default_C_suffixes, default_C_help, Cplusplus_suffixes) (Cplusplus_help, Cjava_suffixes, Cobol_suffixes, Cstar_suffixes) (Erlang_suffixes, Erlang_help, Forth_suffixes, Forth_help) (Fortran_suffixes, Fortran_help, HTML_suffixes, HTML_help) (Lisp_suffixes, Lisp_help, Lua_suffixes, Lua_help) (Makefile_filenames, Makefile_help, Objc_suffixes, Objc_help) (Pascal_suffixes, Pascal_help, Perl_suffixes, Perl_interpreters) (Perl_help, PHP_suffixes, PHP_help, plain_C_suffixses, PS_suffixes) (PS_help, Prolog_suffixes, Prolog_help, Python_suffixes, Python_help) (Scheme_suffixes, Scheme_help, TeX_suffixes, TeX_help, Texinfo_suffixes) (Texinfo_help, Yacc_suffixes, Yacc_help, auto_help, none_help) (no_lang_help, print_language_names) (get_language_from_interpreter, get_language_from_filename) (init, make_tag, struct C_stab_entry, write_classname, TEX_defenv) (TEX_decode_env, nocase_tail, savestr, savenstr, fatal, pfatal) (concat): Use const char*. * make-docfile.c (error, fatal, scan_c_file, scan_lisp_file): Use const char *. * movemail.c (fatal, error, concat): Use const char *. * pop.c (pop_multi_first, socket_connection, sendline): Use conat char*. * pop.h (pop_multi_first): Use const char *. (_ARGS): Remove. * sorted-doc.c (error, fatal, states): Use const char *. * update-game-score.c (get_prefix, write_scores, main): Use const char*.
author Jan D <jan.h.d@swipnet.se>
date Wed, 11 Aug 2010 10:20:34 +0200
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-def.el --- A macro for defining HMAC functions.
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
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
107390
bb307bf2e752 Fix keywords.
Juri Linkov <juri@jurta.org>
parents: 107358
diff changeset
25 ;; This program is implemented from RFC2104,
86795
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
26 ;; "HMAC: Keyed-Hashing for Message Authentication".
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28 ;;; Code:
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 (defmacro define-hmac-function (name H B L &optional bit)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
31 "Define a function NAME(TEXT KEY) which computes HMAC with function H.
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 HMAC function is H(KEY XOR opad, H(KEY XOR ipad, TEXT)):
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 H is a cryptographic hash function, such as SHA1 and MD5, which takes
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
36 a string and return a digest of it (in binary form).
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
37 B is a byte-length of a block size of H. (B=64 for both SHA1 and MD5.)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
38 L is a byte-length of hash outputs. (L=16 for MD5, L=20 for SHA1.)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
39 If BIT is non-nil, truncate output to specified bits."
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40 `(defun ,name (text key)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
41 ,(concat "Compute "
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
42 (upcase (symbol-name name))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
43 " over TEXT with KEY.")
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
44 (let ((key-xor-ipad (make-string ,B ?\x36))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
45 (key-xor-opad (make-string ,B ?\x5C))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 (len (length key))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 (pos 0))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48 (unwind-protect
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 (progn
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 ;; if `key' is longer than the block size, apply hash function
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
51 ;; to `key' and use the result as a real `key'.
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52 (if (> len ,B)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 (setq key (,H key)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54 len ,L))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55 (while (< pos len)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 (aset key-xor-ipad pos (logxor (aref key pos) ?\x36))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 (aset key-xor-opad pos (logxor (aref key pos) ?\x5C))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58 (setq pos (1+ pos)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
59 (setq key-xor-ipad (unwind-protect
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 (concat key-xor-ipad text)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61 (fillarray key-xor-ipad 0))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62 key-xor-ipad (unwind-protect
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63 (,H key-xor-ipad)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64 (fillarray key-xor-ipad 0))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 key-xor-opad (unwind-protect
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 (concat key-xor-opad key-xor-ipad)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67 (fillarray key-xor-opad 0))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68 key-xor-opad (unwind-protect
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 (,H key-xor-opad)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70 (fillarray key-xor-opad 0)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 ;; now `key-xor-opad' contains
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72 ;; H(KEY XOR opad, H(KEY XOR ipad, TEXT)).
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73 ,(if (and bit (< (/ bit 8) L))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
74 `(substring key-xor-opad 0 ,(/ bit 8))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 ;; return a copy of `key-xor-opad'.
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76 `(concat key-xor-opad)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77 ;; cleanup.
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
78 (fillarray key-xor-ipad 0)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79 (fillarray key-xor-opad 0)))))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81 (provide 'hmac-def)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
82
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87665
diff changeset
83 ;; arch-tag: 645adcef-b835-4900-a10a-11f636c982b9
86795
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
84 ;;; hmac-def.el ends here