|
|
1.1 root 1: head 1.1;
2: branch ;
3: access ;
4: symbols ;
5: locks bin:1.1; strict;
6: comment @@;
7:
8:
9: 1.1
10: date 92.10.01.12.05.11; author bin; state Exp;
11: branches ;
12: next ;
13:
14:
15: desc
16: @@
17:
18:
19:
20: 1.1
21: log
22: @Initial revision
23: @
24: text
25: @/////////////////////////////////////////////////////////////////////////
26: / /
27: / /
28: / File: DESSUBS.S /
29: / /
30: / Author: JN /
31: / /
32: / Date: 7/18/86 /
33: / /
34: / Description: Assembly language version of COHERENT (v. 2.3.35) DES /
35: / (Data Encryption Standard) subroutines converted from /
36: / 'C' for speed improvement purposes. The following /
37: / routines are replaced: /
38: / /
39: / permute /
40: / bcopy /
41: / lrot /
42: / m2add /
43: / dosboxes /
44: / /
45: / /
46: /////////////////////////////////////////////////////////////////////////
47:
48: /
49: / Modifications:
50: / 04/01/87; JN; Fixed bug in lrot() where the array wasn't getting
51: / rotated properly for shift counts of 2.
52: /
53:
54: /
55: / Note that not all of these subroutines use the same algorithms as their 'C'
56: / counter-parts (for speed), although the result is the same.
57: /
58:
59: ///////
60: /
61: / permute(src, dest, tptr, nbits)
62: / char *src, *dest, *tptr;
63: / int nbits;
64: /
65: / Input: dest = pointer to place to store permuted bit array
66: / src = pointer to bit array to permute
67: / tptr = pointer to table containing permution data
68: / nbits = number of bits to permute
69: /
70: / Action: Using pointer to passed table, stores permuted source
71: / bit array into destination.
72: /
73: / Returns: nothing.
74: /
75: ///////
76:
77: .globl permute_ / visible by all
78: .shri / shared instruction
79:
80: permute_:
81: push si
82: push di
83: push bp
84: mov bp,sp
85: mov cx,14(bp) / get number of bits
86: mov si,12(bp) / get pointer to table
87: mov di,10(bp) / get pointer to dest
88: mov dx,8(bp) / get pointer to source
89: shr cx,$1 / always even
90: cld
91:
92: perm_0:
93: lodsw / get 2 bit positions from table
94: movb bl,al / get 1st bit position
95: xorb bh,bh / zero bh
96: add bx,dx / bx = pointer to specified source bit
97: movb al,(bx) / get bit
98:
99: movb bl,ah / get 2nd bit position
100: xorb bh,bh / zero bh
101: add bx,dx / bx = pointer to specified source bit
102: movb ah,(bx) / get bit
103: stosw / store both bits
104: loop perm_0
105:
106: pop bp
107: pop di
108: pop si
109: ret
110:
111:
112:
113: ///////
114: /
115: / bcopy(src, dest, n)
116: / char *src, *dest;
117: / int n;
118: /
119: / Input: dest = pointer to dest string
120: / src = pointer to source string
121: / n = number of bytes to copy
122: /
123: / Action: copy source string to destination.
124: /
125: / Returns: nothing.
126: /
127: ///////
128:
129: .globl bcopy_ / visible by all
130: .shri / shared instruction
131:
132: bcopy_:
133: push si
134: push di
135: push bp
136: mov bp,sp
137: mov cx,12(bp) / get count
138: mov si,8(bp) / get pointer to source
139: mov di,10(bp) / get pointer to dest
140: cld
141:
142: bcpy_0:
143: shr cx,$1 / copy words for speed
144: jnc bcpy_1 / even if no carry
145: movsb / move odd byte
146:
147: bcpy_1:
148: rep
149: movsw / copy the rest
150: pop bp
151: pop di
152: pop si
153: ret
154:
155:
156: ///////
157: /
158: / lrot(bits, ns, nbits)
159: / char *bits;
160: / int ns, nbits;
161: /
162: / Input: bits = pointer to bit array
163: / ns = number of shifts
164: / nbits = number of bits in bit array (1 or 2)
165: /
166: / Action: rotate bit array left 'ns' number of times. 'ns'
167: / must be a 1 or 2.
168: /
169: / Returns: nothing.
170: /
171: ///////
172:
173: .globl lrot_ / visible by all
174: .shri / shared instruction
175:
176: lrot_:
177: push si
178: push di
179: push bp
180: mov bp,sp
181: movb dl,10(bp) / get number of times to rotate
182: mov cx,12(bp) / get number of bits
183: cld
184: mov si,8(bp) / point to bit array
185: mov di,si
186: decb dl / dl = 1 or 2
187: jnz lr2
188: call lrot_1 / rotate left by one
189: jmp lr_ret
190:
191: lr2:
192: call lrot_2 / rotate left by two
193:
194: lr_ret:
195: pop bp
196: pop di
197: pop si
198: ret
199:
200: /
201: / subroutine to rotate bit array left by one
202: /
203:
204: lrot_1:
205: lodsb / get first bit (carry)
206: movb ah,al / and save
207: dec cx / already got carry bit
208: rep
209: movsb / shift left by one
210: movb al,ah
211: stosb / store carry bit
212: ret
213:
214:
215: /
216: / subroutine to rotate bit array left by two
217: /
218:
219: lrot_2:
220: lodsw / get first bits (carry)
221: shr cx,$1 / always even
222: dec cx / already got carry bits
223: rep
224: movsw / shift left by two
225: stosw / store carry bits
226: ret
227:
228:
229: ///////
230: /
231: / m2add(i1, i2, o, nbits)
232: / char *i1, *i2, *o;
233: / int nbits;
234: /
235: / Input: i1 = pointer to 1st bit array
236: / i2 = pointer to 2nd bit array
237: / o = place to store the result
238: / nbits = number of bits in each bit array
239: /
240: / Action: modulo 2 addition of bit arrays (exclusive or)
241: /
242: / Returns: nothing.
243: /
244: ///////
245:
246: .globl m2add_ / visible by all
247: .shri / shared instruction
248:
249: m2add_:
250: push si
251: push di
252: push bp
253: mov bp,sp
254: mov cx,14(bp) / get number of bits
255: mov si,8(bp) / get i1
256: mov bx,10(bp) / get i2
257: mov di,12(bp) / get dest
258: shr cx,$1 / always even
259: cld
260:
261: m2add_1:
262: lodsw / get 2 bits from i1
263: xor ax,(bx) / o = i1 xor i2
264: inc bx / inc ptr to i2
265: inc bx
266: stosw / store into o
267: loop m2add_1
268: pop bp
269: pop di
270: pop si
271: ret
272:
273:
274: ///////
275: /
276: / dosboxes(ibits, obits)
277: / char *ibits, *ibits;
278: /
279: / Input: ibits = pointer to source (48 bit array)
280: / obits = pointer to dest (32 bit array)
281: /
282: / Action: convert source array into destination array using
283: / the 'S-box' functions.
284: /
285: / Returns: nothing.
286: /
287: ///////
288:
289: .globl dosboxes_ / visible by all
290: .shri / shared instruction
291:
292: dosboxes_:
293: push si
294: push di
295: push bp
296: mov bp,sp
297: sub sp,$2 / allocate local space
298: cld
299:
300: /
301: / initialize variables
302: /
303: mov -2(bp),$0 / count (0 - 7)
304: mov si,8(bp) / pointer to source
305: mov di,10(bp) / pointer to place to store result
306:
307: /
308: / parse the source array in 6 bit pieces-- the first and last
309: / bits are the S-box row, the middle 4 bits are the S-box column.
310: /
311:
312: dosbox_0:
313: lodsb / r1
314: movb dl,al / dl = row
315: lodsb / c1
316: movb dh,al / dh = column
317: shlb dh,$1
318: lodsb / c2
319: orb dh,al
320: shlb dh,$1
321: lodsb / c3
322: orb dh,al
323: shlb dh,$1
324: lodsb / c4
325: orb dh,al
326: shlb dl,$1
327: lodsb / r2
328: orb dl,al
329:
330: /
331: / get S-box entry using row & column address
332: /
333: mov bx,-2(bp) / get count
334: movb cl,$6 / sbox = count * 64 (size of each sbox)
335: shl bx,cl
336: movb al,dl / get row number
337: xorb ah,ah / zero ah
338: movb cl,$4 / row = row # * 16
339: shl ax,cl
340: add bx,ax
341: movb al,dh / get column number
342: xorb ah,ah / zero ah
343: add bx,ax / bx now points to the proper sbox entry
344: movb ah,Sboxes_(bx) / get sbox entry
345:
346: /
347: / unpack sbox entry and store in dest
348: /
349: mov cx,$4 / # of significant bits in sbox entry
350: shlb ah,cl / move to upper nybble
351:
352: sbox_0:
353: xorb al,al / default to zero bit
354: shlb ah,$1 / shift left bit into carry
355: jnc sbox_1
356: incb al / a 1 was shifted out
357:
358: sbox_1:
359: stosb / store bit into dest
360: loop sbox_0
361:
362: /
363: / do until count (bp-2) = 8
364: /
365: inc -2(bp)
366: cmp -2(bp),$8
367: jb dosbox_0
368: mov sp,bp / de-allocate local space
369: pop bp
370: pop di
371: pop si
372: ret
373:
374:
375:
376:
377: @
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.