123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- (eval-when-compile (require 'cl))
- (defconst rfc2104-ipad ?\x36)
- (defconst rfc2104-opad ?\x5C)
- (defconst rfc2104-nybbles
- (let ((v (make-vector
-
- (1+ (max ?0 ?9 ?a ?f ?A ?F))
-
- nil))
- (ls '((?0 . 0) (?a . 10) (?A . 10)
- (?1 . 1) (?b . 11) (?B . 11)
- (?2 . 2) (?c . 12) (?C . 12)
- (?3 . 3) (?d . 13) (?D . 13)
- (?4 . 4) (?e . 14) (?E . 14)
- (?5 . 5) (?f . 15) (?F . 15)
- (?6 . 6)
- (?7 . 7)
- (?8 . 8)
- (?9 . 9))))
- (while ls
- (aset v (caar ls) (cdar ls))
- (setq ls (cdr ls)))
- v))
- (eval-when-compile
- (defmacro rfc2104-string-make-unibyte (string)
- "Return the unibyte equivalent of STRING.
- In XEmacs return just STRING."
- (if (featurep 'xemacs)
- string
- `(string-make-unibyte ,string))))
- (defun rfc2104-hash (hash block-length hash-length key text)
- (let* (
- (key (if (> (length key) block-length)
- (funcall hash key) key))
- (len (length key))
- (ipad (make-string block-length rfc2104-ipad))
- (opad (make-string (+ block-length hash-length) rfc2104-opad))
- c partial)
-
- (do ((i 0 (1+ i)))
- ((= len i))
- (setq c (aref key i))
- (aset ipad i (logxor rfc2104-ipad c))
- (aset opad i (logxor rfc2104-opad c)))
-
- (setq partial (rfc2104-string-make-unibyte
- (funcall hash (concat ipad text))))
-
- (do ((r 0 (+ 2 r))
- (w block-length (1+ w)))
- ((= (* 2 hash-length) r))
- (aset opad w
- (+ (* 16 (aref rfc2104-nybbles (aref partial r)))
- ( aref rfc2104-nybbles (aref partial (1+ r))))))
-
- (rfc2104-string-make-unibyte (funcall hash opad))))
- (provide 'rfc2104)
|