⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 twofish.lst

📁 简单的BASE算法
💻 LST
📖 第 1 页 / 共 2 页
字号:
  220                         		eor	tabEF,X
  221                         		sta	dst
  222                         		lda	dst+1
  223                         		eor	tabEF,X
  224                         		sta	dst+1
  225                         		lda	dst+2
  226                         		eor	tab5B,X
  227                         		sta	dst+2
  228                         		txa
  229                         		eor	dst+3
  230                         		sta	dst+3
  231                         	  .else
  232                         	    .if USE_ALPHA_TAB
  233                         		stx	tmp
  234                         		txa
  235                         		eor	dst+3
  236                         		sta	dst+3
  237                         		ldx	alpha,X
  238                         		stx	tmp+1		;tmp+1 = alpha**-1
  239                         		lda	alpha,X
  240                         	    .else
  241                         		sta	tmp		;save the 01 thing
  242                         		eor	dst+3
  243                         		sta	dst+3		;xor the 01
  244                         		lda	tmp
  245                         		mulAlpha
  246                         		sta	tmp+1
  247                         		mulAlpha
  248                         	    .endif
  249                         		eor	tmp		;now A = 5B
  250                         		tax			;save 5B in X
  Sat Jun 13 11:05:07 1998                                                                                               Page    6

        Twofish for 6805
        Author: Doug Whiting, Hi/fn, May 1998

  251                         		eor	dst+2
  252                         		sta	dst+2
  253                         		txa			;A = 5B
  254                         		eor	tmp+1		;now A = EF
  255                         		tax			;save 5F in X
  256                         		eor	dst+1
  257                         		sta	dst+1
  258                         		txa	
  259                         		eor	dst
  260                         		sta	dst
  261                         	  .endif
  262                         		;--- 3rd byte, 3rd MDS column = 5B EF 01 EF
  263                         		Sbox8	srcB0+((rotCnt+step*2).AND.3),p0,p1,p1,key+2
  264                         	  .if USE_MDS_TAB
  265                         		lda	dst
  266                         		eor	tab5B,X
  267                         		sta	dst
  268                         		lda	dst+1
  269                         		eor	tabEF,X
  270                         		sta	dst+1
  271                         		txa	
  272                         		eor	dst+2
  273                         		sta	dst+2
  274                         		lda	dst+3
  275                         		eor	tabEF,X
  276                         		sta	dst+3
  277                         	  .else
  278                         	    .if USE_ALPHA_TAB
  279                         		stx	tmp
  280                         		txa
  281                         		eor	dst+2
  282                         		sta	dst+2
  283                         		ldx	alpha,X
  284                         		stx	tmp+1		;tmp+1 = alpha**-1
  285                         		lda	alpha,X
  286                         	    .else
  287                         		sta	tmp		;save the 01 thing
  288                         		eor	dst+2
  289                         		sta	dst+2		;xor the 01
  290                         		lda	tmp
  291                         		mulAlpha
  292                         		sta	tmp+1
  293                         		mulAlpha
  294                         	    .endif
  295                         		eor	tmp		;now A = 5B
  296                         		tax			;save 5B in X
  297                         		eor	dst
  298                         		sta	dst
  299                         		txa			;A = 5B
  300                         		eor	tmp+1		;now A = EF
  301                         		tax			;save 5F in X
  302                         		eor	dst+1
  303                         		sta	dst+1
  304                         		txa	
  305                         		eor	dst+3
  306                         		sta	dst+3
  307                         	  .endif
  Sat Jun 13 11:05:07 1998                                                                                               Page    7

        Twofish for 6805
        Author: Doug Whiting, Hi/fn, May 1998

  308                         		;--- 4th byte, 4th MDS column = 5B 01 EF 5B
  309                         		Sbox8	srcB0+((rotCnt+step*3).AND.3),p1,p1,p0,key+3
  310                         	  .if USE_MDS_TAB
  311                         		lda	dst
  312                         		eor	tab5B,X
  313                         		sta	dst
  314                         		txa
  315                         		eor	dst+1
  316                         		sta	dst+1
  317                         		lda	dst+2
  318                         		eor	tabEF,X
  319                         		sta	dst+2
  320                         		lda	dst+3
  321                         		eor	tab5B,X
  322                         		sta	dst+3
  323                         	  .else
  324                         	    .if USE_ALPHA_TAB
  325                         		stx	tmp
  326                         		txa
  327                         		eor	dst+1
  328                         		sta	dst+1
  329                         		ldx	alpha,X
  330                         		stx	tmp+1		;tmp+1 = alpha**-1
  331                         		lda	alpha,X
  332                         	    .else
  333                         		sta	tmp		;save the 01 thing
  334                         		eor	dst+1
  335                         		sta	dst+1		;xor the 01
  336                         		lda	tmp
  337                         		mulAlpha
  338                         		sta	tmp+1
  339                         		mulAlpha
  340                         	    .endif
  341                         		eor	tmp		;now A = 5B
  342                         		tax			;save 5B in X
  343                         		eor	dst
  344                         		sta	dst
  345                         		txa			;A = 5B
  346                         		eor	dst+3
  347                         		sta	dst+3
  348                         		txa
  349                         		eor	tmp+1		;now A = EF
  350                         		eor	dst+2
  351                         		sta	dst+2
  352                         	  .endif
  353                         	f32Size		.var $-tmpf32
  354                         	f32ByteCnt	.var f32ByteCnt+f32Size
  355                         		.endm
  356                         	
  357                         	
  358                         	op1	.macro	opCode,a,b
  359                         	tmpOp		.var $
  360                         		lda	a
  361                         		opCode	b
  362                         		sta	a
  363                         	tmpOp		.var $-tmpOp
  364                         	op1ByteCnt .var op1ByteCnt+tmpOp
  Sat Jun 13 11:05:07 1998                                                                                               Page    8

        Twofish for 6805
        Author: Doug Whiting, Hi/fn, May 1998

  365                         		.endm
  366                         	
  367                         	op4	.macro	opCode1,opCode2,a,b
  368                         		op1	opCode1,a  ,b
  369                         		op1	opCode2,a+1,b+1
  370                         		op1	opCode2,a+2,b+2
  371                         		op1	opCode2,a+3,b+3
  372                         		.endm
  373                         	
  374                         	swap1	.macro	y,z
  375                         	tmpSwap		.var	$
  376                         		ldx	y
  377                         		lda	z
  378                         		stx	z
  379                         		sta	y
  380                         	tmpSwap		.var	$-tmpSwap
  381                         	swap1ByteCnt .var swap1ByteCnt+tmpSwap
  382                         		.endm
  383                         	
  384                         	swap4	.macro	y,z
  385                         		swap1	y  ,z
  386                         		swap1	y+1,z+1
  387                         		swap1	y+2,z+2
  388                         		swap1	y+3,z+3
  389                         		.endm
  390                         	
  391                         	mov4	.macro	src,dst
  392                         		lda	src
  393                         		sta	dst
  394                         		lda	src+1
  395                         		sta	dst+1
  396                         		lda	src+2
  397                         		sta	dst+2
  398                         		lda	src+3
  399                         		sta	dst+3
  400                         		.endm
  401                         	
  402                         	add4	.macro	a,b		;a=a+b (dword operation)
  403                         		op4	add,adc,a,b
  404                         		.endm
  405                         	
  406                         	add4_1	.macro	a,b		;add4, but assume A already == b[0]
  407                         		add	a		;(save one opcode, three clocks)
  408                         		sta	a
  409                         		op1	adc,a+1,b+1
  410                         		op1	adc,a+2,b+2
  411                         		op1	adc,a+3,b+3
  412                         		.endm
  413                         	
  414                         	xor4	.macro	a,b		;a=a^b (dword operation)
  415                         		op4	eor,eor,a,b
  416                         		.endm
  417                         	
  418                         	rol4_1	.macro	a
  419                         	tmpRot		.var $
  420                         		lda	a
  421                         		add	#80h		;set carry
  Sat Jun 13 11:05:07 1998                                                                                               Page    9

        Twofish for 6805
        Author: Doug Whiting, Hi/fn, May 1998

  422                         		rol	a+1
  423                         		rol	a+2
  424                         		rol	a+3
  425                         		rol	a
  426                         	tmpRot		.var $-tmpRot
  427                         	rotByteCnt	.var rotByteCnt+tmpRot
  428                         		.endm
  429                         	
  430                         	ror4_1	.macro	a
  431                         	tmpRot		.var $
  432                         		lda	a+3
  433                         		lsra			;start the carry bit
  434                         		ror	a+2
  435                         		ror	a+1
  436                         		ror	a
  437                         		ror	a+3
  438                         	tmpRot		.var $-tmpRot
  439                         	rotByteCnt	.var rotByteCnt+tmpRot
  440                         		.endm
  441                         	
  442                         	;----------------------------------------------------------------
  443                         	; round xor function
  444                         	;
  445                         	RoundXor .macro
  446                         	  .if UNROLL_ROUND
  447                         		xor4	Text+8 ,t0
  448                         		xor4	Text+12,t1
  449                         	  .else
  450                         		jsr	rXor
  451                         	  .endif
  452                         	.endm
  453                         	
  454         [01]            	  .ife UNROLL_ROUND 
  455                         	rXor:	xor4	Text+8 ,t0
  456                         		xor4	Text+12,t1
  457                         		rts
  458         [00]            	  .endif
  459                         	
  460                         	
  461                         	;----------------------------------------------------------------
  462                         	; computeSubkey: compute subkey values sk0,sk1 from 
  463                         	;
  464                         	;   Input:	round	=	subkey number
  465                         	;   Output:	sk0,sk1	=	subkeys
  466                         	;		round incremented by two
  467                         	;		modifies sPtr also
  468                         	;----------------------------------------------------------------
  469                         	;
  470  01C5                   	computeSubkey:
  471         [01]            	.if UNROLL_SUBKEY
  472  01C5                   		f32	round,0,0,sk0,K32e
  473         01C5            	tmpf32		.var $
  474                         		;--- 1st byte, first MDS column = 01 5B EF EF
  475  01C5                   		Sbox8	round+((0+0*0).AND.3),p0,p0,p1,K32e
  476         01C5            	tmpS8		.var $
  477         [02]            	  .if K32e.lt.4			;use X as 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -