From 4054fe97e489a28daf21cb0b283520d7df2114b7 Mon Sep 17 00:00:00 2001 From: okada Date: Fri, 16 Feb 2001 11:59:15 +0000 Subject: [PATCH] rename md4-pack-int16, md4-pack-int32, md4-unpack-int16, md4-unpack-int32 --- ChangeLog | 12 +++++++++ md4.el | 44 ++++++++++++++++++++++++++----- ntlm.el | 86 +++++++++++++++++++------------------------------------------ 3 files changed, 77 insertions(+), 65 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8a4d07b..0891f47 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,18 @@ 2001-02-16 Kenichi OKADA * SLIM-TIPS: Fix. + * md4.el(md4-pack-int16): Taken form ntlm.el + (md4-pack-int32): Ditto. + (md4-unpack-int16): Ditto. + (md4-unpack-int32): Ditto. + * ntlm.el (pack-int16): Delete. + (pack-int32): Delete. + (unpack-int16): Delete. + (unpack-int32): Delete. + +2001-02-16 Kenichi OKADA + + * SLIM-TIPS: Fix. * sasl.el(sasl-mechanisms): Add NTLM. (sasl-mechanism-alist): Add NTLM. diff --git a/md4.el b/md4.el index 7b05f26..42cc7ab 100644 --- a/md4.el +++ b/md4.el @@ -69,7 +69,7 @@ bytes long. N is required to handle strings containing character 0." (aset buf n 128) ;0x80 (if (<= n 55) (progn - (setq c4 (pack-int32 b)) + (setq c4 (md4-pack-int32 b)) (aset buf 56 (aref c4 0)) (aset buf 57 (aref c4 1)) (aset buf 58 (aref c4 2)) @@ -77,7 +77,7 @@ bytes long. N is required to handle strings containing character 0." (setq m (md4-copy64 buf)) (md4-64 m)) ;; else - (setq c4 (pack-int32 b)) + (setq c4 (md4-pack-int32 b)) (aset buf 120 (aref c4 0)) (aset buf 121 (aref c4 1)) (aset buf 122 (aref c4 2)) @@ -87,10 +87,10 @@ bytes long. N is required to handle strings containing character 0." (setq m (md4-copy64 (substring buf 64))) (md4-64 m))) - (concat (pack-int32 (aref md4-buffer 0)) - (pack-int32 (aref md4-buffer 1)) - (pack-int32 (aref md4-buffer 2)) - (pack-int32 (aref md4-buffer 3)))) + (concat (md4-pack-int32 (aref md4-buffer 0)) + (md4-pack-int32 (aref md4-buffer 1)) + (md4-pack-int32 (aref md4-buffer 2)) + (md4-pack-int32 (aref md4-buffer 3)))) (defsubst md4-F (x y z) (logior (logand x y) (logand (lognot x) z))) (defsubst md4-G (x y z) (logior (logand x y) (logand x z) (logand y z))) @@ -200,6 +200,38 @@ bytes long. N is required to handle strings containing character 0." (setq i (1+ i))) int32s)) +;;; +;;; sub functions + +(defun md4-pack-int16 (int16) + "Pack 16 bits integer in 2 bytes string as little endian." + (let ((str (make-string 2 0))) + (aset str 0 (logand int16 255)) + (aset str 1 (lsh int16 -8)) + str)) + +(defun md4-pack-int32 (int32) + "Pack 32 bits integer in a 4 bytes string as little endian. A 32 bits +integer is represented as a pair of two 16 bits integers (cons high low)." + (let ((str (make-string 4 0)) + (h (car int32)) (l (cdr int32))) + (aset str 0 (logand l 255)) + (aset str 1 (lsh l -8)) + (aset str 2 (logand h 255)) + (aset str 3 (lsh h -8)) + str)) + +(defun md4-unpack-int16 (str) + (if (eq 2 (length str)) + (+ (lsh (aref str 1) 8) (aref str 0)) + (error "%s is not 2 bytes long" str))) + +(defun md4-unpack-int32 (str) + (if (eq 4 (length str)) + (cons (+ (lsh (aref str 3) 8) (aref str 2)) + (+ (lsh (aref str 1) 8) (aref str 0))) + (error "%s is not 4 bytes long" str))) + (provide 'md4) ;;; md4.el ends here diff --git a/ntlm.el b/ntlm.el index f8b178b..399cb1a 100644 --- a/ntlm.el +++ b/ntlm.el @@ -96,12 +96,12 @@ is not given." (concat request-ident ;8 bytes request-msgType ;4 bytes request-flags ;4 bytes - (pack-int16 lu) ;user field, count field - (pack-int16 lu) ;user field, max count field - (pack-int32 (cons 0 off-u)) ;user field, offset field - (pack-int16 ld) ;domain field, count field - (pack-int16 ld) ;domain field, max count field - (pack-int32 (cons 0 off-d)) ;domain field, offset field + (md4-pack-int16 lu) ;user field, count field + (md4-pack-int16 lu) ;user field, max count field + (md4-pack-int32 (cons 0 off-u)) ;user field, offset field + (md4-pack-int16 ld) ;domain field, count field + (md4-pack-int16 ld) ;domain field, max count field + (md4-pack-int32 (cons 0 off-d)) ;domain field, offset field user ;bufer field domain ;bufer field ))) @@ -129,8 +129,8 @@ by PASSWORD-HASHES. PASSWORD-HASHES should be a return value of domain ;ascii domain string lu ld off-lm off-nt off-d off-u off-w off-s) ;; extract domain string from challenge string - (setq uDomain-len (unpack-int16 (substring uDomain 0 2))) - (setq uDomain-offs (unpack-int32 (substring uDomain 4 8))) + (setq uDomain-len (md4-unpack-int16 (substring uDomain 0 2))) + (setq uDomain-offs (md4-unpack-int32 (substring uDomain 4 8))) (setq domain (ntlm-unicode2ascii (substring challenge (cdr uDomain-offs) @@ -158,45 +158,45 @@ by PASSWORD-HASHES. PASSWORD-HASHES should be a return value of (setq off-s (+ 64 48 (* 2 (+ ld lu lu)))) ;offset to string 'sessionKey ;; pack the response struct in a string (concat "NTLMSSP\0" ;response ident field, 8 bytes - (pack-int32 '(0 . 3)) ;response msgType field, 4 bytes + (md4-pack-int32 '(0 . 3)) ;response msgType field, 4 bytes ;; lmResponse field, 8 bytes ;;AddBytes(response,lmResponse,lmRespData,24); - (pack-int16 24) ;len field - (pack-int16 24) ;maxlen field - (pack-int32 (cons 0 off-lm)) ;field offset + (md4-pack-int16 24) ;len field + (md4-pack-int16 24) ;maxlen field + (md4-pack-int32 (cons 0 off-lm)) ;field offset ;; ntResponse field, 8 bytes ;;AddBytes(response,ntResponse,ntRespData,24); - (pack-int16 24) ;len field - (pack-int16 24) ;maxlen field - (pack-int32 (cons 0 off-nt)) ;field offset + (md4-pack-int16 24) ;len field + (md4-pack-int16 24) ;maxlen field + (md4-pack-int32 (cons 0 off-nt)) ;field offset ;; uDomain field, 8 bytes ;;AddUnicodeString(response,uDomain,domain); ;;AddBytes(response, uDomain, udomain, 2*ld); - (pack-int16 (* 2 ld)) ;len field - (pack-int16 (* 2 ld)) ;maxlen field - (pack-int32 (cons 0 off-d)) ;field offset + (md4-pack-int16 (* 2 ld)) ;len field + (md4-pack-int16 (* 2 ld)) ;maxlen field + (md4-pack-int32 (cons 0 off-d)) ;field offset ;; uUser field, 8 bytes ;;AddUnicodeString(response,uUser,u); ;;AddBytes(response, uUser, uuser, 2*lu); - (pack-int16 (* 2 lu)) ;len field - (pack-int16 (* 2 lu)) ;maxlen field - (pack-int32 (cons 0 off-u)) ;field offset + (md4-pack-int16 (* 2 lu)) ;len field + (md4-pack-int16 (* 2 lu)) ;maxlen field + (md4-pack-int32 (cons 0 off-u)) ;field offset ;; uWks field, 8 bytes ;;AddUnicodeString(response,uWks,u); - (pack-int16 (* 2 lu)) ;len field - (pack-int16 (* 2 lu)) ;maxlen field - (pack-int32 (cons 0 off-w)) ;field offset + (md4-pack-int16 (* 2 lu)) ;len field + (md4-pack-int16 (* 2 lu)) ;maxlen field + (md4-pack-int32 (cons 0 off-w)) ;field offset ;; sessionKey field, 8 bytes ;;AddString(response,sessionKey,NULL); - (pack-int16 0) ;len field - (pack-int16 0) ;maxlen field - (pack-int32 (cons 0 (- off-s off-lm))) ;field offset + (md4-pack-int16 0) ;len field + (md4-pack-int16 0) ;maxlen field + (md4-pack-int32 (cons 0 (- off-s off-lm))) ;field offset ;; flags field, 4 bytes flags ; @@ -217,38 +217,6 @@ by PASSWORD-HASHES. PASSWORD-HASHES should be a return value of (list (smb-passwd-hash password) (ntlm-md4hash password))) -;;; -;;; sub functions - -(defun pack-int16 (int16) - "Pack 16 bits integer in 2 bytes string as little endian." - (let ((str (make-string 2 0))) - (aset str 0 (logand int16 255)) - (aset str 1 (lsh int16 -8)) - str)) - -(defun pack-int32 (int32) - "Pack 32 bits integer in a 4 bytes string as little endian. A 32 bits -integer is represented as a pair of two 16 bits integers (cons high low)." - (let ((str (make-string 4 0)) - (h (car int32)) (l (cdr int32))) - (aset str 0 (logand l 255)) - (aset str 1 (lsh l -8)) - (aset str 2 (logand h 255)) - (aset str 3 (lsh h -8)) - str)) - -(defun unpack-int16 (str) - (if (eq 2 (length str)) - (+ (lsh (aref str 1) 8) (aref str 0)) - (error "%s is not 2 bytes long" str))) - -(defun unpack-int32 (str) - (if (eq 4 (length str)) - (cons (+ (lsh (aref str 3) 8) (aref str 2)) - (+ (lsh (aref str 1) 8) (aref str 0))) - (error "%s is not 4 bytes long" str))) - (defun ntlm-ascii2unicode (str len) "Convert an ASCII string into a NT Unicode string, which is little-endian utf16." -- 1.7.10.4