Annotation of pgp/src/idea68k.s, revision 1.1.1.1

1.1       root        1: ;-------------------------------------------------------------------------
                      2: ; idea68k.a 
                      3: ;
                      4: ; 68000 Assembler version of idea cipher, direct translation from c code
                      5: ; from PGP.
                      6: ;
                      7: ; Author: Risto Paasivirta, [email protected].
                      8: ;
                      9: 
                     10:                section text,code
                     11: 
                     12:                xdef    _asm_mul,_asm_inv
                     13:                xdef    _asm_cipher_idea
                     14: 
                     15: ; key schedule block
                     16: 
                     17: ROUNDS         equ     8
                     18: 
                     19: Z0             equ     0
                     20: Z1             equ     (ROUNDS+1)*2
                     21: Z2             equ     (ROUNDS+1)*4
                     22: Z3             equ     (ROUNDS+1)*6
                     23: Z4             equ     (ROUNDS+1)*8
                     24: Z5             equ     (ROUNDS+1)*10
                     25: 
                     26: ZSIZE          equ     (ROUNDS+1)*12
                     27: 
                     28: KSSIZE         equ     ZSIZE*2
                     29: 
                     30: ;-------------------------------------------------------------------------
                     31: ;
                     32: ; idmul da,db -- db = da * db mod 65537, d0 = scratch (da may be d0)
                     33: ;
                     34: 
                     35: idmul          macro
                     36:                tst.w   \2
                     37:                bne.b   idmul1.\@
                     38: 
                     39:                moveq   #1,\2
                     40:                sub.w   \1,\2
                     41:                bra.b   idmul3.\@
                     42: 
                     43: idmul1.\@      tst.w   \1
                     44:                bne.b   idmul2.\@
                     45:                moveq   #1,d0
                     46:                sub.w   \2,d0
                     47:                move.w  d0,\2
                     48:                bra.b   idmul3.\@
                     49: 
                     50: idmul2.\@      mulu.w  \1,\2
                     51:                move.l  \2,d0
                     52:                swap    d0
                     53:                sub.w   d0,\2
                     54:                bcc.b   idmul3.\@
                     55:                addq.w  #1,\2
                     56: idmul3.\@
                     57:                endm
                     58: 
                     59: ;-------------------------------------------------------------------------
                     60: ; idea_cip (a0=inblock,a1=outblock,a2=keyshedule) (d0-d7/a3 scratch)
                     61: ;
                     62: ;
                     63: ;
                     64: 
                     65: idea_cip       movem.w (a0),d1-d4
                     66:                moveq   #0,d7
                     67: 
                     68: idea_cip_loop  lea     0(a2,d7.w),a3
                     69:                idmul   (a3),d1
                     70:                idmul   Z3(a3),d4
                     71:                add.w   Z1(a3),d2
                     72:                add.w   Z2(a3),d3
                     73:                move.w  d1,d6
                     74:                eor.w   d3,d6
                     75:                idmul   Z4(a3),d6
                     76:                move.w  d4,d5
                     77:                eor.w   d2,d5
                     78:                add.w   d6,d5
                     79:                idmul   Z5(a3),d5
                     80:                add.w   d5,d6
                     81:                eor.w   d5,d1
                     82:                eor.w   d6,d4
                     83:                eor.w   d6,d2
                     84:                eor.w   d5,d3
                     85:                exg     d2,d3
                     86:                addq.w  #2,d7
                     87:                cmp.w   #ROUNDS*2,d7
                     88:                bcs     idea_cip_loop
                     89: 
                     90:                lea     0(a2,d7.w),a3
                     91:                idmul   (a3),d1
                     92:                idmul   Z3(a3),d4
                     93:                add.w   Z1(a3),d3
                     94:                add.w   Z2(a3),d2
                     95:                exg     d2,d3
                     96:                movem.w d1-d4,(a1)
                     97:                rts
                     98: 
                     99: ;-------------------------------------------------------------------------
                    100: ; _asm_cipher_idea(word16 *in,word16 *out,word16 *ks)
                    101: ;
                    102: ;
                    103: ;
                    104: 
                    105: _asm_cipher_idea
                    106:                movem.l a2-a3/d2-d7,-(sp)
                    107:                movem.l 36(sp),a0-a2
                    108:                bsr     idea_cip
                    109:                movem.l (sp)+,a2-a3/d2-d7
                    110:                rts
                    111: 
                    112: ;-------------------------------------------------------------------------
                    113: ; word16 _asm_mul(word16, word16);
                    114: ;
                    115: ;
                    116: 
                    117: _asm_mul       move.w  6(sp),d1
                    118:                idmul   10(sp),d1
                    119:                moveq   #0,d0
                    120:                move.w  d1,d0
                    121:                rts
                    122: 
                    123: ;-------------------------------------------------------------------------
                    124: ; d0:16 = inv(d0) 
                    125: ;
                    126: 
                    127: _asm_inv       move.w  6(sp),d0
                    128: 
                    129: inv            cmp.w   #2,d0           ; inv(0)=0,inv(1)=1
                    130:                bcs.b   1$
                    131: 
                    132:                cmp.w   #3,d0
                    133:                bcc.b   2$
                    134: 
                    135:                move.w  #32769,d0       ; inv(2)
                    136: 1$             rts
                    137: 
                    138: 2$             movem.l d1-d7,-(sp)
                    139:                move.l  #$10001,d1      ; d1 = n1
                    140:                moveq   #1,d2           ; d2 = b2
                    141:                moveq   #0,d3           ; d3 = b1               
                    142: 
                    143: inv_loop       divu.w  d0,d1
                    144:                move.l  d1,d4
                    145:                swap    d4              ; r = d4
                    146:                tst.w   d4
                    147:                beq.b   inv_done
                    148: 
                    149:                move.w  d2,d5
                    150:                muls.w  d1,d5
                    151:                exg     d3,d2
                    152:                sub.l   d5,d2
                    153:                moveq   #0,d1
                    154:                move.w  d0,d1
                    155:                move.w  d4,d0
                    156:                bra.b   inv_loop
                    157: 
                    158: inv_done       tst.l   d2
                    159:                bpl.b   1$
                    160: 
                    161:                move.l  #$10001,d0
                    162:                add.l   d2,d0
                    163:                bra.b   2$
                    164: 
                    165: 1$             move.l  d2,d0
                    166: 
                    167: 2$             movem.l (sp)+,d1-d7
                    168:                rts
                    169: 
                    170: ;-------------------------------------------------------------------------
                    171: 
                    172:                end
                    173: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.