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

📄 rijndael.asm

📁 ASM 多种hash模块,汇编源码 MD2,4,5 SHA 等多种加密算法 还有其他赠送内容
💻 ASM
📖 第 1 页 / 共 3 页
字号:
			;-
			mov ebx,eax
			mov ecx,eax
			mov edx,eax
			shr eax,24
			shr ebx,16
			shr ecx,8
			and ebx,0FFh
			and ecx,0FFh
			and edx,0FFh
			mov eax,Te4[eax*4]
			mov ebx,Te4[ebx*4]
			mov ecx,Te4[ecx*4]
			mov edx,Te4[edx*4]
			and eax,0ff000000h
			and ebx,000ff0000h
			and ecx,00000ff00h
			and edx,0000000ffh
			xor eax,ebx
			xor eax,ecx
			xor eax,edx
			;-
			xor eax,[edi+4*4]
			mov [edi+12*4],eax
			xor eax,[edi+5*4]
			mov [edi+13*4],eax
			xor eax,[edi+6*4]
			mov [edi+14*4],eax
			xor eax,[edi+7*4]
			mov [edi+15*4],eax
			;-
			add edi,8*4
		.endw
		mov esi,14
	.endif
	mov ebx,esi
	mov rij_rounds,esi
	xor ecx,ecx
	shl ebx,2
	mov esi,offset rk_enc
	mov edi,offset rk_dec
	;  invert the order of the round keys: 
	.while ecx<=ebx
		mov eax,[esi+ecx*4]
		mov edx,[esi+ecx*4+4]
		mov [edi+ebx*4],eax
		mov [edi+ebx*4+4],edx
		mov eax,[esi+ecx*4+8]
		mov edx,[esi+ecx*4+12]
		mov [edi+ebx*4+8],eax
		mov [edi+ebx*4+12],edx
		mov eax,[esi+ebx*4]
		mov edx,[esi+ebx*4+4]
		mov [edi+ecx*4],eax
		mov [edi+ecx*4+4],edx
		mov eax,[esi+ebx*4+8]
		mov edx,[esi+ebx*4+12]
		mov [edi+ecx*4+8],eax
		mov [edi+ecx*4+12],edx
		add ecx,4
		sub ebx,4
	.endw
	mov esi,rij_rounds
	dec esi
	.while esi
		add edi,4*4
		MixColumn 0
		MixColumn 1
		MixColumn 2
		MixColumn 3
		dec esi
	.endw
	ret
RijndaelInit endp

rij_ROUND_enc macro _tx,_sx0,_sx1,_sx2,_sx3,_rki
		mov eax,_sx0
		mov ebx,_sx1
		mov ecx,_sx2
		mov edx,_sx3
		shr eax,24
		shr ebx,16
		shr ecx,8
		and ebx,0FFh
		and ecx,0FFh
		and edx,0FFh
		mov eax,Te0[eax*4]
		mov ebx,Te1[ebx*4]
		mov ecx,Te2[ecx*4]
		mov edx,Te3[edx*4]
		xor eax,ebx
		xor eax,ecx
		xor eax,edx
		xor eax,[edi+_rki*4]
		mov _tx,eax	
endm

rij_ROUND_enc_last macro _sx0,_sx1,_sx2,_sx3,_rki
		mov eax,_sx0
		mov ebx,_sx1
		mov ecx,_sx2
		mov edx,_sx3
		shr eax,24
		shr ebx,16
		shr ecx,8
		and ebx,0FFh
		and ecx,0FFh
		and edx,0FFh
		mov eax,Te4[eax*4]
		mov ebx,Te4[ebx*4]		
		mov ecx,Te4[ecx*4]
		mov edx,Te4[edx*4]
		and eax,0ff000000h
		and ebx,000ff0000h
		and ecx,00000ff00h
		and edx,0000000FFh
		xor eax,ebx
		xor eax,ecx
		xor eax,edx
		xor eax,[edi+_rki*4]
endm

