64位汇编语言之RSA加密算法

64位汇编语言之RSA加密算法RSA算法广泛地应用在计算机行业:应用软件使用数字签名防止软件被篡改那怕只修改一个bit也会被检测到软件有没有被病毒感染查看数字证书倒是一个好方

RSA算法广泛地应用在计算机行业:应用软件使用数字签名防止软件被篡改那怕只修改一个bit也会被检测到

64位汇编语言之RSA加密算法

软件有没有被病毒感染查看数字证书倒是一个好方法

windows驱动程序必须要数字签名才能正常运行,商业软件VMP(VMProtect)使用RSA算法来保护软件的有效使用权限

64位汇编语言之RSA加密算法

VMP 保护软件不被逆向跟踪,使付费软件开发者把更多精力放在产品功能上。

VMP保护的代码分析起来让人抓狂,整个代码会被压缩存放,运行时现场解压,正常的API调用会被隐藏,正常的IF ELSE 分支给你用虚拟代码膨胀到几十万行代码…….本人也是研究它RSA加密运算的简便方法时在虚拟代码中迷失了。。。。。.扯得有点远。以下代码参考了它的方法。

视频加载中…

option casemap:none
OPTION DOTNAME

include rsa_64.inc

.code

ASCII2HEX proc uses rbx rsi rdi pret_buffer:qword,size_ret_buffer:qword,pascii_buffer:qword,size_ascii_buffer:qword
	
	
		
		mov rbx,size_ascii_buffer
		.if rbx { rsa_n_length*2
		
			mov rax,-1
			ret
		.endif
	
		mov rbx,size_ret_buffer
		.if rbx { rsa_n_length
		
			mov rax,-1
			ret
		.endif
	
	
		mov rcx,size_ascii_buffer
		mov rsi,pascii_buffer
		
		mov rdx,size_ret_buffer
		mov rdi,pret_buffer
				
		.while sqword ptr rcx } 0 && sqword ptr rdx } 0
			and rax,0
			and rbx,0
					
			mov al, byte ptr [rsi]
					
			.if al }= "0" && al {= "9"
						
				sub al,"0"
						
						
			.elseif al }= "A" && al {= "F"
				sub al,"0"
				sub al,7
			.elseif al }= "a" && al {= "f"	
						
				sub al,"0"
				sub al,27h	
			.elseif al == 0
						
						
			;	invoke MessageBox,0,addr compcheck1,0,MB_OK
			;	mov rax,-1
			;	ret		
			.else
				mov rax,-1
				ret	
			.endif
					
					
			dec rcx
			
			inc rsi
			mov bl, byte ptr [rsi]
					
			.if bl }= "0" && bl {= "9"
						
				sub bl,"0"
						
						
			.elseif bl }= "A" && bl {= "F"
				sub bl,"0"
				sub bl,7
			.elseif bl }= "a" && bl {= "f"	
						
				sub bl,"0"
				sub bl,27h	
			.elseif bl == 0
				
						
			.else
				mov rax,-1
				ret	
			.endif
			shl al,4
			or al,bl
			cld
			stosb 
					
					
			
			dec rcx
			dec rdx
			inc rsi
		.endw
			
	ret

ASCII2HEX endp

HEX2ASCII proc uses rbx rsi rdi pret_buffer:qword,size_ret_buffer:qword,phex_buffer:qword,size_hex_buffer:qword	;16进制转ascii
	
	
	mov rsi,phex_buffer
	
	mov rdi,pret_buffer
	mov rbx,0
	mov rdx,0
	mov rax,0
	
	mov rcx,size_hex_buffer
	
	.if rcx { rsa_n_length
		mov rax,-1
		ret
	.endif
	
	
	mov rcx,size_ret_buffer
	.if rcx { rsa_n_length
		mov rax,-1
		ret
	.endif
	
	mov rcx,size_hex_buffer
	mov rdx,size_ret_buffer
	.while sqword ptr rcx } 0 && sqword ptr rdx } 0
		
		
		
		mov al,[rsi]
		
		shr al,4
		.if al }=0 && al {= 9
			add al,30h
		.elseif al }=0ah && al {= 0fh
			add al,37h
		.else
			mov rax,-1
		;	int 3
		;	ret	
		.endif
		cld
		stosb
		
		
		mov al,[rsi]
		and al,0fh
		.if al }=0 && al {= 9
			add al,30h
		.elseif al }=0ah && al {= 0fh
			add al,37h
		.else
			mov rax,-1
		;	int 3
		;	ret	
		.endif
		
		cld
		stosb
		
		
		inc rsi
		
		dec rcx
		dec rdx
		dec rdx
	.endw
	
	;mov dword ptr [rdi],0
	
	
	ret

HEX2ASCII endp
rsa_calmod proc uses rbx rsi rdi r11 r12 r13 r14 r15 prsa_n_buffer_and_value:qword,_prsacalbuffer_for_mid:qword,count:qword
	
	LOCAL @addflags_craay:qword
	
	
		mov r12,prsa_n_buffer_and_value
		lea r12,[r12+rsa_n_length_8*63]
		lea r12,[r12+rsa_n_length_8-8]
		mov rbx,rsa_n_length_8*64
	
		.while rbx {} 0
			mov rdi,r12
			mov  rsi,_prsacalbuffer_for_mid
			add rsi,rsa_n_length_8-8
		
			
			mov ecx,rsa_n_length_8/8
			std
			repz cmpsq
		
		
			.if ~(CARRY?) && ~ZERO?	;大于就减
			
				mov r15,0
				mov  @addflags_craay,0
				mov  rdi,_prsacalbuffer_for_mid
				mov rsi,r12
				sub rsi,rsa_n_length;定位到头部
			
				.while r15 {} rsa_n_length_8 
					shr @addflags_craay,1
					
					mov rax,[rsi+r15]
					
					sbb [rdi+r15],rax
					setc byte ptr @addflags_craay	;把进位保存
					add r15,8
				.endw
				
			
			.endif
		
			sub rbx,rsa_n_length_8 
			sub r12,rsa_n_length_8 ;指向上一个中间数据的尾部的8字节
		.endw
	
		
		.if count } 8
		
			nop
			mov  rsi,_prsacalbuffer_for_mid
			
			lea rsi,[rsi+rsa_n_length_8-8-8]
		
			mov rdi,_prsacalbuffer_for_mid
			lea rdi,[rdi+rsa_n_length_8-8]
			mov rcx,rsa_n_length/8	;少移动8字节,小心内存泄漏
			std 
			rep movsq
	
			mov rsi,_prsacalbuffer_for_mid
			mov qword ptr [rsi],0;相当于左移64位 最低位补0
			
		;	invoke rsa_calmod,prsa_n_buffer_and_value,_prsacalbuffer_for_mid,0
		
			mov r12,prsa_n_buffer_and_value
			lea r12,[r12+rsa_n_length_8*63]
			lea r12,[r12+rsa_n_length_8-8]
			mov rbx,rsa_n_length_8*64
	
			.while rbx {} 0
				mov rdi,r12
				mov  rsi,_prsacalbuffer_for_mid
				add rsi,rsa_n_length_8-8
		
				
				mov ecx,rsa_n_length_8/8
				std
				repz cmpsq
		
		
				.if ~(CARRY?) && ~ZERO?	;大于就减
			
					mov r15,0
					mov  @addflags_craay,0
					mov  rdi,_prsacalbuffer_for_mid
					mov rsi,r12
					sub rsi,rsa_n_length;定位到头部
			
					.while r15 {} rsa_n_length_8 
						shr @addflags_craay,1
					
						mov rax,[rsi+r15]
					
						sbb [rdi+r15],rax
						setc byte ptr @addflags_craay	;把进位保存
						add r15,8
					.endw
				
			
				.endif
		
				sub rbx,rsa_n_length_8 
				sub r12,rsa_n_length_8 ;指向上一个中间数据的尾部的8字节
			.endw
	
		
		.endif
		
	ret

