+2004-01-12 Daiki Ueno <ueno@unixuser.org>
+
+ * sasl.texi: Texinfo markup fixes. From Jesper Harder
+ <harder@ifa.au.dk>.
+
+2004-01-07 Katsumi Yamaoka <yamaoka@jpl.org>
+
+ * sha1-el.el (sha1-string-external): Use with-temp-buffer.
+
+2004-01-07 Katsumi Yamaoka <yamaoka@jpl.org>
+
+ * sha1-el.el (sha1-string-external): Make it can return a string
+ in binary form.
+ (sha1-region-external): Ditto.
+ (sha1-string-internal): Ditto.
+ (sha1-region-internal): Ditto.
+ (sha1-region): Ditto.
+ (sha1-string): Ditto.
+ (sha1): Ditto.
+
+2003-12-16 Simon Josefsson <jas@extundo.com>
+
+ * sha1-el.el (autoload): Don't use ignore-errors.
+ (sha1-use-external): Use condition-case. Suggested by Katsumi
+ Yamaoka <yamaoka@jpl.org>.
+
+2003-12-15 Simon Josefsson <jas@extundo.com>
+
+ * sha1-el.el (autoload): Ignore errors for
+ executable-find. (XEmacs ecrypto does not require sh-script where
+ executable.el is located.)
+ (sha1-use-external): Likewise.
+
+ * sha1-el.el (sha1): Add defgroup.
+ (sha1-maximum-internal-length, sha1-program, sha1-use-external)
+ (sha1-program): Use 'sha1sum' from GNU CoreUtils instead of OpenSSL.
+ (sha1): Autoload.
+
+2001-12-29 ShengHuo ZHU <zsh@cs.rochester.edu>
+
+ * sha1-el.el (sha1-use-external): New variable.
+ (sha1-region): Use it.
+ (sha1-string): Ditto.
+
+2004-01-05 Katsumi Yamaoka <yamaoka@jpl.org>
+
+ * ntlm.el (ntlm-string-as-unibyte): New macro.
+ (ntlm-build-auth-response): Use it.
+
+2004-01-05 Simon Josefsson <jas@extundo.com>
+
+ * ntlm.el: Fix namespace. Change smb-passwd-hash into
+ ntlm-smb-passwd-hash, smb-owf-encrypt into ntlm-smb-owf-encrypt,
+ smb-passwd-hash into ntlm-smb-passwd-hash, smbdes-e-p16 into
+ ntlm-smb-des-e-p16, smbdes-e-p24 into ntlm-smb-des-e-p24, smbhash
+ into ntlm-smb-hash, smb-sp8 into ntlm-smb-sp8, smb-str-to-key into
+ ntlm-smb-str-to-key, smb-dohash into ntlm-smb-dohash, smb-perm1
+ into ntlm-smb-perm1, smb-perm2 into ntlm-smb-perm2, smb-perm3 into
+ ntlm-smb-perm3, smb-perm4 into ntlm-smb-perm4, smb-perm5 into
+ ntlm-smb-perm5, smb-perm6 into ntlm-smb-perm6, smb-sc into
+ ntlm-smb-sc, smb-sbox into ntlm-smb-sbox, string-permute into
+ ntlm-string-permute, string-lshift into ntlm-string-lshift,
+ string-xor into ntlm-string-xor. Suggested by
+ Jesper Harder <harder@myrealbox.com>.
+
+ * ntlm.el: Don't include poem.
+
+ * md4.el (print-int32, print-string-hexa): Remove. Suggested by
+ Jesper Harder <harder@myrealbox.com>.
+
+\f
+2003-12-20 MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
+
+ * FLIM: Version 1.14.6 (Marutamachi) released.
+
2003-12-14 MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
* mime-def.el (mime-header-accept-quoted-encoded-words): Change
;;; md4.el --- MD4 Message Digest Algorithm.
+;; Copyright (C) 2004 Free Software Foundation, Inc.
;; Copyright (C) 2001 Taro Kawagishi
;; Author: Taro Kawagishi <tarok@transpulse.org>
;; Keywords: MD4
;;;
;;; MD4 hash calculation
-(defun print-int32 (int32)
- "print 32 bits integer in 4 bytes string as little endian"
- (let ((h (car int32)) (l (cdr int32)))
- (list (logand l 255) (lsh l -8) (logand h 255) (lsh h -8))))
-
-(defun print-string-hexa (str)
- "print a string in hexadecimal"
- (let (out)
- (mapcar (function (lambda (x) (concat out (format "%x" x)))) str)))
-
(defvar md4-buffer (make-vector 4 '(0 . 0))
"work buffer of four 32-bit integers")
;;; Code:
-(require 'poem)
(require 'md4)
;;;
domain ;bufer field
)))
+(eval-when-compile
+ (defmacro ntlm-string-as-unibyte (string)
+ (if (fboundp 'string-as-unibyte)
+ `(string-as-unibyte ,string)
+ string)))
+
(defun ntlm-build-auth-response (challenge user password-hashes)
"Return the response string to a challenge string CHALLENGE given by
the NTLM based server for the user USER and the password hash list
PASSWORD-HASHES. NTLM uses two hash values which are represented
by PASSWORD-HASHES. PASSWORD-HASHES should be a return value of
- (list (smb-passwd-hash password) (ntlm-md4hash password))"
- (let* ((rchallenge (string-as-unibyte challenge))
+ (list (ntlm-smb-passwd-hash password) (ntlm-md4hash password))"
+ (let* ((rchallenge (ntlm-string-as-unibyte challenge))
;; get fields within challenge struct
;;(ident (substring rchallenge 0 8)) ;ident, 8 bytes
;;(msgType (substring rchallenge 8 12)) ;msgType, 4 bytes
;; generate response data
(setq lmRespData
- (smb-owf-encrypt (car password-hashes) challengeData))
+ (ntlm-smb-owf-encrypt (car password-hashes) challengeData))
(setq ntRespData
- (smb-owf-encrypt (cadr password-hashes) challengeData))
+ (ntlm-smb-owf-encrypt (cadr password-hashes) challengeData))
;; get offsets to fields to pack the response struct in a string
(setq lu (length user))
(defun ntlm-get-password-hashes (password)
"Return a pair of SMB hash and NT MD4 hash of the given password PASSWORD"
- (list (smb-passwd-hash password)
+ (list (ntlm-smb-passwd-hash password)
(ntlm-md4hash password)))
(defun ntlm-ascii2unicode (str len)
j (+ 2 j)))
buf))
-(defun smb-passwd-hash (passwd)
+(defun ntlm-smb-passwd-hash (passwd)
"Return the SMB password hash string of 16 bytes long for the given password
string PASSWD. PASSWD is truncated to 14 bytes if longer."
(let ((len (min (length passwd) 14)))
- (smbdes-e-p16
+ (ntlm-smb-des-e-p16
(concat (substring (upcase passwd) 0 len) ;fill top 14 bytes with passwd
(make-string (- 15 len) 0)))))
-(defun smb-owf-encrypt (passwd c8)
+(defun ntlm-smb-owf-encrypt (passwd c8)
"Return the response string of 24 bytes long for the given password
string PASSWD based on the DES encryption. PASSWD is of at most 14
bytes long and the challenge string C8 of 8 bytes long."
(let ((len (min (length passwd) 16)) p22)
(setq p22 (concat (substring passwd 0 len) ;fill top 16 bytes with passwd
(make-string (- 22 len) 0)))
- (smbdes-e-p24 p22 c8)))
+ (ntlm-smb-des-e-p24 p22 c8)))
-(defun smbdes-e-p24 (p22 c8)
+(defun ntlm-smb-des-e-p24 (p22 c8)
"Return a 24 bytes hashed string for a 21 bytes string P22 and a 8 bytes
string C8."
- (concat (smbhash c8 p22 t) ;hash first 8 bytes of p22
- (smbhash c8 (substring p22 7) t)
- (smbhash c8 (substring p22 14) t)))
+ (concat (ntlm-smb-hash c8 p22 t) ;hash first 8 bytes of p22
+ (ntlm-smb-hash c8 (substring p22 7) t)
+ (ntlm-smb-hash c8 (substring p22 14) t)))
-(defconst smb-sp8 [75 71 83 33 64 35 36 37])
+(defconst ntlm-smb-sp8 [75 71 83 33 64 35 36 37])
-(defun smbdes-e-p16 (p15)
+(defun ntlm-smb-des-e-p16 (p15)
"Return a 16 bytes hashed string for a 15 bytes string P15."
- (concat (smbhash smb-sp8 p15 t) ;hash of first 8 bytes of p15
- (smbhash smb-sp8 (substring p15 7) t) ;hash of last 8 bytes of p15
- ))
+ (concat (ntlm-smb-hash ntlm-smb-sp8 p15 t) ;hash of first 8 bytes of p15
+ (ntlm-smb-hash ntlm-smb-sp8 ;hash of last 8 bytes of p15
+ (substring p15 7) t)))
-(defun smbhash (in key forw)
+(defun ntlm-smb-hash (in key forw)
"Return the hash string of length 8 for a string IN of length 8 and
a string KEY of length 8. FORW is t or nil."
(let ((out (make-string 8 0))
outb ;string of length 64
(inb (make-string 64 0))
(keyb (make-string 64 0))
- (key2 (smb-str-to-key key))
+ (key2 (ntlm-smb-str-to-key key))
(i 0) aa)
(while (< i 64)
(unless (zerop (logand (aref in (/ i 8)) (lsh 1 (- 7 (% i 8)))))
(unless (zerop (logand (aref key2 (/ i 8)) (lsh 1 (- 7 (% i 8)))))
(aset keyb i 1))
(setq i (1+ i)))
- (setq outb (smb-dohash inb keyb forw))
+ (setq outb (ntlm-smb-dohash inb keyb forw))
(setq i 0)
(while (< i 64)
(unless (zerop (aref outb i))
(setq i (1+ i)))
out))
-(defun smb-str-to-key (str)
+(defun ntlm-smb-str-to-key (str)
"Return a string of length 8 for the given string STR of length 7."
(let ((key (make-string 8 0))
(i 7))
(setq i (1- i)))
key))
-(defconst smb-perm1 [57 49 41 33 25 17 9
+(defconst ntlm-smb-perm1 [57 49 41 33 25 17 9
1 58 50 42 34 26 18
10 2 59 51 43 35 27
19 11 3 60 52 44 36
14 6 61 53 45 37 29
21 13 5 28 20 12 4])
-(defconst smb-perm2 [14 17 11 24 1 5
+(defconst ntlm-smb-perm2 [14 17 11 24 1 5
3 28 15 6 21 10
23 19 12 4 26 8
16 7 27 20 13 2
44 49 39 56 34 53
46 42 50 36 29 32])
-(defconst smb-perm3 [58 50 42 34 26 18 10 2
+(defconst ntlm-smb-perm3 [58 50 42 34 26 18 10 2
60 52 44 36 28 20 12 4
62 54 46 38 30 22 14 6
64 56 48 40 32 24 16 8
61 53 45 37 29 21 13 5
63 55 47 39 31 23 15 7])
-(defconst smb-perm4 [32 1 2 3 4 5
+(defconst ntlm-smb-perm4 [32 1 2 3 4 5
4 5 6 7 8 9
8 9 10 11 12 13
12 13 14 15 16 17
24 25 26 27 28 29
28 29 30 31 32 1])
-(defconst smb-perm5 [16 7 20 21
+(defconst ntlm-smb-perm5 [16 7 20 21
29 12 28 17
1 15 23 26
5 18 31 10
19 13 30 6
22 11 4 25])
-(defconst smb-perm6 [40 8 48 16 56 24 64 32
+(defconst ntlm-smb-perm6 [40 8 48 16 56 24 64 32
39 7 47 15 55 23 63 31
38 6 46 14 54 22 62 30
37 5 45 13 53 21 61 29
34 2 42 10 50 18 58 26
33 1 41 9 49 17 57 25])
-(defconst smb-sc [1 1 2 2 2 2 2 2 1 2 2 2 2 2 2 1])
+(defconst ntlm-smb-sc [1 1 2 2 2 2 2 2 1 2 2 2 2 2 2 1])
-(defconst smb-sbox [[[14 4 13 1 2 15 11 8 3 10 6 12 5 9 0 7]
+(defconst ntlm-smb-sbox [[[14 4 13 1 2 15 11 8 3 10 6 12 5 9 0 7]
[ 0 15 7 4 14 2 13 1 10 6 12 11 9 5 3 8]
[ 4 1 14 8 13 6 2 11 15 12 9 7 3 10 5 0]
[15 12 8 2 4 9 1 7 5 11 3 14 10 0 6 13]]
[ 7 11 4 1 9 12 14 2 0 6 10 13 15 3 5 8]
[ 2 1 14 7 4 10 8 13 15 12 9 0 3 5 6 11]]])
-(defsubst string-permute (in perm n)
+(defsubst ntlm-string-permute (in perm n)
"Return a string of length N for a string IN and a permutation vector
PERM of size N. The length of IN should be height of PERM."
(let ((i 0) (out (make-string n 0)))
(setq i (1+ i)))
out))
-(defsubst string-lshift (str count len)
+(defsubst ntlm-string-lshift (str count len)
"Return a string by circularly shifting a string STR by COUNT to the left.
length of STR is LEN."
(let ((c (% count len)))
(concat (substring str c len) (substring str 0 c))))
-(defsubst string-xor (in1 in2 n)
+(defsubst ntlm-string-xor (in1 in2 n)
"Return exclusive-or of sequences in1 and in2"
(let ((w (make-string n 0)) (i 0))
(while (< i n)
(setq i (1+ i)))
w))
-(defun smb-dohash (in key forw)
+(defun ntlm-smb-dohash (in key forw)
"Return the hash value for a string IN and a string KEY.
Length of IN and KEY are 64. FORW non nill means forward, nil means
backward."
r ;string of length 32
rl ;string of length 64
(i 0) (j 0) (k 0))
- (setq pk1 (string-permute key smb-perm1 56))
+ (setq pk1 (ntlm-string-permute key ntlm-smb-perm1 56))
(setq c (substring pk1 0 28))
(setq d (substring pk1 28 56))
(setq i 0)
(while (< i 16)
- (setq c (string-lshift c (aref smb-sc i) 28))
- (setq d (string-lshift d (aref smb-sc i) 28))
+ (setq c (ntlm-string-lshift c (aref ntlm-smb-sc i) 28))
+ (setq d (ntlm-string-lshift d (aref ntlm-smb-sc i) 28))
(setq cd (concat (substring c 0 28) (substring d 0 28)))
- (aset ki i (string-permute cd smb-perm2 48))
+ (aset ki i (ntlm-string-permute cd ntlm-smb-perm2 48))
(setq i (1+ i)))
- (setq pd1 (string-permute in smb-perm3 64))
+ (setq pd1 (ntlm-string-permute in ntlm-smb-perm3 64))
(setq l (substring pd1 0 32))
(setq r (substring pd1 32 64))
r2 ;string of length 32
jj m n bj sbox-jmn)
(while (< i 16)
- (setq er (string-permute r smb-perm4 48))
- (setq erk (string-xor er
+ (setq er (ntlm-string-permute r ntlm-smb-perm4 48))
+ (setq erk (ntlm-string-xor er
(aref ki (if forw i (- 15 i)))
48))
(setq j 0)
(lsh (aref bj 3) 1)
(aref bj 4)))
(setq k 0)
- (setq sbox-jmn (aref (aref (aref smb-sbox j) m) n))
+ (setq sbox-jmn (aref (aref (aref ntlm-smb-sbox j) m) n))
(while (< k 4)
(aset bj k
(if (zerop (logand sbox-jmn (lsh 1 (- 3 k))))
(setq cb (concat cb (substring (aref b j) 0 4)))
(setq j (1+ j)))
- (setq pcb (string-permute cb smb-perm5 32))
- (setq r2 (string-xor l pcb 32))
+ (setq pcb (ntlm-string-permute cb ntlm-smb-perm5 32))
+ (setq r2 (ntlm-string-xor l pcb 32))
(setq l r)
(setq r r2)
(setq i (1+ i))))
(setq rl (concat r l))
- (string-permute rl smb-perm6 64)))
+ (ntlm-string-permute rl ntlm-smb-perm6 64)))
(defun ntlm-md4hash (passwd)
"Return the 16 bytes MD4 hash of a string PASSWD after converting it
@set VERSION 0.2
+@dircategory Emacs
@direntry
* SASL: (sasl). The Emacs SASL library.
@end direntry
@defun sasl-find-mechanism mechanisms
Retrieve an apropriate mechanism.
-This function compares MECHANISMS and @code{sasl-mechanisms} then
+This function compares @var{mechanisms} and @code{sasl-mechanisms} then
returns apropriate @code{sasl-mechanism} object.
@example
@section Steps
A step (@code{sasl-step} object) is an abstraction of authentication
-"step" which holds the response value and the next entry point for the
+``step'' which holds the response value and the next entry point for the
authentication process (the latter is not accessible).
@defun sasl-step-data step
-Return the data which STEP holds, a string.
+Return the data which @var{step} holds, a string.
@end defun
@defun sasl-step-set-data step data
-Store DATA string to STEP.
+Store @var{data} string to @var{step}.
@end defun
To get the initial response, you should call the function
-@code{sasl-next-step} with the second argument nil.
+@code{sasl-next-step} with the second argument @code{nil}.
@example
(setq name (sasl-mechanism-name mechanism))
@defun sasl-next-step client step
Perform the authentication step.
-At the first time STEP should be set to nil.
+At the first time @var{step} should be set to @code{nil}.
@end defun
@node Backend drivers
-;;; sha1-el.el --- SHA1 Secure Hash Algorithm in Emacs-Lisp.
+;;; sha1-el.el --- SHA1 Secure Hash Algorithm in Emacs-Lisp
-;; Copyright (C) 1999, 2001 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2001, 2003, 2004 Free Software Foundation, Inc.
;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
;; Keywords: SHA1, FIPS 180-1
(require 'hex-util)
+(autoload 'executable-find "executable")
+
;;;
;;; external SHA1 function.
;;;
-(defvar sha1-maximum-internal-length 500
+(defgroup sha1 nil
+ "Elisp interface for SHA1 hash computation."
+ :group 'extensions)
+
+(defcustom sha1-maximum-internal-length 500
"*Maximum length of message to use lisp version of SHA1 function.
If message is longer than this, `sha1-program' is used instead.
If this variable is set to 0, use extarnal program only.
-If this variable is set to nil, use internal function only.")
+If this variable is set to nil, use internal function only."
+ :type 'integer
+ :group 'sha1)
-(defvar sha1-program '("openssl" "sha1")
+(defcustom sha1-program '("sha1sum")
"*Name of program to compute SHA1.
-It must be a string \(program name\) or list of strings \(name and its args\).")
-
-(defun sha1-string-external (string)
- ;; `with-temp-buffer' is new in v20, so we do not use it.
- (save-excursion
- (let (buffer)
- (unwind-protect
- (let (prog args)
- (if (consp sha1-program)
- (setq prog (car sha1-program)
- args (cdr sha1-program))
- (setq prog sha1-program
- args nil))
- (setq buffer (set-buffer
- (generate-new-buffer " *sha1 external*")))
- (insert string)
- (apply (function call-process-region)
- (point-min)(point-max)
- prog t t nil args)
- ;; SHA1 is 40 bytes long in hexadecimal form.
- (buffer-substring (point-min)(+ (point-min) 40)))
- (and buffer
- (buffer-name buffer)
- (kill-buffer buffer))))))
-
-(defun sha1-region-external (beg end)
- (sha1-string-external (buffer-substring-no-properties beg end)))
+It must be a string \(program name\) or list of strings \(name and its args\)."
+ :type '(repeat string)
+ :group 'sha1)
+
+(defcustom sha1-use-external (condition-case ()
+ (executable-find (car sha1-program))
+ (error))
+ "*Use external SHA1 program.
+If this variable is set to nil, use internal function only."
+ :type 'boolean
+ :group 'sha1)
+
+(defun sha1-string-external (string &optional binary)
+ (let (prog args digest default-enable-multibyte-characters)
+ (if (consp sha1-program)
+ (setq prog (car sha1-program)
+ args (cdr sha1-program))
+ (setq prog sha1-program
+ args nil))
+ (with-temp-buffer
+ (insert string)
+ (apply (function call-process-region)
+ (point-min)(point-max)
+ prog t t nil args)
+ ;; SHA1 is 40 bytes long in hexadecimal form.
+ (setq digest (buffer-substring (point-min)(+ (point-min) 40))))
+ (if binary
+ (decode-hex-string digest)
+ digest)))
+
+(defun sha1-region-external (beg end &optional binary)
+ (sha1-string-external (buffer-substring-no-properties beg end) binary))
;;;
;;; internal SHA1 function.
(fillarray block-high nil)
(fillarray block-low nil))))
-(defun sha1-string-internal (string)
- (encode-hex-string (sha1-binary string)))
+(defun sha1-string-internal (string &optional binary)
+ (if binary
+ (sha1-binary string)
+ (encode-hex-string (sha1-binary string))))
-(defun sha1-region-internal (beg end)
- (sha1-string-internal (buffer-substring-no-properties beg end)))
+(defun sha1-region-internal (beg end &optional binary)
+ (sha1-string-internal (buffer-substring-no-properties beg end) binary))
;;;
;;; application interface.
;;;
-(defun sha1-region (beg end)
- (if (and sha1-maximum-internal-length
+(defun sha1-region (beg end &optional binary)
+ (if (and sha1-use-external
+ sha1-maximum-internal-length
(> (abs (- end beg)) sha1-maximum-internal-length))
- (sha1-region-external beg end)
- (sha1-region-internal beg end)))
+ (sha1-region-external beg end binary)
+ (sha1-region-internal beg end binary)))
-(defun sha1-string (string)
- (if (and sha1-maximum-internal-length
+(defun sha1-string (string &optional binary)
+ (if (and sha1-use-external
+ sha1-maximum-internal-length
(> (length string) sha1-maximum-internal-length))
- (sha1-string-external string)
- (sha1-string-internal string)))
+ (sha1-string-external string binary)
+ (sha1-string-internal string binary)))
-(defun sha1 (object &optional beg end)
+;;;###autoload
+(defun sha1 (object &optional beg end binary)
"Return the SHA1 (Secure Hash Algorithm) of an object.
OBJECT is either a string or a buffer.
Optional arguments BEG and END denote buffer positions for computing the
-hash of a portion of OBJECT."
+hash of a portion of OBJECT.
+If BINARY is non-nil, return a string in binary form."
(if (stringp object)
- (sha1-string object)
+ (sha1-string object binary)
(save-excursion
(set-buffer object)
- (sha1-region (or beg (point-min)) (or end (point-max))))))
+ (sha1-region (or beg (point-min)) (or end (point-max)) binary))))
(provide 'sha1-el)