	; Don't even think of reading this code
	; It was automatically generated by cast-586.pl
	; Which is a perl program used to generate the x86 assember for
	; any of ELF, a.out, COFF, Win32, ...
	; eric <eay@cryptsoft.com>
	; 
%ifdef __omf__
section	code	use32 class=code
%else
section	.text
%endif
extern	_CAST_S_table0
extern	_CAST_S_table1
extern	_CAST_S_table2
extern	_CAST_S_table3
global	_CAST_encrypt
_CAST_encrypt:
	; 
	push	ebp
	push	ebx
	mov	ebx,		DWORD [12+esp]
	mov	ebp,		DWORD [16+esp]
	push	esi
	push	edi
	; Load the 2 words
	mov	edi,		DWORD [ebx]
	mov	esi,		DWORD [4+ebx]
	; Get short key flag
	mov	eax,		DWORD [128+ebp]
	push	eax
	xor	eax,		eax
	; round 0
	mov	edx,		DWORD [ebp]
	mov	ecx,		DWORD [4+ebp]
	add	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	add	ecx,		ebx
	xor	edi,		ecx
	; round 1
	mov	edx,		DWORD [8+ebp]
	mov	ecx,		DWORD [12+ebp]
	xor	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	xor	ecx,		ebx
	xor	esi,		ecx
	; round 2
	mov	edx,		DWORD [16+ebp]
	mov	ecx,		DWORD [20+ebp]
	sub	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	sub	ecx,		ebx
	xor	edi,		ecx
	; round 3
	mov	edx,		DWORD [24+ebp]
	mov	ecx,		DWORD [28+ebp]
	add	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	add	ecx,		ebx
	xor	esi,		ecx
	; round 4
	mov	edx,		DWORD [32+ebp]
	mov	ecx,		DWORD [36+ebp]
	xor	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	xor	ecx,		ebx
	xor	edi,		ecx
	; round 5
	mov	edx,		DWORD [40+ebp]
	mov	ecx,		DWORD [44+ebp]
	sub	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	sub	ecx,		ebx
	xor	esi,		ecx
	; round 6
	mov	edx,		DWORD [48+ebp]
	mov	ecx,		DWORD [52+ebp]
	add	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	add	ecx,		ebx
	xor	edi,		ecx
	; round 7
	mov	edx,		DWORD [56+ebp]
	mov	ecx,		DWORD [60+ebp]
	xor	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	xor	ecx,		ebx
	xor	esi,		ecx
	; round 8
	mov	edx,		DWORD [64+ebp]
	mov	ecx,		DWORD [68+ebp]
	sub	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	sub	ecx,		ebx
	xor	edi,		ecx
	; round 9
	mov	edx,		DWORD [72+ebp]
	mov	ecx,		DWORD [76+ebp]
	add	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	add	ecx,		ebx
	xor	esi,		ecx
	; round 10
	mov	edx,		DWORD [80+ebp]
	mov	ecx,		DWORD [84+ebp]
	xor	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	xor	ecx,		ebx
	xor	edi,		ecx
	; round 11
	mov	edx,		DWORD [88+ebp]
	mov	ecx,		DWORD [92+ebp]
	sub	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	sub	ecx,		ebx
	xor	esi,		ecx
	; test short key flag
	pop	edx
	or	edx,		edx
	jnz NEAR	@L000cast_enc_done
	; round 12
	mov	edx,		DWORD [96+ebp]
	mov	ecx,		DWORD [100+ebp]
	add	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	add	ecx,		ebx
	xor	edi,		ecx
	; round 13
	mov	edx,		DWORD [104+ebp]
	mov	ecx,		DWORD [108+ebp]
	xor	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	xor	ecx,		ebx
	xor	esi,		ecx
	; round 14
	mov	edx,		DWORD [112+ebp]
	mov	ecx,		DWORD [116+ebp]
	sub	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	sub	ecx,		ebx
	xor	edi,		ecx
	; round 15
	mov	edx,		DWORD [120+ebp]
	mov	ecx,		DWORD [124+ebp]
	add	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	add	ecx,		ebx
	xor	esi,		ecx
@L000cast_enc_done:
	nop
	mov	eax,		DWORD [20+esp]
	mov	DWORD [4+eax],	edi
	mov	DWORD [eax],	esi
	pop	edi
	pop	esi
	pop	ebx
	pop	ebp
	ret
extern	_CAST_S_table0
extern	_CAST_S_table1
extern	_CAST_S_table2
extern	_CAST_S_table3
global	_CAST_decrypt
_CAST_decrypt:
	; 
	push	ebp
	push	ebx
	mov	ebx,		DWORD [12+esp]
	mov	ebp,		DWORD [16+esp]
	push	esi
	push	edi
	; Load the 2 words
	mov	edi,		DWORD [ebx]
	mov	esi,		DWORD [4+ebx]
	; Get short key flag
	mov	eax,		DWORD [128+ebp]
	or	eax,		eax
	jnz NEAR	@L001cast_dec_skip
	xor	eax,		eax
	; round 15
	mov	edx,		DWORD [120+ebp]
	mov	ecx,		DWORD [124+ebp]
	add	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	add	ecx,		ebx
	xor	edi,		ecx
	; round 14
	mov	edx,		DWORD [112+ebp]
	mov	ecx,		DWORD [116+ebp]
	sub	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	sub	ecx,		ebx
	xor	esi,		ecx
	; round 13
	mov	edx,		DWORD [104+ebp]
	mov	ecx,		DWORD [108+ebp]
	xor	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	xor	ecx,		ebx
	xor	edi,		ecx
	; round 12
	mov	edx,		DWORD [96+ebp]
	mov	ecx,		DWORD [100+ebp]
	add	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	add	ecx,		ebx
	xor	esi,		ecx
@L001cast_dec_skip:
	; round 11
	mov	edx,		DWORD [88+ebp]
	mov	ecx,		DWORD [92+ebp]
	sub	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	sub	ecx,		ebx
	xor	edi,		ecx
	; round 10
	mov	edx,		DWORD [80+ebp]
	mov	ecx,		DWORD [84+ebp]
	xor	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	xor	ecx,		ebx
	xor	esi,		ecx
	; round 9
	mov	edx,		DWORD [72+ebp]
	mov	ecx,		DWORD [76+ebp]
	add	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	add	ecx,		ebx
	xor	edi,		ecx
	; round 8
	mov	edx,		DWORD [64+ebp]
	mov	ecx,		DWORD [68+ebp]
	sub	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	sub	ecx,		ebx
	xor	esi,		ecx
	; round 7
	mov	edx,		DWORD [56+ebp]
	mov	ecx,		DWORD [60+ebp]
	xor	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	xor	ecx,		ebx
	xor	edi,		ecx
	; round 6
	mov	edx,		DWORD [48+ebp]
	mov	ecx,		DWORD [52+ebp]
	add	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	add	ecx,		ebx
	xor	esi,		ecx
	; round 5
	mov	edx,		DWORD [40+ebp]
	mov	ecx,		DWORD [44+ebp]
	sub	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	sub	ecx,		ebx
	xor	edi,		ecx
	; round 4
	mov	edx,		DWORD [32+ebp]
	mov	ecx,		DWORD [36+ebp]
	xor	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	xor	ecx,		ebx
	xor	esi,		ecx
	; round 3
	mov	edx,		DWORD [24+ebp]
	mov	ecx,		DWORD [28+ebp]
	add	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	add	ecx,		ebx
	xor	edi,		ecx
	; round 2
	mov	edx,		DWORD [16+ebp]
	mov	ecx,		DWORD [20+ebp]
	sub	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	sub	ecx,		ebx
	xor	esi,		ecx
	; round 1
	mov	edx,		DWORD [8+ebp]
	mov	ecx,		DWORD [12+ebp]
	xor	edx,		esi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	add	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	xor	ecx,		ebx
	xor	edi,		ecx
	; round 0
	mov	edx,		DWORD [ebp]
	mov	ecx,		DWORD [4+ebp]
	add	edx,		edi
	rol	edx,		cl
	mov	ebx,		edx
	xor	ecx,		ecx
	mov	cl,		dh
	and	ebx,		255
	shr	edx,		16
	xor	eax,		eax
	mov	al,		dh
	and	edx,		255
	mov	ecx,		DWORD [_CAST_S_table0+ecx*4]
	mov	ebx,		DWORD [_CAST_S_table1+ebx*4]
	xor	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table2+eax*4]
	sub	ecx,		ebx
	mov	ebx,		DWORD [_CAST_S_table3+edx*4]
	add	ecx,		ebx
	xor	esi,		ecx
	nop
	mov	eax,		DWORD [20+esp]
	mov	DWORD [4+eax],	edi
	mov	DWORD [eax],	esi
	pop	edi
	pop	esi
	pop	ebx
	pop	ebp
	ret
