From: okada Date: Mon, 22 Nov 1999 15:22:56 +0000 (+0000) Subject: * hex-util.el: New file. X-Git-Tag: slim-1_13_2~3 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=753bc0435f20689eddf43c41c3589b9586a908d3;p=elisp%2Fflim.git * hex-util.el: New file. * hmac-util.el: Remove. * hmac-md5.el: Update. * FLIM-ELS (flim-modeules): Rename `hex-util' from `hmac-util'. --- diff --git a/ChangeLog b/ChangeLog index b184c17..8c2e7bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,21 +1,29 @@ +1999-10-23 Kenichi OKADA + + * hex-util.el: New file. + * hmac-util.el: Remove. + * hmac-md5.el: Update. + * FLIM-ELS (flim-modeules): Rename `hex-util' from `hmac-util'. + 1999-10-22 Kenichi OKADA - * smtp.el (smtp-via-smtp): Fix to use `smtp-authentication-type', + * smtp.el (smtp-via-smtp): Fix to use `smtp-authentication-type', `smtp-authentication-user', `smtp-authentication-passphrase' and `smtp-connection-type'. 1999-10-22 Daiki Ueno - * smtp.el (smtp-authentication-type): New variable. - (smtp-authentication-user): New variable. - (smtp-authentication-passphrase): New variable. - (smtp-connection-type): New variable. + * smtp.el (smtp-authentication-type): New variable. + (smtp-authentication-user): New variable. + (smtp-authentication-passphrase): New variable. + (smtp-connection-type): New variable. -1999-10-20 Kenichi OKADA + +1999-10-21 Kenichi OKADA * SLIM: Version 1.13.1 released. -1999-10-20 Kenichi OKADA +1999-10-21 Kenichi OKADA * SLIM-TIPS: Add comment. @@ -51,6 +59,7 @@ * hmac-def.el (define-hmac-function): Update to delete insecure sequences. + 1999-10-20 Kenichi OKADA * SLIM: Version 1.13.0 released. @@ -95,6 +104,7 @@ * smtp.el (smtp-via-smtp): Use sasl.el for SASL. * FLIM-ELS (flim-modules): Add `sasl'. + 1999-08-17 MORIOKA Tomohiko * FLIM: Version 1.13.2 (Kasanui) released. diff --git a/FLIM-ELS b/FLIM-ELS index 11a40ba..ae1b06f 100644 --- a/FLIM-ELS +++ b/FLIM-ELS @@ -13,7 +13,7 @@ smtp smtpmail sasl md5 md5-el md5-dl sha1 sha1-el sha1-dl - hmac-def hmac-util hmac-md5 hmac-sha1 + hmac-def hmac-md5 hmac-sha1 hex-util starttls)) (unless (and (fboundp 'base64-encode-string) diff --git a/hex-util.el b/hex-util.el new file mode 100644 index 0000000..72ec56f --- /dev/null +++ b/hex-util.el @@ -0,0 +1,73 @@ +;;; hex-util.el --- Functions to encode/decode hexadecimal string. + +;; Copyright (C) 1999 Shuhei KOBAYASHI + +;; Author: Shuhei KOBAYASHI +;; Keywords: data + +;; This file is part of FLIM (Faithful Library about Internet Message). + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation; either version 2, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Commentary: + +;;; Code: + +(eval-when-compile + (defmacro hex-char-to-num (chr) + (` (let ((chr (, chr))) + (cond + ((and (<= ?a chr)(<= chr ?f)) (+ (- chr ?a) 10)) + ((and (<= ?A chr)(<= chr ?F)) (+ (- chr ?A) 10)) + ((and (<= ?0 chr)(<= chr ?9)) (- chr ?0)) + (t (error "Invalid hexadecimal digit `%c'" chr)))))) + (defmacro num-to-hex-char (num) + (` (aref "0123456789abcdef" (, num))))) + +(defun decode-hex-string (string) + "Decode hexadecimal STRING to octet string." + (let* ((len (length string)) + (dst (make-string (/ len 2) 0)) + (idx 0)(pos 0)) + (while (< pos len) +;;;; logior and lsh are not byte-coded. +;;;; (aset dst idx (logior (lsh (hex-char-to-num (aref string pos)) 4) +;;;; (hex-char-to-num (aref string (1+ pos))))) + (aset dst idx (+ (* (hex-char-to-num (aref string pos)) 16) + (hex-char-to-num (aref string (1+ pos))))) + (setq idx (1+ idx) + pos (+ 2 pos))) + dst)) + +(defun encode-hex-string (string) + "Encode octet STRING to hexadecimal string." + (let* ((len (length string)) + (dst (make-string (* len 2) 0)) + (idx 0)(pos 0)) + (while (< pos len) +;;;; logand and lsh are not byte-coded. +;;;; (aset dst idx (num-to-hex-char (logand (lsh (aref string pos) -4) 15))) + (aset dst idx (num-to-hex-char (/ (aref string pos) 16))) + (setq idx (1+ idx)) +;;;; (aset dst idx (num-to-hex-char (logand (aref string pos) 15))) + (aset dst idx (num-to-hex-char (% (aref string pos) 16))) + (setq idx (1+ idx) + pos (1+ pos))) + dst)) + +(provide 'hex-util) + +;;; hex-util.el ends here diff --git a/hmac-md5.el b/hmac-md5.el index d627622..9c936d0 100644 --- a/hmac-md5.el +++ b/hmac-md5.el @@ -28,35 +28,35 @@ ;; Test cases from RFC 2202, "Test Cases for HMAC-MD5 and HMAC-SHA-1". ;; -;; (hmac-hex-string (hmac-md5 "Hi There" (make-string 16 ?\x0b))) +;; (encode-hex-string (hmac-md5 "Hi There" (make-string 16 ?\x0b))) ;; => "9294727a3638bb1c13f48ef8158bfc9d" ;; -;; (hmac-hex-string (hmac-md5 "what do ya want for nothing?" "Jefe")) +;; (encode-hex-string (hmac-md5 "what do ya want for nothing?" "Jefe")) ;; => "750c783e6ab0b503eaa86e310a5db738" ;; -;; (hmac-hex-string (hmac-md5 (make-string 50 ?\xdd) (make-string 16 ?\xaa))) +;; (encode-hex-string (hmac-md5 (make-string 50 ?\xdd) (make-string 16 ?\xaa))) ;; => "56be34521d144c88dbb8c733f0e8b3f6" ;; -;; (hmac-hex-string +;; (encode-hex-string ;; (hmac-md5 ;; (make-string 50 ?\xcd) -;; (hmac-unhex-string "0102030405060708090a0b0c0d0e0f10111213141516171819"))) +;; (decode-hex-string "0102030405060708090a0b0c0d0e0f10111213141516171819"))) ;; => "697eaf0aca3a3aea3a75164746ffaa79" ;; -;; (hmac-hex-string +;; (encode-hex-string ;; (hmac-md5 "Test With Truncation" (make-string 16 ?\x0c))) ;; => "56461ef2342edc00f9bab995690efd4c" -;; (hmac-hex-string +;; (encode-hex-string ;; (hmac-md5-96 "Test With Truncation" (make-string 16 ?\x0c))) ;; => "56461ef2342edc00f9bab995" ;; -;; (hmac-hex-string +;; (encode-hex-string ;; (hmac-md5 ;; "Test Using Larger Than Block-Size Key - Hash Key First" ;; (make-string 80 ?\xaa))) ;; => "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd" ;; -;; (hmac-hex-string +;; (encode-hex-string ;; (hmac-md5 ;; "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data" ;; (make-string 80 ?\xaa))) @@ -65,27 +65,31 @@ ;;; Code: (eval-when-compile (require 'hmac-def)) +(require 'hex-util) ; (decode-hex-string STRING) (require 'md5) ; expects (md5 STRING) -(cond - ((and (featurep 'xemacs) - (>= (function-max-args 'md5) 4)) - ;; recent XEmacs has `md5' as a built-in function. - ;; and default CODING is 'undecided. - ;; - (define-hmac-function hmac-md5 - (lambda - (object &optional start end) - (md5 object start end 'binary)) 64 16) - ) - (t - (define-hmac-function hmac-md5 md5 64 16) - )) -; => (hmac-md5 TEXT KEY) +;; We cannot define this function in md5.el because recent XEmacs provides +;; built-in md5 function and provides feature 'md5 at startup. +(if (and (featurep 'xemacs) + (fboundp 'md5) + (subrp (symbol-function 'md5)) + (condition-case nil + ;; `md5' of XEmacs 21 takes 4th arg CODING (and 5th arg NOERROR). + (md5 "" nil nil 'binary) ; => "fb5d2156096fa1f254352f3cc3fada7e" + (error nil))) + ;; XEmacs 21. + (defun md5-binary (string &optional start end) + "Return the MD5 of STRING in binary form." + (decode-hex-string (md5 string start end 'binary))) + ;; not XEmacs 21 and not DL. + (if (not (fboundp 'md5-binary)) + (defun md5-binary (string) + "Return the MD5 of STRING in binary form." + (decode-hex-string (md5 string))))) -;; (define-hmac-function hmac-md5-96 md5 64 16 96) -;; => (hmac-md5-96 TEXT KEY) +(define-hmac-function hmac-md5 md5-binary 64 16) ; => (hmac-md5 TEXT KEY) +;; (define-hmac-function hmac-md5-96 md5-binary 64 16 96) (provide 'hmac-md5) -;;; hmac-md5.el ends here. +;;; hmac-md5.el ends here diff --git a/hmac-util.el b/hmac-util.el deleted file mode 100644 index 7d1c056..0000000 --- a/hmac-util.el +++ /dev/null @@ -1,62 +0,0 @@ -;;; hmac-util.el --- Utilities for HMAC functions. - -;; Copyright (C) 1999 Shuhei KOBAYASHI - -;; Author: Shuhei KOBAYASHI -;; Keywords: HMAC, RFC 2104 - -;; This file is part of FLIM (Faithful Library about Internet Message). - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the GNU General Public License as -;; published by the Free Software Foundation; either version 2, or -;; (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program; see the file COPYING. If not, write to -;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -;; Boston, MA 02111-1307, USA. - -;;; Commentary: - -;;; Code: - -(defsubst hmac-hex-to-int (chr) - (cond ((<= ?a chr) (+ (- chr ?a) 10)) - ((<= ?A chr) (+ (- chr ?A) 10)) - ((<= ?0 chr) (- chr ?0)))) - -(defsubst hmac-int-to-hex (num) - (aref "0123456789abcdef" num)) - -(defun hmac-unhex-string (str) - (let* ((len (length str)) - (dst (make-string (/ len 2) 0)) - (idx 0)(pos 0)) - (while (< pos len) - (aset dst idx (logior (lsh (hmac-hex-to-int (aref str pos)) 4) - (hmac-hex-to-int (aref str (1+ pos))))) - (setq idx (1+ idx) - pos (+ 2 pos))) - dst)) - -(defun hmac-hex-string (str) - (let* ((len (length str)) - (dst (make-string (* len 2) 0)) - (idx 0)(pos 0)) - (while (< pos len) - (aset dst idx (hmac-int-to-hex (logand (lsh (aref str pos) -4) 15))) - (setq idx (1+ idx)) - (aset dst idx (hmac-int-to-hex (logand (aref str pos) 15))) - (setq idx (1+ idx) - pos (1+ pos))) - dst)) - -(provide 'hmac-util) - -;;; hmac-util.el ends here.