51 |
;;; 1999-10-23 included in pgnus |
;;; 1999-10-23 included in pgnus |
52 |
;;; 2000-08-15 `rfc2104-hexstring-to-bitstring' |
;;; 2000-08-15 `rfc2104-hexstring-to-bitstring' |
53 |
;;; 2000-05-12 added sha-1 example, added test case reference |
;;; 2000-05-12 added sha-1 example, added test case reference |
54 |
|
;;; 2003-11-13 change rfc2104-hexstring-to-bitstring to ...-byte-list |
55 |
|
|
56 |
;;; Code: |
;;; Code: |
57 |
|
|
87 |
(rfc2104-hex-to-int (reverse (append str nil)))) |
(rfc2104-hex-to-int (reverse (append str nil)))) |
88 |
0)) |
0)) |
89 |
|
|
90 |
(defun rfc2104-hexstring-to-bitstring (str) |
(defun rfc2104-hexstring-to-byte-list (str) |
91 |
(let (out) |
(let (out) |
92 |
(while (< 0 (length str)) |
(while (< 0 (length str)) |
93 |
(push (rfc2104-hex-to-int (substring str -2)) out) |
(push (rfc2104-hex-to-int (substring str -2)) out) |
94 |
(setq str (substring str 0 -2))) |
(setq str (substring str 0 -2))) |
95 |
(concat out))) |
out)) |
96 |
|
|
97 |
(defun rfc2104-hash (hash block-length hash-length key text) |
(defun rfc2104-hash (hash block-length hash-length key text) |
98 |
(let* (;; if key is longer than B, reset it to HASH(key) |
(let* (;; if key is longer than B, reset it to HASH(key) |
109 |
(setq k_ipad (mapcar (lambda (c) (logxor c rfc2104-ipad)) k_ipad)) |
(setq k_ipad (mapcar (lambda (c) (logxor c rfc2104-ipad)) k_ipad)) |
110 |
(setq k_opad (mapcar (lambda (c) (logxor c rfc2104-opad)) k_opad)) |
(setq k_opad (mapcar (lambda (c) (logxor c rfc2104-opad)) k_opad)) |
111 |
;; perform outer hash |
;; perform outer hash |
112 |
(funcall hash (concat k_opad (rfc2104-hexstring-to-bitstring |
(funcall hash |
113 |
;; perform inner hash |
(encode-coding-string |
114 |
(funcall hash (concat k_ipad text))))))) |
(concat k_opad (rfc2104-hexstring-to-byte-list |
115 |
|
;; perform inner hash |
116 |
|
(funcall hash (concat k_ipad text)))) |
117 |
|
'iso-latin-1)))) |
118 |
|
|
119 |
(provide 'rfc2104) |
(provide 'rfc2104) |
120 |
|
|