Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Key handling functions for PPC AES implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2015 Markus Stockhausen <stockhausen@collogia.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <asm/ppc_asm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #ifdef __BIG_ENDIAN__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define LOAD_KEY(d, s, off) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 	lwz		d,off(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #define LOAD_KEY(d, s, off) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	li		r0,off; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	lwbrx		d,s,r0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define INITIALIZE_KEY \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	stwu		r1,-32(r1);	/* create stack frame		*/ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	stw		r14,8(r1);	/* save registers		*/ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	stw		r15,12(r1);					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	stw		r16,16(r1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define FINALIZE_KEY \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	lwz		r14,8(r1);	/* restore registers		*/ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	lwz		r15,12(r1);					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	lwz		r16,16(r1);					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	xor		r5,r5,r5;	/* clear sensitive data		*/ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	xor		r6,r6,r6;					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	xor		r7,r7,r7;					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	xor		r8,r8,r8;					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	xor		r9,r9,r9;					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	xor		r10,r10,r10;					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	xor		r11,r11,r11;					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	xor		r12,r12,r12;					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	addi		r1,r1,32;	/* cleanup stack		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define LS_BOX(r, t1, t2) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	lis		t2,PPC_AES_4K_ENCTAB@h;				   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	ori		t2,t2,PPC_AES_4K_ENCTAB@l;			   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	rlwimi		t2,r,4,20,27;					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	lbz		t1,8(t2);					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	rlwimi		r,t1,0,24,31;					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	rlwimi		t2,r,28,20,27;					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	lbz		t1,8(t2);					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	rlwimi		r,t1,8,16,23;					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	rlwimi		t2,r,20,20,27;					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	lbz		t1,8(t2);					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	rlwimi		r,t1,16,8,15;					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	rlwimi		t2,r,12,20,27;					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	lbz		t1,8(t2);					   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	rlwimi		r,t1,24,0,7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define GF8_MUL(out, in, t1, t2) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	lis t1,0x8080;			/* multiplication in GF8	*/ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	ori t1,t1,0x8080; 						   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	and t1,t1,in; 							   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	srwi t1,t1,7; 							   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	mulli t1,t1,0x1b; 						   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	lis t2,0x7f7f; 							   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	ori t2,t2,0x7f7f; 						   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	and t2,t2,in; 							   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	slwi t2,t2,1; 							   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	xor out,t1,t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * ppc_expand_key_128(u32 *key_enc, const u8 *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * Expand 128 bit key into 176 bytes encryption key. It consists of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * key itself plus 10 rounds with 16 bytes each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) _GLOBAL(ppc_expand_key_128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	INITIALIZE_KEY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	LOAD_KEY(r5,r4,0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	LOAD_KEY(r6,r4,4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	LOAD_KEY(r7,r4,8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	LOAD_KEY(r8,r4,12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	stw		r5,0(r3)	/* key[0..3] = input data	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	stw		r6,4(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	stw		r7,8(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	stw		r8,12(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	li		r16,10		/* 10 expansion rounds		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	lis		r0,0x0100	/* RCO(1)			*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) ppc_expand_128_loop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	addi		r3,r3,16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	mr		r14,r8		/* apply LS_BOX to 4th temp	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	rotlwi		r14,r14,8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	LS_BOX(r14, r15, r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	xor		r14,r14,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	xor		r5,r5,r14	/* xor next 4 keys		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	xor		r6,r6,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	xor		r7,r7,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	xor		r8,r8,r7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	stw		r5,0(r3)	/* store next 4 keys		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	stw		r6,4(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	stw		r7,8(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	stw		r8,12(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	GF8_MUL(r0, r0, r4, r14)	/* multiply RCO by 2 in GF	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	subi		r16,r16,1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	cmpwi		r16,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	bt		eq,ppc_expand_128_end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	b		ppc_expand_128_loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ppc_expand_128_end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	FINALIZE_KEY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	blr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * ppc_expand_key_192(u32 *key_enc, const u8 *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * Expand 192 bit key into 208 bytes encryption key. It consists of key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  * itself plus 12 rounds with 16 bytes each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) _GLOBAL(ppc_expand_key_192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	INITIALIZE_KEY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	LOAD_KEY(r5,r4,0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	LOAD_KEY(r6,r4,4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	LOAD_KEY(r7,r4,8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	LOAD_KEY(r8,r4,12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	LOAD_KEY(r9,r4,16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	LOAD_KEY(r10,r4,20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	stw		r5,0(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	stw		r6,4(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	stw		r7,8(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	stw		r8,12(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	stw		r9,16(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	stw		r10,20(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	li		r16,8		/* 8 expansion rounds		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	lis		r0,0x0100	/* RCO(1)			*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) ppc_expand_192_loop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	addi		r3,r3,24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	mr		r14,r10		/* apply LS_BOX to 6th temp	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	rotlwi		r14,r14,8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	LS_BOX(r14, r15, r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	xor		r14,r14,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	xor		r5,r5,r14	/* xor next 6 keys		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	xor		r6,r6,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	xor		r7,r7,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	xor		r8,r8,r7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	xor		r9,r9,r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	xor		r10,r10,r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	stw		r5,0(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	stw		r6,4(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	stw		r7,8(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	stw		r8,12(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	subi		r16,r16,1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	cmpwi		r16,0		/* last round early kick out	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	bt		eq,ppc_expand_192_end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	stw		r9,16(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	stw		r10,20(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	GF8_MUL(r0, r0, r4, r14)	/* multiply RCO GF8		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	b		ppc_expand_192_loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ppc_expand_192_end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	FINALIZE_KEY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	blr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * ppc_expand_key_256(u32 *key_enc, const u8 *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  * Expand 256 bit key into 240 bytes encryption key. It consists of key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  * itself plus 14 rounds with 16 bytes each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) _GLOBAL(ppc_expand_key_256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	INITIALIZE_KEY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	LOAD_KEY(r5,r4,0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	LOAD_KEY(r6,r4,4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	LOAD_KEY(r7,r4,8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	LOAD_KEY(r8,r4,12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	LOAD_KEY(r9,r4,16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	LOAD_KEY(r10,r4,20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	LOAD_KEY(r11,r4,24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	LOAD_KEY(r12,r4,28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	stw		r5,0(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	stw		r6,4(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	stw		r7,8(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	stw		r8,12(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	stw		r9,16(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	stw		r10,20(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	stw		r11,24(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	stw		r12,28(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	li		r16,7		/* 7 expansion rounds		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	lis		r0,0x0100	/* RCO(1)			*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ppc_expand_256_loop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	addi		r3,r3,32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	mr		r14,r12		/* apply LS_BOX to 8th temp	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	rotlwi		r14,r14,8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	LS_BOX(r14, r15, r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	xor		r14,r14,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	xor		r5,r5,r14	/* xor 4 keys			*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	xor		r6,r6,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	xor		r7,r7,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	xor		r8,r8,r7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	mr		r14,r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	LS_BOX(r14, r15, r4)		/* apply LS_BOX to 4th temp	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	xor		r9,r9,r14	/* xor 4 keys			*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	xor		r10,r10,r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	xor		r11,r11,r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	xor		r12,r12,r11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	stw		r5,0(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	stw		r6,4(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	stw		r7,8(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	stw		r8,12(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	subi		r16,r16,1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	cmpwi		r16,0		/* last round early kick out	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	bt		eq,ppc_expand_256_end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	stw		r9,16(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	stw		r10,20(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	stw		r11,24(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	stw		r12,28(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	GF8_MUL(r0, r0, r4, r14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	b		ppc_expand_256_loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) ppc_expand_256_end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	FINALIZE_KEY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	blr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * ppc_generate_decrypt_key: derive decryption key from encryption key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  * number of bytes to handle are calculated from length of key (16/24/32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) _GLOBAL(ppc_generate_decrypt_key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	addi		r6,r5,24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	slwi		r6,r6,2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	lwzx		r7,r4,r6	/* first/last 4 words are same	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	stw		r7,0(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	lwz		r7,0(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	stwx		r7,r3,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	addi		r6,r6,4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	lwzx		r7,r4,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	stw		r7,4(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	lwz		r7,4(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	stwx		r7,r3,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	addi		r6,r6,4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	lwzx		r7,r4,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	stw		r7,8(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	lwz		r7,8(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	stwx		r7,r3,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	addi		r6,r6,4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	lwzx		r7,r4,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	stw		r7,12(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	lwz		r7,12(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	stwx		r7,r3,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	addi		r3,r3,16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	add		r4,r4,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	subi		r4,r4,28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	addi		r5,r5,20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	srwi		r5,r5,2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) ppc_generate_decrypt_block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	li	r6,4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	mtctr	r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) ppc_generate_decrypt_word:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	lwz		r6,0(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	GF8_MUL(r7, r6, r0, r7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	GF8_MUL(r8, r7, r0, r8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	GF8_MUL(r9, r8, r0, r9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	xor		r10,r9,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	xor		r11,r7,r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	xor		r11,r11,r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	xor		r12,r7,r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	rotrwi		r12,r12,24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	xor		r11,r11,r12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	xor		r12,r8,r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	rotrwi		r12,r12,16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	xor		r11,r11,r12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	rotrwi		r12,r10,8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	xor		r11,r11,r12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	stw		r11,0(r3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	addi		r3,r3,4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	addi		r4,r4,4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	bdnz		ppc_generate_decrypt_word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	subi		r4,r4,32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	subi		r5,r5,1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	cmpwi		r5,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	bt		gt,ppc_generate_decrypt_block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	blr