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