aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/net/ntlm.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/net/ntlm.el')
-rw-r--r--lisp/net/ntlm.el44
1 files changed, 19 insertions, 25 deletions
diff --git a/lisp/net/ntlm.el b/lisp/net/ntlm.el
index ebcd21948bf..9401430799c 100644
--- a/lisp/net/ntlm.el
+++ b/lisp/net/ntlm.el
@@ -69,7 +69,6 @@
69 69
70(require 'md4) 70(require 'md4)
71(require 'hmac-md5) 71(require 'hmac-md5)
72(require 'calc)
73 72
74(defgroup ntlm nil 73(defgroup ntlm nil
75 "NTLM (NT LanManager) authentication." 74 "NTLM (NT LanManager) authentication."
@@ -133,32 +132,27 @@ is not given."
133 domain ;buffer field 132 domain ;buffer field
134 )))) 133 ))))
135 134
136(defun ntlm-compute-timestamp () 135(defun ntlm--time-to-timestamp (time)
137 "Compute an NTLMv2 timestamp. 136 "Convert TIME to an NTLMv2 timestamp.
138Return a unibyte string representing the number of tenths of a 137Return a unibyte string representing the number of tenths of a
139microsecond since January 1, 1601 as a 64-bit little-endian 138microsecond since January 1, 1601 as a 64-bit little-endian
140signed integer." 139signed integer. TIME must be on the form (HIGH LOW USEC PSEC)."
141 ;; FIXME: This can likely be significantly simplified using the new 140 (let* ((s (+ (ash (nth 0 time) 16) (nth 1 time)))
142 ;; bignums support! 141 (us (nth 2 time))
143 (let* ((s-to-tenths-of-us "mul(add(lsh($1,16),$2),10000000)") 142 (ps (nth 3 time))
144 (us-to-tenths-of-us "mul($3,10)") 143 (tenths-of-us-since-jan-1-1601
145 (ps-to-tenths-of-us "idiv($4,100000)") 144 (+ (* s 10000000) (* us 10) (/ ps 100000)
146 (tenths-of-us-since-jan-1-1601 145 ;; tenths of microseconds between 1601-01-01 and 1970-01-01
147 (apply #'calc-eval (concat "add(add(add(" 146 116444736000000000)))
148 s-to-tenths-of-us "," 147 (apply #'unibyte-string
149 us-to-tenths-of-us ")," 148 (mapcar (lambda (i)
150 ps-to-tenths-of-us ")," 149 (logand (ash tenths-of-us-since-jan-1-1601 (* i -8))
151 ;; tenths of microseconds between 150 #xff))
152 ;; 1601-01-01 and 1970-01-01 151 (number-sequence 0 7)))))
153 "116444736000000000)") 152
154 'rawnum (time-convert nil 'list))) 153(defun ntlm-compute-timestamp ()
155 result-bytes) 154 "Current time as an NTLMv2 timestamp, as a unibyte string."
156 (dotimes (_byte 8) 155 (ntlm--time-to-timestamp (time-convert nil 'list)))
157 (push (calc-eval "and($1,16#FF)" 'rawnum tenths-of-us-since-jan-1-1601)
158 result-bytes)
159 (setq tenths-of-us-since-jan-1-1601
160 (calc-eval "rsh($1,8,64)" 'rawnum tenths-of-us-since-jan-1-1601)))
161 (apply #'unibyte-string (nreverse result-bytes))))
162 156
163(defun ntlm-generate-nonce () 157(defun ntlm-generate-nonce ()
164 "Generate a random nonce, not to be used more than once. 158 "Generate a random nonce, not to be used more than once.