|
|
1.1 ! root 1: /* ! 2: ** ! 3: ** 80386 assembly primitives for RSA library ! 4: ** GNU gas syntax, tested with gcc v1.39 ! 5: ** ! 6: ** Compile with UNIT32 defined, MULTUNIT must be unsigned long ! 7: ** assemble this file with gcc -c (file should have .S suffix) ! 8: ** ! 9: ** Written by Branko Lankester ([email protected]) 11/18/91 ! 10: ** Last revised: 03/04/91 ! 11: ** ! 12: */ ! 13: ! 14: #if defined(__GNUC__) || defined(__ASSEMBLER__) ! 15: #ifdef __STDC__ ! 16: #define ENTRY(name) .align 4 ; .globl _##name ; _##name: ! 17: #else ! 18: #define ENTRY(name) .align 4 ; .globl _/**/name ; _/**/name: ! 19: #endif ! 20: #else /* !__GNUC__ */ ! 21: #define ENTRY(name) .align 4 ; .globl name ; name: ! 22: #endif ! 23: ! 24: .text ! 25: ! 26: /* ! 27: ********************* set precision ******************** ! 28: */ ! 29: ENTRY (P_SETP) ! 30: pushl %ebp ! 31: movl %esp,%ebp ! 32: pushl %ebx ! 33: pushl %ecx ! 34: pushl %edx ! 35: movl 8(%ebp),%eax ! 36: addl $0x1f,%eax ! 37: shrl $5,%eax ! 38: movl %eax,%ebx ! 39: shrl $3,%eax ! 40: movl %eax,prec8 ! 41: andl $7,%ebx ! 42: ! 43: movl $add_ref,%eax ! 44: movl %eax,%ecx ! 45: subl $add_1ref,%eax ! 46: mul %ebx ! 47: subl %eax,%ecx ! 48: movl %ecx,addp ! 49: movl $sub_ref,%ecx ! 50: subl %eax,%ecx ! 51: movl %ecx,subp ! 52: ! 53: movl $rot_ref,%eax ! 54: movl %eax,%ecx ! 55: subl $rot_1ref,%eax ! 56: mul %ebx ! 57: subl %eax,%ecx ! 58: movl %ecx,rotp ! 59: ! 60: movl $mul_ref,%eax ! 61: movl %eax,%ecx ! 62: subl $mul_1ref,%eax ! 63: mul %ebx ! 64: subl %eax,%ecx ! 65: movl %ecx,mulp ! 66: ! 67: popl %edx ! 68: popl %ecx ! 69: popl %ebx ! 70: leave ! 71: ret ! 72: ! 73: ! 74: ! 75: /* ! 76: ********************* mpi add with carry ******************** ! 77: */ ! 78: ! 79: #define ADDU lodsl ; adcl %eax,(%ebx,%esi) ! 80: ! 81: ENTRY (P_ADDC) ! 82: pushl %ebp ! 83: movl %esp,%ebp ! 84: pushl %ebx ! 85: pushl %ecx ! 86: pushl %esi ! 87: pushl %edi ! 88: movl 12(%ebp),%esi ! 89: movl 8(%ebp),%ebx ! 90: subl %esi,%ebx ! 91: subl $4,%ebx ! 92: cld ! 93: movl 16(%ebp),%eax ! 94: movl prec8,%ecx ! 95: orl %ecx,%ecx ! 96: rcrl $1,%eax /* set the carry flag */ ! 97: jz add_units /* z-flag set by orl %ecx,%ecx */ ! 98: add_8u: ! 99: ADDU ; ADDU ; ADDU ; ADDU ; ADDU ; ADDU ; ADDU ; ADDU ! 100: loop add_8u ! 101: add_units: ! 102: jmp *addp ! 103: ADDU ; ADDU ; ADDU ; ADDU ; ADDU ; ADDU ! 104: add_1ref: /* label to compute size of codes */ ! 105: ADDU ! 106: add_ref: ! 107: rcll $1,%eax ! 108: andl $1,%eax ! 109: ! 110: popl %edi ! 111: popl %esi ! 112: popl %ecx ! 113: popl %ebx ! 114: leave ! 115: ret ! 116: ! 117: ! 118: /* ! 119: ********************* mpi subtract with borrow ******************** ! 120: */ ! 121: ! 122: #define SUBU lodsl ; sbbl %eax,(%ebx,%esi) ! 123: ! 124: ENTRY (P_SUBB) ! 125: pushl %ebp ! 126: movl %esp,%ebp ! 127: pushl %ebx ! 128: pushl %ecx ! 129: pushl %esi ! 130: pushl %edi ! 131: movl 12(%ebp),%esi ! 132: movl 8(%ebp),%ebx ! 133: subl %esi,%ebx ! 134: subl $4,%ebx ! 135: cld ! 136: movl 16(%ebp),%eax ! 137: movl prec8,%ecx ! 138: orl %ecx,%ecx ! 139: rcrl $1,%eax ! 140: jz sub_units ! 141: sub_8u: ! 142: SUBU ; SUBU ; SUBU ; SUBU ; SUBU ; SUBU ; SUBU ; SUBU ! 143: loop sub_8u ! 144: sub_units: ! 145: jmp *subp ! 146: SUBU ; SUBU ; SUBU ; SUBU ; SUBU ; SUBU ; SUBU ! 147: sub_ref: ! 148: rcll $1,%eax ! 149: andl $1,%eax ! 150: ! 151: popl %edi ! 152: popl %esi ! 153: popl %ecx ! 154: popl %ebx ! 155: leave ! 156: ret ! 157: ! 158: ! 159: ! 160: /* ! 161: ********************* mpi rotate left ******************** ! 162: */ ! 163: ! 164: #define ROTU rcll $1,(%ebx,%esi,4) ; incl %esi ! 165: ! 166: ENTRY (P_ROTL) ! 167: pushl %ebp ! 168: movl %esp,%ebp ! 169: pushl %ebx ! 170: pushl %ecx ! 171: pushl %esi ! 172: movl 8(%ebp),%ebx ! 173: movl 12(%ebp),%eax ! 174: xorl %esi,%esi ! 175: movl prec8,%ecx ! 176: orl %ecx,%ecx ! 177: rcrl $1,%eax /* set the carry flag */ ! 178: jz rot_units /* z-flag set by orl %ecx,%ecx */ ! 179: rot_8u: ! 180: rcll $1,(%ebx) ! 181: rcll $1,4(%ebx) ! 182: rcll $1,8(%ebx) ! 183: rcll $1,12(%ebx) ! 184: rcll $1,16(%ebx) ! 185: rcll $1,20(%ebx) ! 186: rcll $1,24(%ebx) ! 187: rcll $1,28(%ebx) ! 188: leal 32(%ebx),%ebx ! 189: loop rot_8u ! 190: rot_units: ! 191: jmp *rotp ! 192: ROTU ; ROTU ; ROTU ; ROTU ; ROTU ; ROTU ; ROTU ! 193: rot_1ref: ! 194: ROTU ! 195: rot_ref: ! 196: rcll $1,%eax ! 197: andl $1,%eax ! 198: ! 199: popl %esi ! 200: popl %ecx ! 201: popl %ebx ! 202: leave ! 203: ret ! 204: ! 205: /* ! 206: ********************* mpi multiply ******************** ! 207: */ ! 208: #define MULU \ ! 209: lodsl ; \ ! 210: mull %ebp ; \ ! 211: addl %ebx,%eax ; \ ! 212: adcl $0,%edx ; \ ! 213: addl (%edi),%eax ; \ ! 214: adcl $0,%edx ; \ ! 215: movl %edx,%ebx ; \ ! 216: stosl ! 217: ! 218: ENTRY (P_SMUL) ! 219: pushl %ebp ! 220: movl %esp,%ebp ! 221: pushl %ebx ! 222: pushl %ecx ! 223: pushl %edx ! 224: pushl %esi ! 225: pushl %edi ! 226: ! 227: xorl %ebx,%ebx ! 228: movl prec8,%ecx ! 229: movl 8(%ebp),%edi ! 230: movl 12(%ebp),%esi ! 231: movl 16(%ebp),%ebp ! 232: cld ! 233: orl %ecx,%ecx ! 234: jz mul_units ! 235: mul_8u: ! 236: MULU ; MULU ; MULU ; MULU ; MULU ; MULU ; MULU ; MULU ! 237: decl %ecx ! 238: jnz mul_8u /* offset too big for loop */ ! 239: mul_units: ! 240: jmp *mulp ! 241: MULU ; MULU ; MULU ; MULU ; MULU ; MULU ! 242: mul_1ref: ! 243: MULU ! 244: mul_ref: ! 245: movl %ebx,(%edi) ! 246: ! 247: popl %edi ! 248: popl %esi ! 249: popl %edx ! 250: popl %ecx ! 251: popl %ebx ! 252: popl %ebp ! 253: ret ! 254: ! 255: .lcomm prec8,4 ! 256: .lcomm addp,4 ! 257: .lcomm subp,4 ! 258: .lcomm rotp,4 ! 259: .lcomm mulp,4 ! 260:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.