global	_CAST_cbc_encrypt
_CAST_cbc_encrypt:
	; 
	push	ebp
	push	ebx
	push	esi
	push	edi
	mov	ebp,		DWORD [28+esp]
	; getting iv ptr from parameter 4
	mov	ebx,		DWORD [36+esp]
	mov	esi,		DWORD [ebx]
	mov	edi,		DWORD [4+ebx]
	push	edi
	push	esi
	push	edi
	push	esi
	mov	ebx,		esp
	mov	esi,		DWORD [36+esp]
	mov	edi,		DWORD [40+esp]
	; getting encrypt flag from parameter 5
	mov	ecx,		DWORD [56+esp]
	; get and push parameter 3
	mov	eax,		DWORD [48+esp]
	push	eax
	push	ebx
	cmp	ecx,		0
	jz NEAR	@L002decrypt
	and	ebp,		4294967288
	mov	eax,		DWORD [8+esp]
	mov	ebx,		DWORD [12+esp]
	jz NEAR	@L003encrypt_finish
@L004encrypt_loop:
	mov	ecx,		DWORD [esi]
	mov	edx,		DWORD [4+esi]
	xor	eax,		ecx
	xor	ebx,		edx
	bswap	eax
	bswap	ebx
	mov	DWORD [8+esp],	eax
	mov	DWORD [12+esp],	ebx
	call	_CAST_encrypt
	mov	eax,		DWORD [8+esp]
	mov	ebx,		DWORD [12+esp]
	bswap	eax
	bswap	ebx
	mov	DWORD [edi],	eax
	mov	DWORD [4+edi],	ebx
	add	esi,		8
	add	edi,		8
	sub	ebp,		8
	jnz NEAR	@L004encrypt_loop
@L003encrypt_finish:
	mov	ebp,		DWORD [52+esp]
	and	ebp,		7
	jz NEAR	@L005finish
	call	@L006PIC_point
@L006PIC_point:
	pop	edx
	lea	ecx,		[(@L007cbc_enc_jmp_table-@L006PIC_point)+edx]
	mov	ebp,		DWORD [ebp*4+ecx]
	add	ebp,		edx
	xor	ecx,		ecx
	xor	edx,		edx
	jmp	ebp
@L008ej7:
	xor	edx,		edx
	mov	dh,		BYTE [6+esi]
	shl	edx,		8
@L009ej6:
	mov	dh,		BYTE [5+esi]
@L010ej5:
	mov	dl,		BYTE [4+esi]
@L011ej4:
	mov	ecx,		DWORD [esi]
	jmp	@L012ejend
@L013ej3:
	mov	ch,		BYTE [2+esi]
	xor	ecx,		ecx
	shl	ecx,		8
@L014ej2:
	mov	ch,		BYTE [1+esi]