rsa_calmod endp

rsamul_to_mod proc	uses rbx rsi rdi r11 r12 r13 r14 r15 preturn_rsa:qword, pmingma:qword,pmingma1:qword,_prsa_n_buffer_and_value:qword		; pmingma*pmingma1 mod prsa_n_buffer_and_value
	
	LOCAL @addflags_craay:qword ;每次相加产生的进位
	
	LOCAL @flags_c_mod:qword
	
	LOCAL @count:qword
	
	mov rax,0
	mov  rdi,prsacalbuffer_for_mid
	mov rcx,(rsa_n_length_8 )/8
	cld
	rep stosq
	
	
	mov rcx,(rsa_n_length_8 )/8
	mov rsi,pmingma
	mov rdi,pmidvalue ;被乘数的中间值 
	cld 
	rep movsq
	
	mov rsi,pmidvalue
	
			
	mov ebx,63	;64位系统,单次就可以处理64位长度的数据:我们把pmingma值的总共左移63次的结果全部保存下来,用来加快求余的过程
	.while ebx {}0
			
		mov ecx,rsa_n_length_8  ;字节长度	;每次加密的数据长度是80h字节,我们在内存中按88h字节处理,移位后的进位项需要占用一些内存,最多占用64位
		
		mov  @flags_c_mod,0
		.while ecx {} 0	;80h个数据整体左移一位的结果,*2
			cld	
			shr @flags_c_mod,1
			lodsq;	mov rax,qword ptr [rsi]
			rcl rax,1
			setc byte ptr @flags_c_mod
			stosq;	mov qword ptr [rdi],rax
			sub rcx,8
		.endw	
		dec ebx
	.endw
	
		
	mov rsi,pmingma1	
	lea rsi,[rsi+rsa_n_length_8 ];定位到最高位 
	sub rsi,8 ;减去8字节 开始获取最高位的8字节数据
	sub rdi,8	
	mov r12,rdi	;pmidvalue 最高位
	
	mov r13,prsacalbuffer_for_mid
	mov r14,_prsa_n_buffer_and_value
	
	mov ebx,rsa_n_length_8 	
	.while ebx {} 0
		std	;从高位向低位获取
		lodsq
			
		mov r11,rax
		mov r14,64
		.while r14{}0
			shl r11,1	;从最高位开始测试
			
			.if CARRY?
				mov r15,0
				mov  @addflags_craay,0
				sub r12,rsa_n_length;定位到头部 会影响cf标志
				.while r15 {} rsa_n_length_8 
					
						
					shr @addflags_craay,1
					mov rax,[r12+r15]
					
					adc [r13+r15],rax
					setc byte ptr @addflags_craay	;把进位保存
					add r15,8
				.endw
					
				add r12,rsa_n_length;重新定位到尾部
				
			.endif
			sub r12,rsa_n_length_8 ;指向上一个中间数据的尾部的8字节
			dec r14
		.endw
		invoke rsa_calmod,_prsa_n_buffer_and_value,prsacalbuffer_for_mid,rbx
			
		sub ebx,8
		mov r12,rdi
	.endw
	mov rsi,prsacalbuffer_for_mid
	
	mov rdi,preturn_rsa
	mov rcx,rsa_n_length/8
	cld
	rep movsq	

	ret