align dword
RijndaelEncrypt proc uses esi edi ebx pBlockIn:DWORD,pBlockOut:DWORD
LOCAL  s0, s1, s2, s3, t0, t1, t2, t3
	mov esi,pBlockIn
	mov edi,offset rk_enc
	mov eax,[esi+0*4]
	mov ebx,[esi+1*4]
	mov ecx,[esi+2*4]
	mov edx,[esi+3*4]
	bswap eax
	bswap ebx
	bswap ecx
	bswap edx
	xor eax,[edi+0*4]
	xor ebx,[edi+1*4]
	xor ecx,[edi+2*4]
	xor edx,[edi+3*4]
	mov s0,eax
	mov s1,ebx
	mov s2,ecx
	mov s3,edx
	mov esi,rij_rounds
	shr esi,1
	.while 1
		rij_ROUND_enc t0, s0,s1,s2,s3, 4
		rij_ROUND_enc t1, s1,s2,s3,s0, 5
		rij_ROUND_enc t2, s2,s3,s0,s1, 6
		rij_ROUND_enc t3, s3,s0,s1,s2, 7
		add edi,8*4;rk+=8
		dec esi
		.break .if zero?
		rij_ROUND_enc s0, t0,t1,t2,t3, 0
		rij_ROUND_enc s1, t1,t2,t3,t0, 1
		rij_ROUND_enc s2, t2,t3,t0,t1, 2
		rij_ROUND_enc s3, t3,t0,t1,t2, 3
	.endw
	mov esi,pBlockOut
	rij_ROUND_enc_last t0,t1,t2,t3, 0
	bswap eax
	mov [esi+0*4],eax
	rij_ROUND_enc_last t1,t2,t3,t0, 1
	bswap eax
	mov [esi+1*4],eax
	rij_ROUND_enc_last t2,t3,t0,t1, 2
	bswap eax
	mov [esi+2*4],eax
	rij_ROUND_enc_last t3,t0,t1,t2, 3
	bswap eax
	mov [esi+3*4],eax
	ret
RijndaelEncrypt endp

rij_ROUND_dec macro _tx,_sx0,_sx1,_sx2,_sx3,_rki
		mov eax,_sx0
		mov ebx,_sx1
		mov ecx,_sx2
		mov edx,_sx3
		shr eax,24
		shr ebx,16
		shr ecx,8
		and ebx,0FFh
		and ecx,0FFh
		and edx,0FFh
		mov eax,Td0[eax*4]
		mov ebx,Td1[ebx*4]
		mov ecx,Td2[ecx*4]
		mov edx,Td3[edx*4]
		xor eax,ebx
		xor eax,ecx
		xor eax,edx
		xor eax,[edi+_rki*4]
		mov _tx,eax	
endm

rij_ROUND_dec_last macro _sx0,_sx1,_sx2,_sx3,_rki
		mov eax,_sx0
		mov ebx,_sx1
		mov ecx,_sx2
		mov edx,_sx3
		shr eax,24
		shr ebx,16
		shr ecx,8
		and ebx,0FFh
		and ecx,0FFh
		and edx,0FFh
		mov eax,Td4[eax*4]
		mov ebx,Td4[ebx*4]
		mov ecx,Td4[ecx*4]
		mov edx,Td4[edx*4]
		and eax,0ff000000h
		and ebx,000ff0000h
		and ecx,00000ff00h
		and edx,0000000FFh
		xor eax,ebx
		xor eax,ecx
		xor eax,edx
		xor eax,[edi+_rki*4]
endm

align dword
RijndaelDecrypt proc uses esi edi ebx pBlockIn:DWORD,pBlockOut:DWORD
LOCAL  s0, s1, s2, s3, t0, t1, t2, t3
	mov esi,pBlockIn
	mov edi,offset rk_dec
	mov eax,[esi+0*4]
	mov ebx,[esi+1*4]
	mov ecx,[esi+2*4]
	mov edx,[esi+3*4]
	bswap eax
	bswap ebx
	bswap ecx
	bswap edx
	xor eax,[edi+0*4]
	xor ebx,[edi+1*4]
	xor ecx,[edi+2*4]
	xor edx,[edi+3*4]
	mov s0,eax
	mov s1,ebx
	mov s2,ecx
	mov s3,edx
	mov esi,rij_rounds
	shr esi,1
	.while 1
		rij_ROUND_dec t0, s0,s3,s2,s1, 4
		rij_ROUND_dec t1, s1,s0,s3,s2, 5
		rij_ROUND_dec t2, s2,s1,s0,s3, 6
		rij_ROUND_dec t3, s3,s2,s1,s0, 7
		add edi,8*4;rk+=8
		dec esi
		.break .if zero?
		rij_ROUND_dec s0, t0,t3,t2,t1, 0
		rij_ROUND_dec s1, t1,t0,t3,t2, 1
		rij_ROUND_dec s2, t2,t1,t0,t3, 2
		rij_ROUND_dec s3, t3,t2,t1,t0, 3
	.endw
	mov esi,pBlockOut
	rij_ROUND_dec_last t0,t3,t2,t1, 0
	bswap eax
	mov [esi+0*4],eax
	rij_ROUND_dec_last t1,t0,t3,t2, 1
	bswap eax
	mov [esi+1*4],eax
	rij_ROUND_dec_last t2,t1,t0,t3, 2
	bswap eax
	mov [esi+2*4],eax
	rij_ROUND_dec_last t3,t2,t1,t0, 3
	bswap eax
	mov [esi+3*4],eax
	ret
RijndaelDecrypt endp


end

⌨️ 快捷键说明

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