Mercurial > emacs
comparison lisp/gnus/rfc2104.el @ 89617:f7f76c4ee683
* rfc2104.el (rfc2104-hexstring-to-byte-list): Renamed from
rfc2104-hexstring-to-bitstring and changed to return a byte list.
(rfc2104-hash): Convert the result of concat to unibyte string.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Thu, 13 Nov 2003 08:49:29 +0000 |
parents | 375f2633d815 |
children | 561b856c5b1f |
comparison
equal
deleted
inserted
replaced
89616:3c6a6f43d21b | 89617:f7f76c4ee683 |
---|---|
49 ;;; 1998-08-26 don't require hexl | 49 ;;; 1998-08-26 don't require hexl |
50 ;;; 1998-09-25 renamed from hmac.el to rfc2104.el, also renamed functions | 50 ;;; 1998-09-25 renamed from hmac.el to rfc2104.el, also renamed functions |
51 ;;; 1999-10-23 included in pgnus | 51 ;;; 1999-10-23 included in pgnus |
52 ;;; 2000-08-15 `rfc2104-hexstring-to-bitstring' | 52 ;;; 2000-08-15 `rfc2104-hexstring-to-bitstring' |
53 ;;; 2000-05-12 added sha-1 example, added test case reference | 53 ;;; 2000-05-12 added sha-1 example, added test case reference |
54 ;;; 2003-11-13 change rfc2104-hexstring-to-bitstring to ...-byte-list | |
54 | 55 |
55 ;;; Code: | 56 ;;; Code: |
56 | 57 |
57 (eval-when-compile (require 'cl)) | 58 (eval-when-compile (require 'cl)) |
58 | 59 |
84 (+ (* 16 (rfc2104-hex-to-int (cdr str))) | 85 (+ (* 16 (rfc2104-hex-to-int (cdr str))) |
85 (cdr (assoc (car str) rfc2104-hex-alist))) | 86 (cdr (assoc (car str) rfc2104-hex-alist))) |
86 (rfc2104-hex-to-int (reverse (append str nil)))) | 87 (rfc2104-hex-to-int (reverse (append str nil)))) |
87 0)) | 88 0)) |
88 | 89 |
89 (defun rfc2104-hexstring-to-bitstring (str) | 90 (defun rfc2104-hexstring-to-byte-list (str) |
90 (let (out) | 91 (let (out) |
91 (while (< 0 (length str)) | 92 (while (< 0 (length str)) |
92 (push (rfc2104-hex-to-int (substring str -2)) out) | 93 (push (rfc2104-hex-to-int (substring str -2)) out) |
93 (setq str (substring str 0 -2))) | 94 (setq str (substring str 0 -2))) |
94 (concat out))) | 95 out)) |
95 | 96 |
96 (defun rfc2104-hash (hash block-length hash-length key text) | 97 (defun rfc2104-hash (hash block-length hash-length key text) |
97 (let* (;; if key is longer than B, reset it to HASH(key) | 98 (let* (;; if key is longer than B, reset it to HASH(key) |
98 (key (if (> (length key) block-length) | 99 (key (if (> (length key) block-length) |
99 (funcall hash key) key)) | 100 (funcall hash key) key)) |
106 (setq k_opad (append k_opad (list rfc2104-zero)))) | 107 (setq k_opad (append k_opad (list rfc2104-zero)))) |
107 ;; XOR key with ipad/opad into k_ipad/k_opad | 108 ;; XOR key with ipad/opad into k_ipad/k_opad |
108 (setq k_ipad (mapcar (lambda (c) (logxor c rfc2104-ipad)) k_ipad)) | 109 (setq k_ipad (mapcar (lambda (c) (logxor c rfc2104-ipad)) k_ipad)) |
109 (setq k_opad (mapcar (lambda (c) (logxor c rfc2104-opad)) k_opad)) | 110 (setq k_opad (mapcar (lambda (c) (logxor c rfc2104-opad)) k_opad)) |
110 ;; perform outer hash | 111 ;; perform outer hash |
111 (funcall hash (concat k_opad (rfc2104-hexstring-to-bitstring | 112 (funcall hash |
112 ;; perform inner hash | 113 (encode-coding-string |
113 (funcall hash (concat k_ipad text))))))) | 114 (concat k_opad (rfc2104-hexstring-to-byte-list |
115 ;; perform inner hash | |
116 (funcall hash (concat k_ipad text)))) | |
117 'iso-latin-1)))) | |
114 | 118 |
115 (provide 'rfc2104) | 119 (provide 'rfc2104) |
116 | 120 |
117 ;;; rfc2104.el ends here | 121 ;;; rfc2104.el ends here |