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

📄 des_enc.m4

📁 开放的SSL工具
💻 M4
📖 第 1 页 / 共 3 页
字号:
	sll	out5, 29, temp1	or	local3, local4, $1	srl	out5, 3, $2	ifelse($5,2,{mov in4, in3})	ld	[out2+272], ip5	srl	$4, 4, local0	or	$2, temp1, $2	srl	$2, 1, temp1	xor	temp1, $1, temp1	and	temp1, ip5, temp1	xor	local0, $3, local0	sll	temp1, 1, temp2	xor	$1, temp1, $1	and	local0, ip1, local0	add	in2, -8, in2	sll	local0, 4, local7	xor	$3, local0, $3	ld	[out2+268], ip4	srl	$1, 8, temp1	xor	$2, temp2, $2	ld	[out2+260], ip2	srl	$3, 16, local0	xor	$4, local7, $4	xor	temp1, $2, temp1	xor	local0, $4, local0	and	temp1, ip4, temp1	and	local0, ip2, local0	sll	temp1, 8, temp2	xor	$2, temp1, $2	sll	local0, 16, local7	xor	$4, local0, $4	srl	$2, 2, temp1	xor	$1, temp2, $1	ld	[out2+264], temp2         ! ip3	srl	$4, 2, local0	xor	$3, local7, $3	xor	temp1, $1, temp1	xor	local0, $3, local0	and	temp1, temp2, temp1	and	local0, temp2, local0	sll	temp1, 2, temp2	xor	$1, temp1, $1	sll	local0, 2, local7	xor	$3, local0, $3	srl	$1, 16, temp1	xor	$2, temp2, $2	srl	$3, 8, local0	xor	$4, local7, $4	xor	temp1, $2, temp1	xor	local0, $4, local0	and	temp1, ip2, temp1	and	local0, ip4, local0	sll	temp1, 16, temp2	xor	$2, temp1, local4	sll	local0, 8, local7	xor	$4, local0, $4	srl	$4, 1, local0	xor	$3, local7, $3	srl	local4, 4, temp1	xor	local0, $3, local0	xor	$1, temp2, $1	and	local0, ip5, local0	sll	local0, 1, local7	xor	temp1, $1, temp1	xor	$3, local0, $3	xor	$4, local7, $4	sll	$3, 3, local5	and	temp1, ip1, temp1	sll	temp1, 4, temp2	xor	$1, temp1, $1	ifelse($5,1,{LDPTR	KS2, in4})	sll	$4, 3, local2	xor	local4, temp2, $2	! reload since used as temporar:	ld	[out2+280], out4          ! loop counter	srl	$3, 29, local0	ifelse($5,1,{add in4, 120, in4})	ifelse($5,1,{LDPTR	KS1, in3})	srl	$4, 29, local7	or	local0, local5, $4	or	local2, local7, $3})! {load_little_endian}!! parameter 1  address! parameter 2  destination left! parameter 3  destination right! parameter 4  temporar! parameter 5  labeldefine(load_little_endian, {! {load_little_endian}! $1 $2 $3 $4 $5 $6 $7 $8 $9	! first in memory to rightmost in register#ifdef OPENSSL_SYSNAME_ULTRASPARC	andcc	$1, 3, global0	bne,pn	%icc, $5	nop	lda	[$1] 0x88, $2	add	$1, 4, $4	ba,pt	%icc, $5a	lda	[$4] 0x88, $3#endif$5:	ldub	[$1+3], $2	ldub	[$1+2], $4	sll	$2, 8, $2	or	$2, $4, $2	ldub	[$1+1], $4	sll	$2, 8, $2	or	$2, $4, $2	ldub	[$1+0], $4	sll	$2, 8, $2	or	$2, $4, $2	ldub	[$1+3+4], $3	ldub	[$1+2+4], $4	sll	$3, 8, $3	or	$3, $4, $3	ldub	[$1+1+4], $4	sll	$3, 8, $3	or	$3, $4, $3	ldub	[$1+0+4], $4	sll	$3, 8, $3	or	$3, $4, $3$5a:})! {load_little_endian_inc}!! parameter 1  address! parameter 2  destination left! parameter 3  destination right! parameter 4  temporar! parameter 4  label!! adds 8 to addressdefine(load_little_endian_inc, {! {load_little_endian_inc}! $1 $2 $3 $4 $5 $6 $7 $8 $9	! first in memory to rightmost in register#ifdef OPENSSL_SYSNAME_ULTRASPARC	andcc	$1, 3, global0	bne,pn	%icc, $5	nop	lda	[$1] 0x88, $2	add	$1, 4, $1	lda	[$1] 0x88, $3	ba,pt	%icc, $5a	add	$1, 4, $1#endif$5:	ldub	[$1+3], $2	ldub	[$1+2], $4	sll	$2, 8, $2	or	$2, $4, $2	ldub	[$1+1], $4	sll	$2, 8, $2	or	$2, $4, $2	ldub	[$1+0], $4	sll	$2, 8, $2	or	$2, $4, $2	ldub	[$1+3+4], $3	add	$1, 8, $1	ldub	[$1+2+4-8], $4	sll	$3, 8, $3	or	$3, $4, $3	ldub	[$1+1+4-8], $4	sll	$3, 8, $3	or	$3, $4, $3	ldub	[$1+0+4-8], $4	sll	$3, 8, $3	or	$3, $4, $3$5a:})! {load_n_bytes}!! Loads 1 to 7 bytes little endian! Remaining bytes are zeroed.!! parameter 1  address! parameter 2  length! parameter 3  destination register left! parameter 4  destination register right! parameter 5  temp! parameter 6  temp2! parameter 7  label! parameter 8  return labeldefine(load_n_bytes, {! {load_n_bytes}! $1 $2 $5 $6 $7 $8 $7 $8 $9$7.0:	call	.+8	sll	$2, 2, $6	add	%o7,$7.jmp.table-$7.0,$5	add	$5, $6, $5	mov	0, $4	ld	[$5], $5	jmp	%o7+$5	mov	0, $3$7.7:	ldub	[$1+6], $5	sll	$5, 16, $5	or	$3, $5, $3$7.6:	ldub	[$1+5], $5	sll	$5, 8, $5	or	$3, $5, $3$7.5:	ldub	[$1+4], $5	or	$3, $5, $3$7.4:	ldub	[$1+3], $5	sll	$5, 24, $5	or	$4, $5, $4$7.3:	ldub	[$1+2], $5	sll	$5, 16, $5	or	$4, $5, $4$7.2:	ldub	[$1+1], $5	sll	$5, 8, $5	or	$4, $5, $4$7.1:	ldub	[$1+0], $5	ba	$8	or	$4, $5, $4	.align 4$7.jmp.table:	.word	0	.word	$7.1-$7.0	.word	$7.2-$7.0	.word	$7.3-$7.0	.word	$7.4-$7.0	.word	$7.5-$7.0	.word	$7.6-$7.0	.word	$7.7-$7.0})! {store_little_endian}!! parameter 1  address! parameter 2  source left! parameter 3  source right! parameter 4  temporardefine(store_little_endian, {! {store_little_endian}! $1 $2 $3 $4 $5 $6 $7 $8 $9	! rightmost in register to first in memory#ifdef OPENSSL_SYSNAME_ULTRASPARC	andcc	$1, 3, global0	bne,pn	%icc, $5	nop	sta	$2, [$1] 0x88	add	$1, 4, $4	ba,pt	%icc, $5a	sta	$3, [$4] 0x88#endif$5:	and	$2, 255, $4	stub	$4, [$1+0]	srl	$2, 8, $4	and	$4, 255, $4	stub	$4, [$1+1]	srl	$2, 16, $4	and	$4, 255, $4	stub	$4, [$1+2]	srl	$2, 24, $4	stub	$4, [$1+3]	and	$3, 255, $4	stub	$4, [$1+0+4]	srl	$3, 8, $4	and	$4, 255, $4	stub	$4, [$1+1+4]	srl	$3, 16, $4	and	$4, 255, $4	stub	$4, [$1+2+4]	srl	$3, 24, $4	stub	$4, [$1+3+4]$5a:})! {store_n_bytes}!! Stores 1 to 7 bytes little endian!! parameter 1  address! parameter 2  length! parameter 3  source register left! parameter 4  source register right! parameter 5  temp! parameter 6  temp2! parameter 7  label! parameter 8  return labeldefine(store_n_bytes, {! {store_n_bytes}! $1 $2 $5 $6 $7 $8 $7 $8 $9$7.0:	call	.+8	sll	$2, 2, $6	add	%o7,$7.jmp.table-$7.0,$5	add	$5, $6, $5	ld	[$5], $5	jmp	%o7+$5	nop$7.7:	srl	$3, 16, $5	and	$5, 0xff, $5	stub	$5, [$1+6]$7.6:	srl	$3, 8, $5	and	$5, 0xff, $5	stub	$5, [$1+5]$7.5:	and	$3, 0xff, $5	stub	$5, [$1+4]$7.4:	srl	$4, 24, $5	stub	$5, [$1+3]$7.3:	srl	$4, 16, $5	and	$5, 0xff, $5	stub	$5, [$1+2]$7.2:	srl	$4, 8, $5	and	$5, 0xff, $5	stub	$5, [$1+1]$7.1:	and	$4, 0xff, $5	ba	$8	stub	$5, [$1]	.align 4$7.jmp.table:	.word	0	.word	$7.1-$7.0	.word	$7.2-$7.0	.word	$7.3-$7.0	.word	$7.4-$7.0	.word	$7.5-$7.0	.word	$7.6-$7.0	.word	$7.7-$7.0})define(testvalue,{1})define(register_init, {! For test purposes:	sethi	%hi(testvalue), local0	or	local0, %lo(testvalue), local0	ifelse($1,{},{}, {mov	local0, $1})	ifelse($2,{},{}, {mov	local0, $2})	ifelse($3,{},{}, {mov	local0, $3})	ifelse($4,{},{}, {mov	local0, $4})	ifelse($5,{},{}, {mov	local0, $5})	ifelse($6,{},{}, {mov	local0, $6})	ifelse($7,{},{}, {mov	local0, $7})	ifelse($8,{},{}, {mov	local0, $8})	mov	local0, local1	mov	local0, local2	mov	local0, local3	mov	local0, local4	mov	local0, local5	mov	local0, local7	mov	local0, local6	mov	local0, out0	mov	local0, out1	mov	local0, out2	mov	local0, out3	mov	local0, out4	mov	local0, out5	mov	local0, global1	mov	local0, global2	mov	local0, global3	mov	local0, global4	mov	local0, global5}).section	".text"	.align 32.des_enc:	! key address in3	! loads key next encryption/decryption first round from [in4]	rounds_macro(in5, out5, 1, .des_enc.1, in3, in4, retl)	.align 32.des_dec:	! implemented with out5 as first parameter to avoid	! register exchange in ede modes	! key address in4	! loads key next encryption/decryption first round from [in3]	rounds_macro(out5, in5, -1, .des_dec.1, in4, in3, retl)! void DES_encrypt1(data, ks, enc)! *******************************	.align 32	.global DES_encrypt1	.type	 DES_encrypt1,#functionDES_encrypt1:	save	%sp, FRAME, %sp	call	.PIC.me.up	mov	.PIC.me.up-(.-4),out0	ld	[in0], in5                ! left	cmp	in2, 0                    ! enc#ifdef OPENSSL_SYSNAME_ULTRASPARC	be,pn	%icc, .encrypt.dec        ! enc/dec#else	be	.encrypt.dec#endif	ld	[in0+4], out5             ! right	! parameter 6  1/2 for include encryption/decryption	! parameter 7  1 for move in1 to in3	! parameter 8  1 for move in3 to in4, 2 for move in4 to in3	ip_macro(in5, out5, in5, out5, in3, 0, 1, 1)	rounds_macro(in5, out5, 1, .des_encrypt1.1, in3, in4) ! in4 not used	fp_macro(in5, out5, 1)            ! 1 for store to [in0]	ret	restore.encrypt.dec:	add	in1, 120, in3             ! use last subkey for first round	! parameter 6  1/2 for include encryption/decryption	! parameter 7  1 for move in1 to in3	! parameter 8  1 for move in3 to in4, 2 for move in4 to in3	ip_macro(in5, out5, out5, in5, in4, 2, 0, 1) ! include dec,  ks in4	fp_macro(out5, in5, 1)            ! 1 for store to [in0]	ret	restore.DES_encrypt1.end:	.size	 DES_encrypt1,.DES_encrypt1.end-DES_encrypt1! void DES_encrypt2(data, ks, enc)!*********************************	! encrypts/decrypts without initial/final permutation	.align 32	.global DES_encrypt2	.type	 DES_encrypt2,#functionDES_encrypt2:	save	%sp, FRAME, %sp	call	.PIC.me.up	mov	.PIC.me.up-(.-4),out0	! Set sbox address 1 to 6 and rotate halfs 3 left	! Errors caught by destest? Yes. Still? *NO*	!sethi	%hi(DES_SPtrans), global1 ! address sbox 1	!or	global1, %lo(DES_SPtrans), global1  ! sbox 1	add	global1, 256, global2     ! sbox 2	add	global1, 512, global3     ! sbox 3	ld	[in0], out5               ! right	add	global1, 768, global4     ! sbox 4	add	global1, 1024, global5    ! sbox 5	ld	[in0+4], in5              ! left	add	global1, 1280, local6     ! sbox 6	add	global1, 1792, out3       ! sbox 8	! rotate	sll	in5, 3, local5	mov	in1, in3                  ! key address to in3	sll	out5, 3, local7	srl	in5, 29, in5	srl	out5, 29, out5	add	in5, local5, in5	add	out5, local7, out5	cmp	in2, 0	! we use our own stackframe#ifdef OPENSSL_SYSNAME_ULTRASPARC	be,pn	%icc, .encrypt2.dec       ! decryption#else	be	.encrypt2.dec#endif	STPTR	in0, [%sp+BIAS+ARG0+0*ARGSZ]	ld	[in3], out0               ! key 7531 first round	mov	LOOPS, out4               ! loop counter	ld	[in3+4], out1             ! key 8642 first round	sethi	%hi(0x0000FC00), local5	call .des_enc	mov	in3, in4	! rotate	sll	in5, 29, in0	srl	in5, 3, in5	sll	out5, 29, in1	add	in5, in0, in5	srl	out5, 3, out5	LDPTR	[%sp+BIAS+ARG0+0*ARGSZ], in0	add	out5, in1, out5	st	in5, [in0]	st	out5, [in0+4]	ret	restore.encrypt2.dec:	add in3, 120, in4	ld	[in4], out0               ! key 7531 first round	mov	LOOPS, out4               ! loop counter	ld	[in4+4], out1             ! key 8642 first round	sethi	%hi(0x0000FC00), local5	mov	in5, local1               ! left expected in out5	mov	out5, in5	call .des_dec	mov	local1, out5

⌨️ 快捷键说明

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