rsamul_to_mod endp

rsaenc proc uses rsi rdi rbx r11 r12 r13 r14 r15 preturn_rsa:qword,prsa_n_value:qword,prsa_e_value:qword,pmingma:qword
									;加密
	LOCAL @flags_c_mod:qword
	
			.if preturn_rsa == 0
				mov rax,-1
				ret
			.endif 
			.if prsa_n_value == 0
				mov rax,-1
				ret
			.endif 
			.if prsa_e_value == 0
				mov rax,-1
				ret
			.endif 
			.if pmingma == 0
				mov rax,-1
				ret
			.endif 
			
			
			mov rax,0
			mov rcx,(rsa_n_length_8 )*65/8
			mov rdi,prsa_n_buffer_for_value
			cld
			rep stosq	;缓冲清0
			
			mov rax,0
			mov rcx,(rsa_n_length_8 )*65/8
			mov rdi,pmidvalue
			cld
			rep stosq
			
			mov rax,0
			mov rcx,(rsa_n_length_8 )/8
			lea rdi,@mingma
			cld
			rep stosq
	
			mov rax,0
			mov rcx,(rsa_n_length_8 )/8
			lea rdi,@mingma1
			cld
			rep stosq
	
			mov rsi,pmingma
			lea rdi, @mingma
			mov ecx,rsa_n_length/8
			cld
			rep movsq
			
			mov rsi,prsa_n_value
			mov rdi,prsa_n_buffer_for_value	;
			mov ecx,rsa_n_length/8
			cld
			rep movsq
			add rdi,8	
			
			mov rsi,prsa_n_buffer_for_value	
			
			mov ebx,63	;64位系统,单次就可以处理64位长度的数据:我们把n值的总共左移63次的结果全部保存下来,用来加快求余的过程 
					;;64个80h+8字节的缓冲区,存放x*2^1 到x*2^63 的数据 (2x 4x 8x 16x 32x 64x 128x 256x ....)
			.while ebx {}0
			
				mov ecx,rsa_n_length_8  ;字节长度	;每次加密的数据长度是80h字节,我们在内存中按88h字节处理,移位后的进位项需要占用一些内存,最多占用64位
				mov edx,0
			
				mov  @flags_c_mod,0
				.while ecx {} 0	;80h个数据整体左移一位的结果,*2
					cld
					shr @flags_c_mod,1
					lodsq;	mov rax,qword ptr [rsi]
					rcl rax,1
					setc byte ptr @flags_c_mod
					cld
					stosq;	mov qword ptr [rdi],rax
					sub rcx,8
				.endw	
				dec ebx
			.endw
	
			and @flags_c_mod,0
			or qword ptr @mingma1,1	;第一次是1
			mov rsi,prsa_e_value	
			lea rsi,[rsi+rsa_n_length];定位到最高位 
			sub rsi,8 ;减去8字节 开始获取最高位的8字节数据
			
			mov ebx,rsa_n_length
			.while ebx {} 0
				std	;从高位向低位获取
				lodsq
				mov r12,rax
				
				mov r13,64	;每次处理64位数据
				.while sqword ptr r13 }0
					
					shl r12,1;从最高位开始测试
			
					setc byte ptr @flags_c_mod	;保存最高位的值
				
					
					invoke rsamul_to_mod,preturn_rsa,addr @mingma1,addr @mingma1,prsa_n_buffer_for_value	
					
					push rsi
					
					mov rsi, preturn_rsa
					lea rdi,  @mingma1
				
					mov ecx,rsa_n_length/8
			
					cld 
					rep movsq
					pop rsi
					shr  dword  ptr @flags_c_mod,1	;
					.if CARRY?	;最高位的值如果为真
					
						invoke rsamul_to_mod,preturn_rsa,addr @mingma,addr @mingma1,prsa_n_buffer_for_value
						
						push rsi
						mov rsi, preturn_rsa
						lea rdi,  @mingma1
				
						mov ecx,rsa_n_length/8
			
						cld 
						rep movsq
						
						pop rsi
						
						
						
					.endif
					dec r13
				
				.endw
				sub ebx,8
			.endw
			
			;invoke rsa_calmod,prsa_n_buffer_for_value,preturn_rsa,0
	ret