@L015ej1:
	mov	cl,		BYTE [esi]
@L012ejend:
	xor	eax,		ecx
	xor	ebx,		edx
	bswap	eax
	bswap	ebx
	mov	DWORD [8+esp],	eax
	mov	DWORD [12+esp],	ebx
	call	_CAST_encrypt
	mov	eax,		DWORD [8+esp]
	mov	ebx,		DWORD [12+esp]
	bswap	eax
	bswap	ebx
	mov	DWORD [edi],	eax
	mov	DWORD [4+edi],	ebx
	jmp	@L005finish
@L002decrypt:
	and	ebp,		4294967288
	mov	eax,		DWORD [16+esp]
	mov	ebx,		DWORD [20+esp]
	jz NEAR	@L016decrypt_finish
@L017decrypt_loop:
	mov	eax,		DWORD [esi]
	mov	ebx,		DWORD [4+esi]
	bswap	eax
	bswap	ebx
	mov	DWORD [8+esp],	eax
	mov	DWORD [12+esp],	ebx
	call	_CAST_decrypt
	mov	eax,		DWORD [8+esp]
	mov	ebx,		DWORD [12+esp]
	bswap	eax
	bswap	ebx
	mov	ecx,		DWORD [16+esp]
	mov	edx,		DWORD [20+esp]
	xor	ecx,		eax
	xor	edx,		ebx
	mov	eax,		DWORD [esi]
	mov	ebx,		DWORD [4+esi]
	mov	DWORD [edi],	ecx
	mov	DWORD [4+edi],	edx
	mov	DWORD [16+esp],	eax
	mov	DWORD [20+esp],	ebx
	add	esi,		8
	add	edi,		8
	sub	ebp,		8
	jnz NEAR	@L017decrypt_loop
@L016decrypt_finish:
	mov	ebp,		DWORD [52+esp]
	and	ebp,		7
	jz NEAR	@L005finish
	mov	eax,		DWORD [esi]
	mov	ebx,		DWORD [4+esi]
	bswap	eax
	bswap	ebx
	mov	DWORD [8+esp],	eax
	mov	DWORD [12+esp],	ebx
	call	_CAST_decrypt
	mov	eax,		DWORD [8+esp]
	mov	ebx,		DWORD [12+esp]
	bswap	eax
	bswap	ebx
	mov	ecx,		DWORD [16+esp]
	mov	edx,		DWORD [20+esp]
	xor	ecx,		eax
	xor	edx,		ebx
	mov	eax,		DWORD [esi]
	mov	ebx,		DWORD [4+esi]
@L018dj7:
	ror	edx,		16
	mov	BYTE [6+edi],	dl
	shr	edx,		16
@L019dj6:
	mov	BYTE [5+edi],	dh
@L020dj5:
	mov	BYTE [4+edi],	dl
@L021dj4:
	mov	DWORD [edi],	ecx
	jmp	@L022djend
@L023dj3:
	ror	ecx,		16
	mov	BYTE [2+edi],	cl
	shl	ecx,		16
@L024dj2:
	mov	BYTE [1+esi],	ch
@L025dj1:
	mov	BYTE [esi],	cl
@L022djend:
	jmp	@L005finish
@L005finish:
	mov	ecx,		DWORD [60+esp]
	add	esp,		24
	mov	DWORD [ecx],	eax
	mov	DWORD [4+ecx],	ebx
	pop	edi
	pop	esi
	pop	ebx
	pop	ebp
	ret
align	64
@L007cbc_enc_jmp_table:
DD	0
DD	@L015ej1-@L006PIC_point
DD	@L014ej2-@L006PIC_point
DD	@L013ej3-@L006PIC_point
DD	@L011ej4-@L006PIC_point
DD	@L010ej5-@L006PIC_point
DD	@L009ej6-@L006PIC_point
DD	@L008ej7-@L006PIC_point
align	64
