annotate lisp/md4.el @ 94818:8eb267268480

Document the new VC directory mode.
author Eric S. Raymond <esr@snark.thyrsus.com>
date Fri, 09 May 2008 20:03:27 +0000
parents ee5932bf781d
children 225286546090
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
86793
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1 ;;; md4.el --- MD4 Message Digest Algorithm.
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
2
87665
b9e8ab94c460 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86793
diff changeset
3 ;; Copyright (C) 2001, 2004, 2007, 2008 Free Software Foundation, Inc.
86793
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
4
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
5 ;; Author: Taro Kawagishi <tarok@transpulse.org>
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
6 ;; Keywords: MD4
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
7 ;; Version: 1.00
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
8 ;; Created: February 2001
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
9
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
11
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
86793
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
15 ;; (at your option) any later version.
86793
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
16
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
21
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
86793
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
24
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
25 ;;; Code:
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
26
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27 ;;;
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28 ;;; MD4 hash calculation
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
29
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
30 (defvar md4-buffer (make-vector 4 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
31 "work buffer of four 32-bit integers")
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
32
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
33 (defun md4 (in n)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
34 "Returns the MD4 hash string of 16 bytes long for a string IN of N
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
35 bytes long. N is required to handle strings containing character 0."
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
36 (let (m
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
37 (b (cons 0 (* n 8)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
38 (i 0)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
39 (buf (make-string 128 0)) c4)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40 ;; initial values
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
41 (aset md4-buffer 0 '(26437 . 8961)) ;0x67452301
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
42 (aset md4-buffer 1 '(61389 . 43913)) ;0xefcdab89
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
43 (aset md4-buffer 2 '(39098 . 56574)) ;0x98badcfe
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
44 (aset md4-buffer 3 '(4146 . 21622)) ;0x10325476
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
45
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 ;; process the string in 64 bits chunks
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 (while (> n 64)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48 (setq m (md4-copy64 (substring in 0 64)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 (md4-64 m)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 (setq in (substring in 64))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
51 (setq n (- n 64)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 ;; process the rest of the string (length is now n <= 64)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54 (setq i 0)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55 (while (< i n)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 (aset buf i (aref in i))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 (setq i (1+ i)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58 (aset buf n 128) ;0x80
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
59 (if (<= n 55)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 (progn
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61 (setq c4 (md4-pack-int32 b))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62 (aset buf 56 (aref c4 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63 (aset buf 57 (aref c4 1))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64 (aset buf 58 (aref c4 2))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 (aset buf 59 (aref c4 3))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 (setq m (md4-copy64 buf))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67 (md4-64 m))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68 ;; else
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 (setq c4 (md4-pack-int32 b))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70 (aset buf 120 (aref c4 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 (aset buf 121 (aref c4 1))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72 (aset buf 122 (aref c4 2))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73 (aset buf 123 (aref c4 3))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
74 (setq m (md4-copy64 buf))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 (md4-64 m)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76 (setq m (md4-copy64 (substring buf 64)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77 (md4-64 m)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
78
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79 (concat (md4-pack-int32 (aref md4-buffer 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80 (md4-pack-int32 (aref md4-buffer 1))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81 (md4-pack-int32 (aref md4-buffer 2))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
82 (md4-pack-int32 (aref md4-buffer 3))))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
83
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
84 (defsubst md4-F (x y z) (logior (logand x y) (logand (lognot x) z)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
85 (defsubst md4-G (x y z) (logior (logand x y) (logand x z) (logand y z)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
86 (defsubst md4-H (x y z) (logxor x y z))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
87
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
88 (defmacro md4-make-step (name func)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
89 `(defun ,name (a b c d xk s ac)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
90 (let*
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
91 ((h1 (+ (car a) (,func (car b) (car c) (car d)) (car xk) (car ac)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
92 (l1 (+ (cdr a) (,func (cdr b) (cdr c) (cdr d)) (cdr xk) (cdr ac)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
93 (h2 (logand 65535 (+ h1 (lsh l1 -16))))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
94 (l2 (logand 65535 l1))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
95 ;; cyclic shift of 32 bits integer
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
96 (h3 (logand 65535 (if (> s 15)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
97 (+ (lsh h2 (- s 32)) (lsh l2 (- s 16)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
98 (+ (lsh h2 s) (lsh l2 (- s 16))))))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
99 (l3 (logand 65535 (if (> s 15)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
100 (+ (lsh l2 (- s 32)) (lsh h2 (- s 16)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
101 (+ (lsh l2 s) (lsh h2 (- s 16)))))))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
102 (cons h3 l3))))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
103
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
104 (md4-make-step md4-round1 md4-F)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
105 (md4-make-step md4-round2 md4-G)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
106 (md4-make-step md4-round3 md4-H)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
107
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
108 (defsubst md4-add (x y)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
109 "Return 32-bit sum of 32-bit integers X and Y."
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
110 (let ((h (+ (car x) (car y)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
111 (l (+ (cdr x) (cdr y))))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
112 (cons (logand 65535 (+ h (lsh l -16))) (logand 65535 l))))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
113
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
114 (defsubst md4-and (x y)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
115 (cons (logand (car x) (car y)) (logand (cdr x) (cdr y))))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
116
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
117 (defun md4-64 (m)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
118 "Calculate md4 of 64 bytes chunk M which is represented as 16 pairs of
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
119 32 bits integers. The resulting md4 value is placed in md4-buffer."
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
120 (let ((a (aref md4-buffer 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
121 (b (aref md4-buffer 1))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
122 (c (aref md4-buffer 2))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
123 (d (aref md4-buffer 3)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
124 (setq a (md4-round1 a b c d (aref m 0) 3 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
125 d (md4-round1 d a b c (aref m 1) 7 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
126 c (md4-round1 c d a b (aref m 2) 11 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
127 b (md4-round1 b c d a (aref m 3) 19 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
128 a (md4-round1 a b c d (aref m 4) 3 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
129 d (md4-round1 d a b c (aref m 5) 7 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
130 c (md4-round1 c d a b (aref m 6) 11 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
131 b (md4-round1 b c d a (aref m 7) 19 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
132 a (md4-round1 a b c d (aref m 8) 3 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
133 d (md4-round1 d a b c (aref m 9) 7 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
134 c (md4-round1 c d a b (aref m 10) 11 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
135 b (md4-round1 b c d a (aref m 11) 19 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
136 a (md4-round1 a b c d (aref m 12) 3 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
137 d (md4-round1 d a b c (aref m 13) 7 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
138 c (md4-round1 c d a b (aref m 14) 11 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
139 b (md4-round1 b c d a (aref m 15) 19 '(0 . 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
140
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
141 a (md4-round2 a b c d (aref m 0) 3 '(23170 . 31129)) ;0x5A827999
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
142 d (md4-round2 d a b c (aref m 4) 5 '(23170 . 31129))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
143 c (md4-round2 c d a b (aref m 8) 9 '(23170 . 31129))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
144 b (md4-round2 b c d a (aref m 12) 13 '(23170 . 31129))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
145 a (md4-round2 a b c d (aref m 1) 3 '(23170 . 31129))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
146 d (md4-round2 d a b c (aref m 5) 5 '(23170 . 31129))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
147 c (md4-round2 c d a b (aref m 9) 9 '(23170 . 31129))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
148 b (md4-round2 b c d a (aref m 13) 13 '(23170 . 31129))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
149 a (md4-round2 a b c d (aref m 2) 3 '(23170 . 31129))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
150 d (md4-round2 d a b c (aref m 6) 5 '(23170 . 31129))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
151 c (md4-round2 c d a b (aref m 10) 9 '(23170 . 31129))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
152 b (md4-round2 b c d a (aref m 14) 13 '(23170 . 31129))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
153 a (md4-round2 a b c d (aref m 3) 3 '(23170 . 31129))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
154 d (md4-round2 d a b c (aref m 7) 5 '(23170 . 31129))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
155 c (md4-round2 c d a b (aref m 11) 9 '(23170 . 31129))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
156 b (md4-round2 b c d a (aref m 15) 13 '(23170 . 31129))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
157
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
158 a (md4-round3 a b c d (aref m 0) 3 '(28377 . 60321)) ;0x6ED9EBA1
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
159 d (md4-round3 d a b c (aref m 8) 9 '(28377 . 60321))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
160 c (md4-round3 c d a b (aref m 4) 11 '(28377 . 60321))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
161 b (md4-round3 b c d a (aref m 12) 15 '(28377 . 60321))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
162 a (md4-round3 a b c d (aref m 2) 3 '(28377 . 60321))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
163 d (md4-round3 d a b c (aref m 10) 9 '(28377 . 60321))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
164 c (md4-round3 c d a b (aref m 6) 11 '(28377 . 60321))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
165 b (md4-round3 b c d a (aref m 14) 15 '(28377 . 60321))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
166 a (md4-round3 a b c d (aref m 1) 3 '(28377 . 60321))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
167 d (md4-round3 d a b c (aref m 9) 9 '(28377 . 60321))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
168 c (md4-round3 c d a b (aref m 5) 11 '(28377 . 60321))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
169 b (md4-round3 b c d a (aref m 13) 15 '(28377 . 60321))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
170 a (md4-round3 a b c d (aref m 3) 3 '(28377 . 60321))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
171 d (md4-round3 d a b c (aref m 11) 9 '(28377 . 60321))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
172 c (md4-round3 c d a b (aref m 7) 11 '(28377 . 60321))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
173 b (md4-round3 b c d a (aref m 15) 15 '(28377 . 60321)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
174
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
175 (aset md4-buffer 0 (md4-add a (aref md4-buffer 0)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
176 (aset md4-buffer 1 (md4-add b (aref md4-buffer 1)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
177 (aset md4-buffer 2 (md4-add c (aref md4-buffer 2)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
178 (aset md4-buffer 3 (md4-add d (aref md4-buffer 3)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
179 ))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
180
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
181 (defun md4-copy64 (seq)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
182 "Unpack a 64 bytes string into 16 pairs of 32 bits integers."
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
183 (let ((int32s (make-vector 16 0)) (i 0) j)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
184 (while (< i 16)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
185 (setq j (* i 4))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
186 (aset int32s i (cons (+ (aref seq (+ j 2)) (lsh (aref seq (+ j 3)) 8))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
187 (+ (aref seq j) (lsh (aref seq (1+ j)) 8))))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
188 (setq i (1+ i)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
189 int32s))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
190
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
191 ;;;
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
192 ;;; sub functions
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
193
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
194 (defun md4-pack-int16 (int16)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
195 "Pack 16 bits integer in 2 bytes string as little endian."
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
196 (let ((str (make-string 2 0)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
197 (aset str 0 (logand int16 255))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
198 (aset str 1 (lsh int16 -8))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
199 str))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
200
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
201 (defun md4-pack-int32 (int32)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
202 "Pack 32 bits integer in a 4 bytes string as little endian. A 32 bits
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
203 integer is represented as a pair of two 16 bits integers (cons high low)."
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
204 (let ((str (make-string 4 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
205 (h (car int32)) (l (cdr int32)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
206 (aset str 0 (logand l 255))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
207 (aset str 1 (lsh l -8))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
208 (aset str 2 (logand h 255))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
209 (aset str 3 (lsh h -8))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
210 str))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
211
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
212 (defun md4-unpack-int16 (str)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
213 (if (eq 2 (length str))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
214 (+ (lsh (aref str 1) 8) (aref str 0))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
215 (error "%s is not 2 bytes long" str)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
216
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
217 (defun md4-unpack-int32 (str)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
218 (if (eq 4 (length str))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
219 (cons (+ (lsh (aref str 3) 8) (aref str 2))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
220 (+ (lsh (aref str 1) 8) (aref str 0)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
221 (error "%s is not 4 bytes long" str)))
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
222
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
223 (provide 'md4)
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
224
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87665
diff changeset
225 ;; arch-tag: 99d706fe-089b-42ea-9507-67ae41091e6e
86793
4931e6c0f869 Move here from gnus/.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
226 ;;; md4.el ends here