rsaenc endp	

WinMain proc  uses rbx rsi rdi r11 r12 r13 r14 r15  hInst:qword,hPrevInst:qword,CmdLine:qword,CmdShow:qword
	LOCAL	wc:WNDCLASSEX
	LOCAL	msg:MSG
	LOCAL @hInst:qword
	LOCAL @hPrevInst:qword
	LOCAL @CmdLine:qword
	LOCAL @CmdShow:qword
	LOCAL icex:INITCOMMONCONTROLSEX
	
	invoke GetModuleHandle,0

	mov    hInstance,rax
	invoke GetCommandLine
	mov	CommandLine,rax
	invoke RtlZeroMemory,addr wc,sizeof wc
	invoke InitCommonControls
	 mov icex.dwSize,sizeof INITCOMMONCONTROLSEX
   	 mov icex.dwICC,ICC_TAB_CLASSES
   	 invoke InitCommonControlsEx,addr icex
	
	
	
	mov		wc.cbSize,sizeof WNDCLASSEX
	mov		wc.style,CS_HREDRAW or CS_VREDRAW
	lea rax,WndProc
	mov		wc.lpfnWndProc,rax;offset WndProc
	mov		wc.cbClsExtra,NULL
	mov		wc.cbWndExtra,DLGWINDOWEXTRA
	push	hInstance
	pop		wc.hInstance
	mov		wc.hbrBackground,COLOR_BTNFACE+1
	mov		wc.lpszMenuName,IDM_MENU;0
	lea rax,ClassName
	mov		wc.lpszClassName,rax;offset ClassName
	invoke LoadIcon,NULL,IDI_APPLICATION
	mov		wc.hIcon,rax
	mov		wc.hIconSm,rax
	invoke LoadCursor,0,IDC_ARROW
	mov		wc.hCursor,rax
	invoke RegisterClassEx,addr wc
	
	invoke CreateDialogParam,hInstance,IDD_DIALOG,NULL,addr WndProc,NULL
	invoke ShowWindow,hWnd,SW_SHOWNORMAL
	
	
	invoke UpdateWindow,hWnd
	.while TRUE
		invoke GetMessage,addr msg,0,0,0
		 .if rax == 0
	  		.break
	  	.endif
		invoke TranslateMessage,addr msg
		invoke DispatchMessage,addr msg
	.endw
	
	invoke ExitProcess,0
	mov rax,msg.wParam
	
	
	ret


