;ELC   
;;; compiled by yoav@mit.edu on Fri Feb 13 02:47:56 1998
;;; from file /mit/yoav/work/lcs/src/MAC.el
;;; emacs version 19.34.1.
;;; bytecomp version FSF 2.10
;;; optimization is on.
;;; this file uses opcodes which do not exist in Emacs 18.

(if (and (boundp 'emacs-version)
	 (or (and (boundp 'epoch::version) epoch::version)
	     (string-lessp emacs-version "19.29")))
    (error "`MAC.el' was compiled for Emacs 19.29 or later"))


(require (quote timer))
#@58 number of bytes in a block, not including random padding
(defconst MAC-blocksize 56 (#$ . 474))
#@83 number of bytes in the security
padding appended to a block -- security parameter
(defconst MAC-security-padding 8 (#$ . 576))
#@78 number of seconds to let the machine be
idle before trying to process blocks
(defconst MAC-idle-wait 0.5 (#$ . 709))
#@53 number of seconds between iterative calls when idle
(defconst MAC-idle-repeat 0.29999999999999999 (#$ . 832))
#@47 the process to run to compute the f1 function
(defconst MAC-F1-proc "/mit/yoav/work/lcs/bin/MAC-f1" (#$ . 948))
#@47 the process to run to compute the f2 function
(defconst MAC-F2-proc "/mit/yoav/work/lcs/bin/MAC-f2" (#$ . 1066))
(random t)
#@40 a variable to hold the last idle-timer
(defvar MAC-last-idle-timer nil (#$ . 1196))
#@66 first block in any MAC-list, sum changes and so block may change
(defvar MAC-start-block (vector "start" "startpad" nil) (#$ . 1286))
#@46 default value of first block in any MAC-list
(defconst MAC-default-start-block (vector "start" "startpad" nil) (#$ . 1426))
#@28 last block in any MAC-list
(defconst MAC-end-block (vector "end" "endpad" nil) (#$ . 1556))
(byte-code "! B! B!! B!. B" [boundp start-time nil current-load-list modify-start-time t time total-time] 2)
#@48 A list of all buffers currently using MAC-mode
(defvar MAC-buffers nil (#$ . 1801))
#@42 The variable used to hold the key for f1
(defvar MAC-f1-key nil (#$ . 1891))
#@42 The variable used to hold the key for f2
(defvar MAC-f2-key nil (#$ . 1974))
#@44 The process that is used to compute MAC-f1
(defvar MAC-f1-proc nil (#$ . 2057))
#@44 The process that is used to compute MAC-f2
(defvar MAC-f2-proc nil (#$ . 2143))
#@47 The queue being used for encryption of blocks
(defvar MAC-f1-queue nil (#$ . 2229))
#@54 The queue being used for calculating final checksums
(defvar MAC-f2-queue nil (#$ . 2319))
#@157 *Non-nil enables message authentication computations on buffer.
The default value is nil. To change the default, do this:
        (set-default 'MAC-mode t)
(defvar MAC-mode nil (#$ . -2417))
#@104 The secret key associated with the person doing the edits. 
   hopefully the same throough all buffers
(defvar MAC-mode-key nil (#$ . 2615))
#@64 The variable that holds the current XOR of all block checksums
(defvar MAC-local-h nil (#$ . 2762))
#@54 The variable that holds the final encrypted checksum
(defvar MAC-final-sum nil (#$ . 2868))
#@51 The list structure representing the entire buffer
(defvar MAC-list nil (#$ . 2966))
#@132 This variable, when set to 't, implies the MAC-list datastructure
   may have shorter or longer strings than MAC-blocksize in them
(defvar MAC-list-modified t (#$ . 3057))
#@115 This variable, when set to 'nil, implies that if MAC-list-modified
   is 'nil, the sums are still not all correct
(defvar MAC-list-sums-complete nil (#$ . 3236))
#@153 This variable, when set to 't, along with MAC-list-modified and
   MAC-list-sums-complete, decide whether the final checksum for the
   buffer is valid
(defvar MAC-list-final-sum-good nil (#$ . 3405))
#@65 This variable holds the original value of require-final-newline
(defvar MAC-orig-require-final-newline nil (#$ . 3612))
(byte-code "!!!!!!!!!!!!!!!" [make-variable-buffer-local MAC-f1-key MAC-f2-key MAC-f1-proc MAC-f2-proc MAC-f1-queue MAC-f2-queue MAC-local-h MAC-final-sum MAC-start-block MAC-mode MAC-list MAC-list-modified MAC-list-sums-complete MAC-list-final-sum-good after-change-functions] 2)
#@64 return the string associated with the MAC-list structure block
(defalias 'MAC-string #[(block) "H" [block 0] 2 (#$ . 4064)])
(put (quote MAC-string) (quote byte-optimizer) (quote byte-compile-inline-expand))
#@73 return the security pad associated with the MAC-list structure
   block
(defalias 'MAC-pad #[(block) "H" [block 1] 2 (#$ . 4281)])
(put (quote MAC-pad) (quote byte-optimizer) (quote byte-compile-inline-expand))
#@61 return the sum associated with the MAC-list structure block
(defalias 'MAC-sum #[(block) "H" [block 2] 2 (#$ . 4501)])
(put (quote MAC-sum) (quote byte-optimizer) (quote byte-compile-inline-expand))
#@41 set the value of string in block to val
(defalias 'MAC-set-string #[(block val) "\nI" [block 0 val] 3 (#$ . 4709)])
(put (quote MAC-set-string) (quote byte-optimizer) (quote byte-compile-inline-expand))
#@38 set the value of pad in block to val
(defalias 'MAC-set-pad #[(block val) "\nI" [block 1 val] 3 (#$ . 4921)])
(put (quote MAC-set-pad) (quote byte-optimizer) (quote byte-compile-inline-expand))
#@38 set the value of sum in block to val
(defalias 'MAC-set-sum #[(block val) "\nI" [block 2 val] 3 (#$ . 5124)])
(byte-code "# B#" [put MAC-set-sum byte-optimizer byte-compile-inline-expand MAC-mode minor-mode-alist (MAC-mode " MAC") run-with-idle-timer MAC-idle-wait MAC-idle-repeat MAC-mode-idle] 4)
#@85 hook to call after a file is loaded to
    see whether it has been saved with a MAC
(defalias 'MAC-find-file-hook #[nil "P!  *" [buffer-file-truename name ".sum" sumname file-readable-p MAC-mode] 3 (#$ . 5451)])
#@38 hook to call when a buffer is killed
(defalias 'MAC-kill-buffer-hook #[nil " !\n?? \n!" [MAC-f1-proc delete-process MAC-f2-proc] 2 (#$ . 5680)])
(byte-code "\"\"" [add-hook find-file-hooks MAC-find-file-hook kill-buffer-hooks MAC-kill-buffer-hook] 3)
#@64 Minor mode for editing files with automatic MAC
   computation
(defalias 'MAC-mode #[(&optional arg) "	 	? !V \f pC\" \fpCT  !#@ \"!)P\"!  !#t \"!)P\"!! !\"$B$& (&p\f\"($\"\"" [arg MAC-mode prefix-numeric-value 0 MAC-buffers MAC-f1-key MAC-get-f1-key nil process-connection-type start-process "F1" generate-new-buffer-name " F1" MAC-F1-proc MAC-f1-proc error "Couldn't start up " process-kill-without-query process-send-string "\n" tq-create MAC-f1-queue MAC-f2-key MAC-get-f2-key "F2" " F2" MAC-F2-proc MAC-f2-proc MAC-f2-queue timerp MAC-last-idle-timer cancel-timer add-hook after-save-hook MAC-save-checksum MAC-mode-buffer-change-hook after-change-functions 3000000 gc-cons-threshold MAC-prepare-checksum MAC-list 1000000 delete remove-hook] 5 (#$ . 5955) "P"])
#@22 Keymap for MAC-mode.
(defvar MAC-mode-map nil (#$ . 6859))
(byte-code "  !M\f B\fB" [MAC-mode-map copy-keymap current-global-map MAC-mode minor-mode-map-alist] 3)
#@198 This function is supposed to be called every time the buffer
   changes, and will contain information as to exactly HOW the
   buffer changed. This is then used to update the MAC-list
   structure
(defalias 'MAC-mode-buffer-change-hook #[(beg end old-len) "	!\n 	!Ɖ	\n\fA@\fH)GZVX A@=X AA@\fH)GZ0 A@\f= !ABA@\f\fH)G\\@\fI*\f\fI*\f\fH)G\\S\f\fH)OVmU AA@\f\fI*\f\fH)GY\f\fH)GZAAA@\f \f\fH)GZZXO\f\fH)\f\fH)GZ\\\\O\n]\f\fH)O\n{\nPP	{\f\fH)OPP		GW	GUAA\f	\fI*\f	!\fI*	GU\f	\fI*\f	!\fI*@\f\"\f	O\fI*\f\f\fH)!\fI*	O	A	GYc	O!AB@\fI*A	O	,	GU?	!AB@\fI*." [timerp MAC-last-idle-timer cancel-timer t MAC-list-modified MAC-list nil beg pos new-string new-string-end new-string-start block prev 0 1 MAC-end-block MAC-make-list-block "" val 2 old-len MAC-blocksize end MAC-randomizer MAC-calculate-block-sum] 7 (#$ . 7047)])
#@317 This command is called upon a MAC-list datastructure that may be
   segmented, with some MAC-strings shorter or longer than the block
   length. It attempts to make all the strings (except for the last
   one) be of MAC-length size, as well as fix up all the incorrect
   sums. Returns the value of 'h' for the list
(defalias 'MAC-mode-cleanup #[(list) "	!	!" [MAC-mode-fix-strings list MAC-mode-fix-sum] 2 (#$ . 8284)])
#@258 Takes a MAC-list structure where strings may be of wrong
length, and adjusts it so all have MAC-blocksize chars, except for
possibly the last. If any block is adjusted, change the checksum
for it and the previous block to nil to indicate incorrect checksum
(defalias 'MAC-mode-fix-strings #[(list) "A@AAÉ	\n@=\n=\n\fH)GU \fUR @\nA	A	  \n\fI*	@\fI*\fV \n\fH)O\n\fH)O\fI*\n\n\fH)!\fI*\fZ@\n	A	A  \n\fH)\f	@\nA  	@\fI*V+	O!\nBBOZ	A	 U  \n\fI*\n\fH)PGV\nO\fI*\n\fH)\fI*OG@\nA	A	  	G@\nA  \n\fH)GV\n\fH)GV	O!BO	A	GV	!B	Y?	O!\nBB	A	ZOVT	!\nBB.É" [list 0 "" nil len work-string extra offset rest prev current MAC-end-block block MAC-blocksize val 2 MAC-randomizer 1 MAC-make-list-block MAC-list-modified MAC-list-sums-complete] 8 (#$ . 8716)])
#@183 Takes a list of MAC-list-block elements, and sets the value of
  MAC-sum wherever it is set to 'nil, otherwise, it leaves the
  current value there. returns the xor of all the sums.
(defalias 'MAC-mode-fix-sum #[(list) " \n!\n@\nA=A H)+ @\"H)\f\"@A \f+" [MAC-list-modified MAC-mode-fix-strings list nil final rest current MAC-end-block block 2 MAC-calculate-block-sum MAC-xor] 4 (#$ . 9871)])
#@35 Attempts to fix the buffer chosen
(defalias 'MAC-update-buffer #[(buffer) "	!\n 	!q!@A	\n\f=Y H)> \n@\"H)	\"	\n@\nA\n# 	!щ," [timerp MAC-last-idle-timer cancel-timer buffer MAC-mode-fix-strings MAC-list nil MAC-list-modified MAC-list-sums-complete final rest current MAC-end-block block 2 MAC-calculate-block-sum MAC-xor t MAC-local-h MAC-f2 MAC-list-final-sum-good] 4 (#$ . 10313)])
#@99 The computer thinks it is being exceptionally idle, and so
is ready to compute some of the buffer
(defalias 'MAC-mode-idle #[nil "	!\n 	!??  #" [timerp MAC-last-idle-timer cancel-timer MAC-buffers MAC-mode-incremental-fix run-with-timer MAC-idle-wait MAC-idle-repeat] 4 (#$ . 10771)])
#@327 Is called often when the machine is idle, in the hopes of updating
the MAC-list datastructures of all buffers. It will do one thing at a
time, and then return, thereby being 'almost' interruptible. It also
cycles through all the buffers in MAC-buffers. There MUST be a buffer
which is in MAC-mode, or this function will fail.
(defalias 'MAC-mode-incremental-fix #[nil "\n@\nA 	! \n@\nA\f 	!?? \n. 	C3 \n	C	q\fG !  @A	\n\n=  \n\fH)| \n	@\"	@\n	A	Y ? + ? @A	\n\n= \n\fH)\"	@\n	A	 !ω+))" [nil buffer MAC-buffers buffer-name MAC-list-modified MAC-mode-fix-strings MAC-list MAC-list-sums-complete changed rest current MAC-end-block block 2 MAC-calculate-block-sum t MAC-list-final-sum-good MAC-local-h MAC-xor MAC-f2] 4 (#$ . 11081)])
#@76 Select a buffer, and compute the MAC for it, returning the MAC as
  output
(defalias 'MAC-compute-buffer #[(b) "q!!\f\"\n*" [b MAC-prepare-buffer MAC-compute-from-list MAC-list MAC message "The MAC is %s." t MAC-list-sums-complete nil MAC-list-modified] 3 (#$ . 11945)])
#@149 Selects a buffer, and generates a MAC list for it, without filling
in the checksums, hoping that there will be some idle-time used to do
that later
(defalias 'MAC-prepare-buffer #[(b) "q !*\f" [b MAC-make-list-no-sums buffer-string list MAC-list] 3 (#$ . 12242)])
#@166 Takes a long string and returns a properly
formatted (as per MAC-list datastructure) item. It doesn't compute
the checksum for each block, instead leaving it a nil.
(defalias 'MAC-make-list-no-sums #[(str) "G\n	\nB\fU% \f[O!B3 	U3 !BVO S\n_T\n_O!B3 ,B" [str size MAC-blocksize blocks remain MAC-end-block nil list 0 MAC-make-list-block "" MAC-start-block] 6 (#$ . 12522)])
#@80 Takes a string, and turns it into a MAC-list-block.
the checksum is set to nil
(defalias 'MAC-make-list-block #[(str) "		!#" [vector str MAC-randomizer nil] 4 (#$ . 12949)])
#@73 Takes a MAC-list datastructure, and computes the temporary h from
   it
(defalias 'MAC-compute-h-from-list #[(list) "@A!\f!& \n\fH)\"@A\f \n+" [list nil final rest current-block MAC-mode-fix-sum vectorp MAC-xor block 2] 5 (#$ . 13133)])
#@68 Takes a MAC-list datastructure, and computes the final MAC from it
(defalias 'MAC-compute-from-list #[(list) "\n!!" [MAC-f2 MAC-compute-h-from-list list] 3 (#$ . 13399)])
#@165 Takes a current and next block, and sets the sum for the current
block using it's strings and the next block's strings,
which represents f_1(Ri, Ri+1) in the paper
(defalias 'MAC-calculate-block-sum #[(cur-block next-block) "	H)H)P!H)H)P!RH)p#%!)" [tq-enqueue MAC-f1-queue F1-encode cur-block block 0 1 "\n" next-block ".*\n" vector MAC-f1-tq-process accept-process-output MAC-f1-proc] 9 (#$ . 13580)])
#@145 This function is called after a transaction is completed and we
have a block checksum. This simply places the checksum in the
appropriate block
(defalias 'MAC-f1-tq-process #[(closure result) "HqHH)H=( H!I*5 HI*)" [closure 2 0 block 1 F1-decode result val nil] 4 (#$ . 14027)])
#@91 Takes a string of the format 03 aa f2 ... and turns it 
   into an array of number values
(defalias 'F1-decode #[(string) "G\"\fW. \f\f_\f_\\O!I\fT +" [string 3 nil 0 current result len make-string 97 str-to-num 2] 8 (#$ . 14347)])
#@222 Takes a string and turns it into a new string containing
   the hex representation of every char in the string, with the
   following format: '03 aa f2 '  note the final space.. it is
   necessary for this MAC-f1 program
(defalias 'F1-encode #[(string) "GW \fH\"PT \f+" [string "" 0 current result len format "%02x "] 6 (#$ . 14616)])
#@106 Takes a string of the format 'a3' or '2a' and turns it into the 
actual number associated with the value
(defalias 'str-to-num #[(string) "	\fGV, \f!ZV Z_\\\fO +" [0 string nil char cur-string result string-to-char 48 9 49 16 1] 4 (#$ . 14979)])
#@55 Prompts the user for the value of the key used for f1
(defalias 'MAC-get-f1-key #[nil "!" [read-string "Please type in a key for the first-pass function (f1): "] 2 (#$ . 15260)])
#@55 Prompts the user for the value of the key used for f2
(defalias 'MAC-get-f2-key #[nil "!" [read-string "Please type in a key for the second-pass function (f2)  : "] 2 (#$ . 15448)])
#@75 computes the appropriate XOR of the two sum values and returns
the result
(defalias 'MAC-xor #[(arg1 arg2) " \n!\n !G\nG		]\"	^WP H\nH\"IT2 	Wj HITR W \nHITl -" [arg1 copy-sequence arg2 nil 0 result counter common len2 len1 make-string 97 logxor] 7 (#$ . 15639)])
#@43 Takes a value of h, and computes f2 on it
(defalias 'MAC-f2 #[(h) "	!Pp%!)	" [tq-enqueue MAC-f2-queue F2-encode h "\n" ".*\n" MAC-f2-tq-process accept-process-output MAC-f2-proc MAC-final-sum] 6 (#$ . 16000)])
#@55 does encoding for string a appropriate to F2 function
(defalias 'F2-encode #[(a) "	!" [F1-encode a] 2 (#$ . 16230)])
#@55 does encoding for string a appropriate to F2 function
(defalias 'F2-decode #[(a) "	!" [F1-decode a] 2 (#$ . 16355)])
#@89 This function is called when the final checksum has just been
   queued for processing.
(defalias 'MAC-f2-tq-process #[(closure result) "q\n!)" [closure F2-decode result MAC-final-sum] 2 (#$ . 16480)])
#@89 This functions rand(sigma), takes a string as input and computes
a resulting random pad
(defalias 'MAC-randomizer #[(str) "	\nV \nS!!P *" ["" MAC-security-padding num rand-string 0 char-to-string random 256] 3 (#$ . 16695)])
#@106 This function verifies whether a pad that was submitted is indeed a
   valid pad given the string input.
(defalias 'MAC-valid-pad-p #[(str pad) "" [t] 1 (#$ . 16943)])
#@59 run after a file is saved.. attempts to save the checksum
(defalias 'MAC-save-checksum #[nil " !  p!\nP!!!!! !!)!\"- @@Z_A@A@Z\\W _AA@AA@Z\\\"\"" [MAC-mode message "attempting to save MAC.. please hold" modify-start-time current-time start-time MAC-update-buffer require-final-newline MAC-orig-require-final-newline nil buffer-file-truename filename ".sum" new-filename prin1-to-string MAC-compute-from-list MAC-list sum str create-file-buffer buffer switch-to-buffer erase-buffer 10 write-file kill-buffer set-file-modes file-modes time 65536 total-time 2 1000000 "Finished Saving MAC. It took %s microseconds." "Finished Saving MAC. It took %s seconds."] 5 (#$ . 17119)])
#@332 This function attempts to create a MAC-list datastructure that
reflects the exact status of the current buffer. This should be called
after one turns on MAC-mode to speed up the creation of the internal
datastructures by using previously saved information. Returns a
MAC-list datastructure that reflects the current buffer's state
(defalias 'MAC-prepare-checksum #[nil " !p! P\n!0 !p! \n! 	!@\fX \fA@X \fAH \fk !	!p! \fBp\" ! !p!	!-" [nil buffer sumfile m pointer list buffer-file-name message "Could not find checksum. generating in background" MAC-prepare-buffer ".sum" file-readable-p "Could not read checksum. generating in background" find-file-noselect make-marker 1 read MAC-start-block MAC-end-block "sumfile is incorrect, generating in background" kill-buffer MAC-list-matches-buffer-p "Found sumfile with good checksum. using" t MAC-list-modified] 6 (#$ . 17913)])
#@196 Takes a MAC-list structure and a buffer, and checks whether the two
agree on state. THIS DOES NOT CHECK THE CHECKSUM VALUES, only that the
strings in the buffer and in the MAC-list are the same.
(defalias 'MAC-list-matches-buffer-p #[(list buffer) "@A!=! @A\fqdq_ =_ =_ H)c@A5 d\f\f&=s =} )!." [list nil t valid max-for-temp max-for-real temp-buffer rest current generate-new-buffer "temp" MAC-start-block buffer MAC-end-block block 0 compare-buffer-substrings 1 kill-buffer] 8 (#$ . 18887)])
#@106 Evaluates whether a block is valid(i.e. the checksum and
                the pad match the blocks' data)
(defalias 'valid-block-p #[(block next) "J 	? 	\n=??J !	\"H)H)\"4 G H)H)G *" [block next MAC-end-block t copy-sequence first valid MAC-calculate-block-sum MAC-valid-pad-p 0 1 nil 2] 5 (#$ . 19482)])
#@53 Checks the MAC of a supplied filename for validity.
(defalias 'MAC-check-file #[(filename) "	\n\f+ \"P!@ \"!m  !#)P\"!!\"  \"!#')'\"P\"'!(! \f!\f!\f@	\fA\fA  	,H).,H) 	,H).,H) 	\f@\" 	,H)\nd\nd\f@	\n	,H)\"\n\fA\f) 	,H)G\\{	,H)H	,H)G\\	\f@\" \n	,H)2,H)	,H)2,H)\n!!!(!\f!!\"\".\f" [nil 1 done valid buffer datapoint databuffer sumfile m pointer computed-final-sum final-sum list filename message "Could not find %s -- BAD checksum" ".sum" file-readable-p "Could not read checksum: %s.sum --  BAD" t find-file-read-only MAC-f1-key MAC-get-f1-key process-connection-type start-process "F1" generate-new-buffer-name " F1" "/i/yoav/bin/MAC-f1" MAC-f1-proc process-send-string "\n" tq-create MAC-f1-queue MAC-f2-key MAC-get-f2-key "F2" " F2" "/i/yoav/bin/MAC-f2" MAC-f2-proc MAC-f2-queue find-file-noselect make-marker read block 0 MAC-start-block valid-block-p 2 MAC-xor MAC-end-block MAC-f2 tq-close kill-buffer "Good Checksum for %s." "BAD Checksum for %s."] 12 (#$ . 19836) "fFilename to check the MAC of : "])
#@130 Computes the percentage of the buffer for which a valid MAC has
been computed. This is useful for timing and optimization tests.
(defalias 'MAC-percent #[(&optional arg) "q\n@\nA\f6 \fH)' \\- \\@A _\\\"-" [arg 0 MAC-list rest current bad good MAC-end-block block 2 1 message "The percentage is %s." 100] 6 (#$ . 21159) "b"])
#@59 Figures out the time it takes to compute a MAC for a file
(defalias 'MAC-compute-file #[(&optional arg) "   Ɖ" [MAC-mode current-time start-time nil modify-start-time MAC-save-checksum t] 2 (#$ . 21534) "P"])
