53 |
;;; 2000-05-12 added sha-1 example, added test case reference |
;;; 2000-05-12 added sha-1 example, added test case reference |
54 |
|
|
55 |
;;; Code: |
;;; Code: |
56 |
|
|
57 |
(eval-when-compile (require 'cl)) |
(eval-when-compile (require 'cl)) |
58 |
|
|
59 |
;; Magic character for inner HMAC round. 0x36 == 54 == '6' |
;; Magic character for inner HMAC round. 0x36 == 54 == '6' |
66 |
(defconst rfc2104-zero ?\x00) |
(defconst rfc2104-zero ?\x00) |
67 |
|
|
68 |
;; Alist for converting hex to decimal. |
;; Alist for converting hex to decimal. |
69 |
(defconst rfc2104-hex-alist |
(defconst rfc2104-hex-alist |
70 |
'((?0 . 0) (?a . 10) (?A . 10) |
'((?0 . 0) (?a . 10) (?A . 10) |
71 |
(?1 . 1) (?b . 11) (?B . 11) |
(?1 . 1) (?b . 11) (?B . 11) |
72 |
(?2 . 2) (?c . 12) (?C . 12) |
(?2 . 2) (?c . 12) (?C . 12) |
95 |
|
|
96 |
(defun rfc2104-hash (hash block-length hash-length key text) |
(defun rfc2104-hash (hash block-length hash-length key text) |
97 |
(let* (;; if key is longer than B, reset it to HASH(key) |
(let* (;; if key is longer than B, reset it to HASH(key) |
98 |
(key (if (> (length key) block-length) |
(key (if (> (length key) block-length) |
99 |
(funcall hash key) key)) |
(funcall hash key) key)) |
100 |
(k_ipad (append key nil)) |
(k_ipad (append key nil)) |
101 |
(k_opad (append key nil))) |
(k_opad (append key nil))) |