WinMain endp
WndProc proc uses rbx rsi rdi r11 r12 r13 r14 r15 hWin:HWND,uMsg:UINT64,wParam:WPARAM,lParam:LPARAM 
	LOCAL @heap:qword
	
	mov		rax,uMsg
	.if eax==WM_INITDIALOG
		push	hWin
		pop	hWnd
		
	;	invoke GetProcessHeap
	;	mov @heap,rax
	;	invoke HeapAlloc, @heap, HEAP_ZERO_MEMORY,rsa_n_length_8*68
		
		lea rax,midvalue
    		mov pmidvalue, rax
   	;	invoke HeapAlloc, @heap, HEAP_ZERO_MEMORY,rsa_n_length_8*68
   		lea rax,rsa_n_buffer_for_value
    		mov prsa_n_buffer_for_value,rax
    		
    		
	;	invoke HeapAlloc, @heap, HEAP_ZERO_MEMORY,rsa_n_length_8*8
		
		lea rax,rsacalbuffer_for_mid
		mov prsacalbuffer_for_mid,rax	;相乘的结果
		invoke SetDlgItemText,hWin,1001,addr rsa_n_ascii
		
		invoke SetDlgItemText,hWin,1002,addr rsa_e_ascii
		
		invoke SetDlgItemText,hWin,1003,addr rsa_d_ascii
		
		
	.elseif eax==WM_COMMAND
		mov		rax,wParam
		and		rax,0FFFFh
		.if rax==IDM_FILE_EXIT
			invoke SendMessage,hWin,WM_CLOSE,0,0
		.elseif rax==IDM_HELP_ABOUT
			invoke ShellAbout,hWin,addr AppName,addr AboutMsg,NULL
		.elseif rax==1007;服务端用e 值加密
			
		;	int  3
			
			invoke RtlZeroMemory,addr buffer_buffer,sizeof buffer_buffer
		
			invoke GetDlgItemText,hWin,1001,addr buffer_buffer,sizeof buffer_buffer
			.if rax { rsa_n_length*2
				mov rbx,rsa_n_length*2
				sub rbx,rax
				invoke RtlZeroMemory,addr buffer_buffer,sizeof buffer_buffer
				lea rsi,buffer_buffer
				add rsi,rbx
				invoke GetDlgItemText,hWin,1001,rsi,sizeof buffer_buffer
				invoke MessageBox,hWin,addr error_tips3,addr error_tips3,MB_OK
			.endif
			
			invoke ASCII2HEX,addr n_value_buffer,sizeof n_value_buffer,addr buffer_buffer,sizeof buffer_buffer
			;内存中的数据需要低位在前高位在后
			
		
			mov rcx,rsa_n_length
			mov rbx,rsa_n_length/2
			lea rsi,n_value_buffer
			mov rax,0
			.while rbx } 0
				
				
				mov dl,[rsi+rax]
				xchg [rsi+rcx-1],dl
				xchg [rsi+rax],dl
				
				
				inc rax
				dec rcx
				dec rbx
			.endw
		
			;内存中的数据需要低位在前高位在后
			
			invoke RtlZeroMemory,addr buffer_buffer,sizeof buffer_buffer
			invoke GetDlgItemText,hWin,1002,addr buffer_buffer,sizeof buffer_buffer
			
			.if rax { rsa_n_length*2
				mov rbx,rsa_n_length*2
				sub rbx,rax
				invoke RtlZeroMemory,addr buffer_buffer,sizeof buffer_buffer
				lea rsi,buffer_buffer
				add rsi,rbx
				invoke GetDlgItemText,hWin,1002,rsi,sizeof buffer_buffer
				invoke MessageBox,hWin,addr error_tips4,addr error_tips4,MB_OK
			
			.endif
			
			
			
		;	int 3
			invoke ASCII2HEX,addr e_value_buffer,sizeof e_value_buffer,addr buffer_buffer,sizeof buffer_buffer
			mov rcx,rsa_n_length
			mov rbx,rsa_n_length/2
			lea rsi,e_value_buffer
			mov rax,0
			.while rbx } 0
				
				
				mov dl,[rsi+rax]
				xchg [rsi+rcx-1],dl
				xchg [rsi+rax],dl
				
				
				inc rax
				dec rcx
				dec rbx
			.endw
		;	int 3
			invoke RtlZeroMemory,addr buffer_buffer,sizeof buffer_buffer
		
			invoke GetDlgItemText,hWin,1005,addr buffer_buffer,sizeof buffer_buffer
			
			invoke  RtlZeroMemory,addr mingma_buffer,sizeof mingma_buffer
			
			invoke ASCII2HEX,addr mingma_buffer,sizeof mingma_buffer,addr buffer_buffer,sizeof buffer_buffer
		
			lea rax,mingma_buffer
			
			
			invoke RtlZeroMemory,addr buffer_buffer,sizeof buffer_buffer
			
			
		;	lea rax,ffff
		;	lea rbx,gggg
		;	lea rcx,hhhh
		;	lea rdx,iiii
			
			
			
			invoke rsaenc,addr buffer_buffer,addr n_value_buffer,addr e_value_buffer,addr mingma_buffer
			
		;	invoke HEX2ASCII,addr mingma_buffer,80h*2,addr buffer_buffer,80h
			
			lea rsi,buffer_buffer
		;	int 3
		;	lea rsi,[rsi+sizeof buffer_buffer]
		;	mov qword ptr [rsi-8],0
			invoke SetDlgItemText,hWin,1004,addr buffer_buffer;addr error_tips;buffer_buffer;mingma_buffer;buffer_buffer
			invoke SetDlgItemText,hWin,1013,addr buffer_buffer;addr error_tips;buffer_buffer;mingma_buffer;buffer_buffer
			
		.elseif rax==1006;客户端用d 值加密3DH
			
		;	int 3
			invoke RtlZeroMemory,addr buffer_buffer,sizeof buffer_buffer
		
			invoke GetDlgItemText,hWin,1001,addr buffer_buffer,sizeof buffer_buffer
			.if rax { rsa_n_length*2
				mov rbx,rsa_n_length*2
				sub rbx,rax
				invoke RtlZeroMemory,addr buffer_buffer,sizeof buffer_buffer
				lea rsi,buffer_buffer
				add rsi,rbx
				invoke GetDlgItemText,hWin,1001,rsi,sizeof buffer_buffer
				invoke MessageBox,hWin,addr error_tips1,addr error_tips1,MB_OK
			.endif
			
			invoke ASCII2HEX,addr n_value_buffer,sizeof n_value_buffer,addr buffer_buffer,sizeof buffer_buffer
			;内存中的数据需要低位在前高位在后
			
		
			mov rcx,rsa_n_length
			mov rbx,rsa_n_length/2
			lea rsi,n_value_buffer
			mov rax,0
			.while rbx } 0
				
				
				mov dl,[rsi+rax]
				xchg [rsi+rcx-1],dl
				xchg [rsi+rax],dl
				
				
				inc rax
				dec rcx
				dec rbx
			.endw
			
		;	int 3
			
			invoke RtlZeroMemory,addr buffer_buffer,sizeof buffer_buffer
			invoke GetDlgItemText,hWin,1003,addr buffer_buffer,sizeof buffer_buffer
			
			.if rax { rsa_n_length*2
				mov rbx,rsa_n_length*2
				sub rbx,rax
				invoke RtlZeroMemory,addr buffer_buffer,sizeof buffer_buffer
				lea rsi,buffer_buffer
				add rsi,rbx
				invoke GetDlgItemText,hWin,1003,rsi,sizeof buffer_buffer
				;invoke MessageBox,hWin,addr error_tips2,addr error_tips2,MB_OK
			.endif
			
			
		
			invoke ASCII2HEX,addr d_value_buffer,sizeof d_value_buffer,addr buffer_buffer,sizeof buffer_buffer
			mov rcx,rsa_n_length
			mov rbx,rsa_n_length/2
			lea rsi,d_value_buffer
			mov rax,0
			.while rbx } 0
				
				
				mov dl,[rsi+rax]
				xchg [rsi+rcx-1],dl
				xchg [rsi+rax],dl
				
				
				inc rax
				dec rcx
				dec rbx
			.endw
		
			invoke RtlZeroMemory,addr mingma_buffer,sizeof mingma_buffer
			
			invoke GetDlgItemText,hWin,1004,addr mingma_buffer,sizeof mingma_buffer-1
			.if rax } rsa_n_length
				
			
			.endif
			
			invoke RtlZeroMemory,addr buffer_buffer,sizeof buffer_buffer
		;	int 3
			invoke rsaenc,addr buffer_buffer,addr n_value_buffer,addr d_value_buffer,addr mingma_buffer
			
			invoke HEX2ASCII,addr mingma_buffer,sizeof mingma_buffer,addr buffer_buffer,sizeof buffer_buffer
			
			
			invoke SetDlgItemText,hWin,1005,addr mingma_buffer
			
			
		
		.endif
;	.elseif eax==WM_SIZE
	.elseif eax==WM_CLOSE
		invoke DestroyWindow,hWin
	.elseif uMsg==WM_DESTROY
		invoke PostQuitMessage,NULL
	.else
		invoke DefWindowProc,hWin,uMsg,wParam,lParam
		ret
	.endif
	xor    rax,rax
	ret

WndProc endp
end

include win64.inc
include ksamd64.inc
include Macros\x64macros.inc
include Macros\x64calling.inc
include Macros\vasily.inc

include user32.inc
include kernel32.inc
include shell32.inc
include comctl32.inc
include comdlg32.inc


includelib user32.lib
includelib kernel32.lib
includelib shell32.lib
includelib comctl32.lib
includelib comdlg32.lib

WinMain				PROTO :QWORD,:QWORD,:QWORD,:QWORD
WndProc				PROTO :QWORD,:QWORD,:QWORD,:QWORD

IDD_DIALOG			equ 1000

IDM_MENU			equ 10000
IDM_FILE_EXIT		equ 10001
IDM_HELP_ABOUT		equ 10101
rsa_n_length equ 80h ;128字节
rsa_n_length_8 equ 88h


.const

ClassName			db 'DLGCLASS',0
AppName				db 'Dialog as main',0
AboutMsg			db 'MASM64 RadASM Dialog as main',13,10,'Copyright ? masm64 2001',0
			;;;;16进制ascii码 高位在前低位在后

			
			
			
			
			
align 8			




rsa_n_ascii	db "DBD088F58896B30ABC25F9405856F910FD4265D8BAC9A8009B550DADBD5F812C0CF8DF40C9"
		db "F4F279A8777302BBB5A56F75576CD6955CA4AA83B344ED99773DF6B2BEDB5DE2E5230B2BF4"
		db "E24F63E828FE828FDFDAF4B464E02B9B2462D5643C87EA12233E39025DA6B68A37AC460B0A8DFEEA053361F1095D19B98ABCC8822F29",0
		
		
		
align 8	



rsa_e_ascii	db "541A56BCB3150DCDF6AD04CFF4BCDA3100E58DB83DC7784B3B2370C75FE491B4BC05E0CD9637ED2A5525D6D05DE7A333A10EE12ABD1"
		db "D2437C58A2ABE49F090B904A458D09F75517A6C7EFF92C5597AECAD2D394D98D2196EB1E1922DB9230308E8277754EE221A9DB55C87"
		db "EADB9805B0B2CA2ACBC3BE88CEB3ADF80C4034F5BD",0

align 8		
rsa_d_ascii	db "10001",0,0,0,0,0
;rsa_d_ascii	db 	"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
		db	"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011",0	
		dq 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	dq	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	dq 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	dq	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	
error_tips1	db "11长度不在范围内",0	
error_tips2	db "22长度不在范围内",0	
error_tips3	db "33长度不在范围内",0	
error_tips4	db "44长度不在范围内",0	
	
.data?

hInstance			dq ?
CommandLine			dq ?
hWnd				dq ?
pmidvalue			dq ?
prsa_n_buffer_for_value		dq ?
prsacalbuffer_for_mid 		dq ?	;RSA 相乘时用到的中间值,功能类似于prsa_n_buffer_for_value
buffer_buffer 	dw rsa_n_length_8 dup (?);[88h]:word
aaaa		db rsa_n_length_8 dup (?)
n_value_buffer 	db rsa_n_length_8 dup (?); [88h]:byte

bbbb		db rsa_n_length_8 dup (?)
d_value_buffer 	db rsa_n_length_8 dup (?);[88h]:byte
cccc		db rsa_n_length_8 dup (?)
e_value_buffer 	db rsa_n_length_8 dup (?);[88h]:byte
dddd		db rsa_n_length_8 dup (?)
mingma_buffer 	dw rsa_n_length_8 dup (?);[88h]:word
eeee		db rsa_n_length_8 dup (?)


midvalue 		db  rsa_n_length_8*68 	dup (?)
ffff			db rsa_n_length_8 	dup (?)
rsa_n_buffer_for_value 	db  rsa_n_length_8*68 	dup (?)
gggg			db rsa_n_length_8 	dup (?)
rsacalbuffer_for_mid	db  rsa_n_length_8*8 	dup (?)
hhhh			db rsa_n_length_8 	dup (?)


@mingma		db rsa_n_length_8 dup (?)
iiii		db rsa_n_length_8 dup (?)
@mingma1	db rsa_n_length_8 dup (?)
jjjj		db rsa_n_length_8 dup (?)

今天的文章64位汇编语言之RSA加密算法分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/7894.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注