aes_asm.S 26.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#include <linux/linkage.h>
#include <asm/visasm.h>

#define F3F(x,y,z)	(((x)<<30)|((y)<<19)|((z)<<5))

#define FPD_ENCODE(x)	(((x) >> 5) | ((x) & ~(0x20)))

#define RS1(x)		(FPD_ENCODE(x) << 14)
#define RS2(x)		(FPD_ENCODE(x) <<  0)
#define RS3(x)		(FPD_ENCODE(x) <<  9)
#define RD(x)		(FPD_ENCODE(x) << 25)
#define IMM5(x)		((x)           <<  9)

#define AES_EROUND01(a,b,c,d)	\
	.word	(F3F(2, 0x19, 0)|RS1(a)|RS2(b)|RS3(c)|RD(d));
#define AES_EROUND23(a,b,c,d)	\
	.word	(F3F(2, 0x19, 1)|RS1(a)|RS2(b)|RS3(c)|RD(d));
#define AES_DROUND01(a,b,c,d)	\
	.word	(F3F(2, 0x19, 2)|RS1(a)|RS2(b)|RS3(c)|RD(d));
#define AES_DROUND23(a,b,c,d)	\
	.word	(F3F(2, 0x19, 3)|RS1(a)|RS2(b)|RS3(c)|RD(d));
#define AES_EROUND01_L(a,b,c,d)	\
	.word	(F3F(2, 0x19, 4)|RS1(a)|RS2(b)|RS3(c)|RD(d));
#define AES_EROUND23_L(a,b,c,d)	\
	.word	(F3F(2, 0x19, 5)|RS1(a)|RS2(b)|RS3(c)|RD(d));
#define AES_DROUND01_L(a,b,c,d)	\
	.word	(F3F(2, 0x19, 6)|RS1(a)|RS2(b)|RS3(c)|RD(d));
#define AES_DROUND23_L(a,b,c,d)	\
	.word	(F3F(2, 0x19, 7)|RS1(a)|RS2(b)|RS3(c)|RD(d));
#define AES_KEXPAND1(a,b,c,d)	\
	.word	(F3F(2, 0x19, 8)|RS1(a)|RS2(b)|IMM5(c)|RD(d));
#define AES_KEXPAND0(a,b,c)	\
	.word	(F3F(2, 0x36, 0x130)|RS1(a)|RS2(b)|RD(c));
#define AES_KEXPAND2(a,b,c)	\
	.word	(F3F(2, 0x36, 0x131)|RS1(a)|RS2(b)|RD(c));

#define MOVXTOD_G3_F4		\
	.word	0x89b02303;
#define MOVXTOD_G7_F6		\
	.word	0x8db02307;
#define MOVXTOD_G3_F0		\
	.word	0x81b02303;
#define MOVXTOD_G7_F2		\
	.word	0x85b02307;
#define MOVXTOD_O0_F0		\
	.word	0x81b02308;
47 48
#define MOVXTOD_O5_F2		\
	.word	0x85b0230d;
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88

#define ENCRYPT_TWO_ROUNDS(KEY_BASE, I0, I1, T0, T1) \
	AES_EROUND01(KEY_BASE +  0, I0, I1, T0) \
	AES_EROUND23(KEY_BASE +  2, I0, I1, T1) \
	AES_EROUND01(KEY_BASE +  4, T0, T1, I0) \
	AES_EROUND23(KEY_BASE +  6, T0, T1, I1)

#define ENCRYPT_TWO_ROUNDS_LAST(KEY_BASE, I0, I1, T0, T1) \
	AES_EROUND01(KEY_BASE +  0, I0, I1, T0) \
	AES_EROUND23(KEY_BASE +  2, I0, I1, T1) \
	AES_EROUND01_L(KEY_BASE +  4, T0, T1, I0) \
	AES_EROUND23_L(KEY_BASE +  6, T0, T1, I1)

	/* 10 rounds */
#define ENCRYPT_128(KEY_BASE, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS(KEY_BASE +  0, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS(KEY_BASE +  8, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS(KEY_BASE + 16, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS(KEY_BASE + 24, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS_LAST(KEY_BASE + 32, I0, I1, T0, T1)

	/* 12 rounds */
#define ENCRYPT_192(KEY_BASE, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS(KEY_BASE +  0, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS(KEY_BASE +  8, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS(KEY_BASE + 16, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS(KEY_BASE + 24, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS(KEY_BASE + 32, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS_LAST(KEY_BASE + 40, I0, I1, T0, T1)

	/* 14 rounds */
#define ENCRYPT_256(KEY_BASE, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS(KEY_BASE +  0, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS(KEY_BASE +  8, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS(KEY_BASE + 16, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS(KEY_BASE + 24, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS(KEY_BASE + 32, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS(KEY_BASE + 40, I0, I1, T0, T1) \
	ENCRYPT_TWO_ROUNDS_LAST(KEY_BASE + 48, I0, I1, T0, T1)

89 90 91 92 93
#define DECRYPT_TWO_ROUNDS(KEY_BASE, I0, I1, T0, T1) \
	AES_DROUND23(KEY_BASE +  0, I0, I1, T1) \
	AES_DROUND01(KEY_BASE +  2, I0, I1, T0) \
	AES_DROUND23(KEY_BASE +  4, T0, T1, I1) \
	AES_DROUND01(KEY_BASE +  6, T0, T1, I0)
94

95 96 97 98 99
#define DECRYPT_TWO_ROUNDS_LAST(KEY_BASE, I0, I1, T0, T1) \
	AES_DROUND23(KEY_BASE +  0, I0, I1, T1) \
	AES_DROUND01(KEY_BASE +  2, I0, I1, T0) \
	AES_DROUND23_L(KEY_BASE +  4, T0, T1, I1) \
	AES_DROUND01_L(KEY_BASE +  6, T0, T1, I0)
100 101

	/* 10 rounds */
102 103 104 105 106 107
#define DECRYPT_128(KEY_BASE, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS(KEY_BASE +  0, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS(KEY_BASE +  8, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS(KEY_BASE + 16, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS(KEY_BASE + 24, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS_LAST(KEY_BASE + 32, I0, I1, T0, T1)
108 109

	/* 12 rounds */
110 111 112 113 114 115 116
#define DECRYPT_192(KEY_BASE, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS(KEY_BASE +  0, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS(KEY_BASE +  8, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS(KEY_BASE + 16, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS(KEY_BASE + 24, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS(KEY_BASE + 32, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS_LAST(KEY_BASE + 40, I0, I1, T0, T1)
117 118

	/* 14 rounds */
119 120 121 122 123 124 125 126 127 128
#define DECRYPT_256(KEY_BASE, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS(KEY_BASE +  0, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS(KEY_BASE +  8, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS(KEY_BASE + 16, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS(KEY_BASE + 24, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS(KEY_BASE + 32, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS(KEY_BASE + 40, I0, I1, T0, T1) \
	DECRYPT_TWO_ROUNDS_LAST(KEY_BASE + 48, I0, I1, T0, T1)

	.align	32
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
ENTRY(aes_sparc64_key_expand)
	/* %o0=input_key, %o1=output_key, %o2=key_len */
	VISEntry
	ld	[%o0 + 0x00], %f0
	ld	[%o0 + 0x04], %f1
	ld	[%o0 + 0x08], %f2
	ld	[%o0 + 0x0c], %f3

	std	%f0, [%o1 + 0x00]
	std	%f2, [%o1 + 0x08]
	add	%o1, 0x10, %o1

	cmp	%o2, 24
	bl	2f
	 nop

	be	1f
	 nop

	/* 256-bit key expansion */
	ld	[%o0 + 0x10], %f4
	ld	[%o0 + 0x14], %f5
	ld	[%o0 + 0x18], %f6
	ld	[%o0 + 0x1c], %f7

	std	%f4, [%o1 + 0x00]
	std	%f6, [%o1 + 0x08]
	add	%o1, 0x10, %o1

	AES_KEXPAND1(0, 6, 0x0, 8)
	AES_KEXPAND2(2, 8, 10)
	AES_KEXPAND0(4, 10, 12)
	AES_KEXPAND2(6, 12, 14)
	AES_KEXPAND1(8, 14, 0x1, 16)
	AES_KEXPAND2(10, 16, 18)
	AES_KEXPAND0(12, 18, 20)
	AES_KEXPAND2(14, 20, 22)
	AES_KEXPAND1(16, 22, 0x2, 24)
	AES_KEXPAND2(18, 24, 26)
	AES_KEXPAND0(20, 26, 28)
	AES_KEXPAND2(22, 28, 30)
	AES_KEXPAND1(24, 30, 0x3, 32)
	AES_KEXPAND2(26, 32, 34)
	AES_KEXPAND0(28, 34, 36)
	AES_KEXPAND2(30, 36, 38)
	AES_KEXPAND1(32, 38, 0x4, 40)
	AES_KEXPAND2(34, 40, 42)
	AES_KEXPAND0(36, 42, 44)
	AES_KEXPAND2(38, 44, 46)
	AES_KEXPAND1(40, 46, 0x5, 48)
	AES_KEXPAND2(42, 48, 50)
	AES_KEXPAND0(44, 50, 52)
	AES_KEXPAND2(46, 52, 54)
	AES_KEXPAND1(48, 54, 0x6, 56)
	AES_KEXPAND2(50, 56, 58)

	std	%f8, [%o1 + 0x00]
	std	%f10, [%o1 + 0x08]
	std	%f12, [%o1 + 0x10]
	std	%f14, [%o1 + 0x18]
	std	%f16, [%o1 + 0x20]
	std	%f18, [%o1 + 0x28]
	std	%f20, [%o1 + 0x30]
	std	%f22, [%o1 + 0x38]
	std	%f24, [%o1 + 0x40]
	std	%f26, [%o1 + 0x48]
	std	%f28, [%o1 + 0x50]
	std	%f30, [%o1 + 0x58]
	std	%f32, [%o1 + 0x60]
	std	%f34, [%o1 + 0x68]
	std	%f36, [%o1 + 0x70]
	std	%f38, [%o1 + 0x78]
	std	%f40, [%o1 + 0x80]
	std	%f42, [%o1 + 0x88]
	std	%f44, [%o1 + 0x90]
	std	%f46, [%o1 + 0x98]
	std	%f48, [%o1 + 0xa0]
	std	%f50, [%o1 + 0xa8]
	std	%f52, [%o1 + 0xb0]
	std	%f54, [%o1 + 0xb8]
	std	%f56, [%o1 + 0xc0]
	ba,pt	%xcc, 80f
	 std	%f58, [%o1 + 0xc8]

1:	
	/* 192-bit key expansion */
	ld	[%o0 + 0x10], %f4
	ld	[%o0 + 0x14], %f5

	std	%f4, [%o1 + 0x00]
	add	%o1, 0x08, %o1

	AES_KEXPAND1(0, 4, 0x0, 6)
	AES_KEXPAND2(2, 6, 8)
	AES_KEXPAND2(4, 8, 10)
	AES_KEXPAND1(6, 10, 0x1, 12)
	AES_KEXPAND2(8, 12, 14)
	AES_KEXPAND2(10, 14, 16)
	AES_KEXPAND1(12, 16, 0x2, 18)
	AES_KEXPAND2(14, 18, 20)
	AES_KEXPAND2(16, 20, 22)
	AES_KEXPAND1(18, 22, 0x3, 24)
	AES_KEXPAND2(20, 24, 26)
	AES_KEXPAND2(22, 26, 28)
	AES_KEXPAND1(24, 28, 0x4, 30)
	AES_KEXPAND2(26, 30, 32)
	AES_KEXPAND2(28, 32, 34)
	AES_KEXPAND1(30, 34, 0x5, 36)
	AES_KEXPAND2(32, 36, 38)
	AES_KEXPAND2(34, 38, 40)
	AES_KEXPAND1(36, 40, 0x6, 42)
	AES_KEXPAND2(38, 42, 44)
	AES_KEXPAND2(40, 44, 46)
	AES_KEXPAND1(42, 46, 0x7, 48)
	AES_KEXPAND2(44, 48, 50)

	std	%f6, [%o1 + 0x00]
	std	%f8, [%o1 + 0x08]
	std	%f10, [%o1 + 0x10]
	std	%f12, [%o1 + 0x18]
	std	%f14, [%o1 + 0x20]
	std	%f16, [%o1 + 0x28]
	std	%f18, [%o1 + 0x30]
	std	%f20, [%o1 + 0x38]
	std	%f22, [%o1 + 0x40]
	std	%f24, [%o1 + 0x48]
	std	%f26, [%o1 + 0x50]
	std	%f28, [%o1 + 0x58]
	std	%f30, [%o1 + 0x60]
	std	%f32, [%o1 + 0x68]
	std	%f34, [%o1 + 0x70]
	std	%f36, [%o1 + 0x78]
	std	%f38, [%o1 + 0x80]
	std	%f40, [%o1 + 0x88]
	std	%f42, [%o1 + 0x90]
	std	%f44, [%o1 + 0x98]
	std	%f46, [%o1 + 0xa0]
	std	%f48, [%o1 + 0xa8]
	ba,pt	%xcc, 80f
	 std	%f50, [%o1 + 0xb0]

2:
	/* 128-bit key expansion */
	AES_KEXPAND1(0, 2, 0x0, 4)
	AES_KEXPAND2(2, 4, 6)
	AES_KEXPAND1(4, 6, 0x1, 8)
	AES_KEXPAND2(6, 8, 10)
	AES_KEXPAND1(8, 10, 0x2, 12)
	AES_KEXPAND2(10, 12, 14)
	AES_KEXPAND1(12, 14, 0x3, 16)
	AES_KEXPAND2(14, 16, 18)
	AES_KEXPAND1(16, 18, 0x4, 20)
	AES_KEXPAND2(18, 20, 22)
	AES_KEXPAND1(20, 22, 0x5, 24)
	AES_KEXPAND2(22, 24, 26)
	AES_KEXPAND1(24, 26, 0x6, 28)
	AES_KEXPAND2(26, 28, 30)
	AES_KEXPAND1(28, 30, 0x7, 32)
	AES_KEXPAND2(30, 32, 34)
	AES_KEXPAND1(32, 34, 0x8, 36)
	AES_KEXPAND2(34, 36, 38)
	AES_KEXPAND1(36, 38, 0x9, 40)
	AES_KEXPAND2(38, 40, 42)

	std	%f4, [%o1 + 0x00]
	std	%f6, [%o1 + 0x08]
	std	%f8, [%o1 + 0x10]
	std	%f10, [%o1 + 0x18]
	std	%f12, [%o1 + 0x20]
	std	%f14, [%o1 + 0x28]
	std	%f16, [%o1 + 0x30]
	std	%f18, [%o1 + 0x38]
	std	%f20, [%o1 + 0x40]
	std	%f22, [%o1 + 0x48]
	std	%f24, [%o1 + 0x50]
	std	%f26, [%o1 + 0x58]
	std	%f28, [%o1 + 0x60]
	std	%f30, [%o1 + 0x68]
	std	%f32, [%o1 + 0x70]
	std	%f34, [%o1 + 0x78]
	std	%f36, [%o1 + 0x80]
	std	%f38, [%o1 + 0x88]
	std	%f40, [%o1 + 0x90]
	std	%f42, [%o1 + 0x98]
80:
	retl
	 VISExit
ENDPROC(aes_sparc64_key_expand)

318 319 320
	.align		32
ENTRY(aes_sparc64_encrypt_128)
	/* %o0=key, %o1=input, %o2=output */
321 322 323 324 325 326 327
	VISEntry
	ld		[%o1 + 0x00], %f4
	ld		[%o1 + 0x04], %f5
	ld		[%o1 + 0x08], %f6
	ld		[%o1 + 0x0c], %f7
	ldd		[%o0 + 0x00], %f8
	ldd		[%o0 + 0x08], %f10
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
	ldd		[%o0 + 0x10], %f12
	ldd		[%o0 + 0x18], %f14
	ldd		[%o0 + 0x20], %f16
	ldd		[%o0 + 0x28], %f18
	ldd		[%o0 + 0x30], %f20
	ldd		[%o0 + 0x38], %f22
	ldd		[%o0 + 0x40], %f24
	ldd		[%o0 + 0x48], %f26
	ldd		[%o0 + 0x50], %f28
	ldd		[%o0 + 0x58], %f30
	ldd		[%o0 + 0x60], %f32
	ldd		[%o0 + 0x68], %f34
	ldd		[%o0 + 0x70], %f36
	ldd		[%o0 + 0x78], %f38
	ldd		[%o0 + 0x80], %f40
	ldd		[%o0 + 0x88], %f42
	ldd		[%o0 + 0x90], %f44
	ldd		[%o0 + 0x98], %f46
	ldd		[%o0 + 0xa0], %f48
	ldd		[%o0 + 0xa8], %f50
348
	fxor		%f8, %f4, %f4
349 350 351 352 353 354 355 356 357
	fxor		%f10, %f6, %f6
	ENCRYPT_128(12, 4, 6, 0, 2)
	st		%f4, [%o2 + 0x00]
	st		%f5, [%o2 + 0x04]
	st		%f6, [%o2 + 0x08]
	st		%f7, [%o2 + 0x0c]
	retl
	 VISExit
ENDPROC(aes_sparc64_encrypt_128)
358

359 360 361 362 363 364 365 366
	.align		32
ENTRY(aes_sparc64_encrypt_192)
	/* %o0=key, %o1=input, %o2=output */
	VISEntry
	ld		[%o1 + 0x00], %f4
	ld		[%o1 + 0x04], %f5
	ld		[%o1 + 0x08], %f6
	ld		[%o1 + 0x0c], %f7
367

368 369
	ldd		[%o0 + 0x00], %f8
	ldd		[%o0 + 0x08], %f10
370

371 372
	fxor		%f8, %f4, %f4
	fxor		%f10, %f6, %f6
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412

	ldd		[%o0 + 0x10], %f8
	ldd		[%o0 + 0x18], %f10
	ldd		[%o0 + 0x20], %f12
	ldd		[%o0 + 0x28], %f14
	add		%o0, 0x20, %o0

	ENCRYPT_TWO_ROUNDS(8, 4, 6, 0, 2)

	ldd		[%o0 + 0x10], %f12
	ldd		[%o0 + 0x18], %f14
	ldd		[%o0 + 0x20], %f16
	ldd		[%o0 + 0x28], %f18
	ldd		[%o0 + 0x30], %f20
	ldd		[%o0 + 0x38], %f22
	ldd		[%o0 + 0x40], %f24
	ldd		[%o0 + 0x48], %f26
	ldd		[%o0 + 0x50], %f28
	ldd		[%o0 + 0x58], %f30
	ldd		[%o0 + 0x60], %f32
	ldd		[%o0 + 0x68], %f34
	ldd		[%o0 + 0x70], %f36
	ldd		[%o0 + 0x78], %f38
	ldd		[%o0 + 0x80], %f40
	ldd		[%o0 + 0x88], %f42
	ldd		[%o0 + 0x90], %f44
	ldd		[%o0 + 0x98], %f46
	ldd		[%o0 + 0xa0], %f48
	ldd		[%o0 + 0xa8], %f50


	ENCRYPT_128(12, 4, 6, 0, 2)

	st		%f4, [%o2 + 0x00]
	st		%f5, [%o2 + 0x04]
	st		%f6, [%o2 + 0x08]
	st		%f7, [%o2 + 0x0c]

	retl
	 VISExit
413
ENDPROC(aes_sparc64_encrypt_192)
414

415 416 417
	.align		32
ENTRY(aes_sparc64_encrypt_256)
	/* %o0=key, %o1=input, %o2=output */
418 419 420 421 422 423
	VISEntry
	ld		[%o1 + 0x00], %f4
	ld		[%o1 + 0x04], %f5
	ld		[%o1 + 0x08], %f6
	ld		[%o1 + 0x0c], %f7

424 425
	ldd		[%o0 + 0x00], %f8
	ldd		[%o0 + 0x08], %f10
426

427 428
	fxor		%f8, %f4, %f4
	fxor		%f10, %f6, %f6
429

430
	ldd		[%o0 + 0x10], %f8
431

432 433 434 435
	ldd		[%o0 + 0x18], %f10
	ldd		[%o0 + 0x20], %f12
	ldd		[%o0 + 0x28], %f14
	add		%o0, 0x20, %o0
436

437
	ENCRYPT_TWO_ROUNDS(8, 4, 6, 0, 2)
438

439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
	ldd		[%o0 + 0x10], %f8

	ldd		[%o0 + 0x18], %f10
	ldd		[%o0 + 0x20], %f12
	ldd		[%o0 + 0x28], %f14
	add		%o0, 0x20, %o0

	ENCRYPT_TWO_ROUNDS(8, 4, 6, 0, 2)

	ldd		[%o0 + 0x10], %f12
	ldd		[%o0 + 0x18], %f14
	ldd		[%o0 + 0x20], %f16
	ldd		[%o0 + 0x28], %f18
	ldd		[%o0 + 0x30], %f20
	ldd		[%o0 + 0x38], %f22
	ldd		[%o0 + 0x40], %f24
	ldd		[%o0 + 0x48], %f26
	ldd		[%o0 + 0x50], %f28
	ldd		[%o0 + 0x58], %f30
	ldd		[%o0 + 0x60], %f32
	ldd		[%o0 + 0x68], %f34
	ldd		[%o0 + 0x70], %f36
	ldd		[%o0 + 0x78], %f38
	ldd		[%o0 + 0x80], %f40
	ldd		[%o0 + 0x88], %f42
	ldd		[%o0 + 0x90], %f44
	ldd		[%o0 + 0x98], %f46
	ldd		[%o0 + 0xa0], %f48
	ldd		[%o0 + 0xa8], %f50

	ENCRYPT_128(12, 4, 6, 0, 2)
470 471 472 473 474 475 476 477

	st		%f4, [%o2 + 0x00]
	st		%f5, [%o2 + 0x04]
	st		%f6, [%o2 + 0x08]
	st		%f7, [%o2 + 0x0c]

	retl
	 VISExit
478
ENDPROC(aes_sparc64_encrypt_256)
479

480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
	.align		32
ENTRY(aes_sparc64_decrypt_128)
	/* %o0=key, %o1=input, %o2=output */
	VISEntry
	ld		[%o1 + 0x00], %f4
	ld		[%o1 + 0x04], %f5
	ld		[%o1 + 0x08], %f6
	ld		[%o1 + 0x0c], %f7
	ldd		[%o0 + 0xa0], %f8
	ldd		[%o0 + 0xa8], %f10
	ldd		[%o0 + 0x98], %f12
	ldd		[%o0 + 0x90], %f14
	ldd		[%o0 + 0x88], %f16
	ldd		[%o0 + 0x80], %f18
	ldd		[%o0 + 0x78], %f20
	ldd		[%o0 + 0x70], %f22
	ldd		[%o0 + 0x68], %f24
	ldd		[%o0 + 0x60], %f26
	ldd		[%o0 + 0x58], %f28
	ldd		[%o0 + 0x50], %f30
	ldd		[%o0 + 0x48], %f32
	ldd		[%o0 + 0x40], %f34
	ldd		[%o0 + 0x38], %f36
	ldd		[%o0 + 0x30], %f38
	ldd		[%o0 + 0x28], %f40
	ldd		[%o0 + 0x20], %f42
	ldd		[%o0 + 0x18], %f44
	ldd		[%o0 + 0x10], %f46
	ldd		[%o0 + 0x08], %f48
	ldd		[%o0 + 0x00], %f50
	fxor		%f8, %f4, %f4
	fxor		%f10, %f6, %f6
	DECRYPT_128(12, 4, 6, 0, 2)
	st		%f4, [%o2 + 0x00]
	st		%f5, [%o2 + 0x04]
	st		%f6, [%o2 + 0x08]
	st		%f7, [%o2 + 0x0c]
	retl
	 VISExit
ENDPROC(aes_sparc64_decrypt_128)

	.align		32
ENTRY(aes_sparc64_decrypt_192)
	/* %o0=key, %o1=input, %o2=output */
	VISEntry
	ld		[%o1 + 0x00], %f4
	ld		[%o1 + 0x04], %f5
	ld		[%o1 + 0x08], %f6
	ld		[%o1 + 0x0c], %f7
	ldd		[%o0 + 0xc0], %f8
	ldd		[%o0 + 0xc8], %f10
	ldd		[%o0 + 0xb8], %f12
	ldd		[%o0 + 0xb0], %f14
	ldd		[%o0 + 0xa8], %f16
	ldd		[%o0 + 0xa0], %f18
	fxor		%f8, %f4, %f4
	fxor		%f10, %f6, %f6
	ldd		[%o0 + 0x98], %f20
	ldd		[%o0 + 0x90], %f22
	ldd		[%o0 + 0x88], %f24
	ldd		[%o0 + 0x80], %f26
	DECRYPT_TWO_ROUNDS(12, 4, 6, 0, 2)
	ldd		[%o0 + 0x78], %f28
	ldd		[%o0 + 0x70], %f30
	ldd		[%o0 + 0x68], %f32
	ldd		[%o0 + 0x60], %f34
	ldd		[%o0 + 0x58], %f36
	ldd		[%o0 + 0x50], %f38
	ldd		[%o0 + 0x48], %f40
	ldd		[%o0 + 0x40], %f42
	ldd		[%o0 + 0x38], %f44
	ldd		[%o0 + 0x30], %f46
	ldd		[%o0 + 0x28], %f48
	ldd		[%o0 + 0x20], %f50
	ldd		[%o0 + 0x18], %f52
	ldd		[%o0 + 0x10], %f54
	ldd		[%o0 + 0x08], %f56
	ldd		[%o0 + 0x00], %f58
	DECRYPT_128(20, 4, 6, 0, 2)
	st		%f4, [%o2 + 0x00]
	st		%f5, [%o2 + 0x04]
	st		%f6, [%o2 + 0x08]
	st		%f7, [%o2 + 0x0c]
	retl
	 VISExit
ENDPROC(aes_sparc64_decrypt_192)

	.align		32
ENTRY(aes_sparc64_decrypt_256)
	/* %o0=key, %o1=input, %o2=output */
	VISEntry
	ld		[%o1 + 0x00], %f4
	ld		[%o1 + 0x04], %f5
	ld		[%o1 + 0x08], %f6
	ld		[%o1 + 0x0c], %f7
	ldd		[%o0 + 0xe0], %f8
	ldd		[%o0 + 0xe8], %f10
	ldd		[%o0 + 0xd8], %f12
	ldd		[%o0 + 0xd0], %f14
	ldd		[%o0 + 0xc8], %f16
	fxor		%f8, %f4, %f4
	ldd		[%o0 + 0xc0], %f18
	fxor		%f10, %f6, %f6
	ldd		[%o0 + 0xb8], %f20
	AES_DROUND23(12, 4, 6, 2)
	ldd		[%o0 + 0xb0], %f22
	AES_DROUND01(14, 4, 6, 0)
	ldd		[%o0 + 0xa8], %f24
	AES_DROUND23(16, 0, 2, 6)
	ldd		[%o0 + 0xa0], %f26
	AES_DROUND01(18, 0, 2, 4)
	ldd		[%o0 + 0x98], %f12
	AES_DROUND23(20, 4, 6, 2)
	ldd		[%o0 + 0x90], %f14
	AES_DROUND01(22, 4, 6, 0)
	ldd		[%o0 + 0x88], %f16
	AES_DROUND23(24, 0, 2, 6)
	ldd		[%o0 + 0x80], %f18
	AES_DROUND01(26, 0, 2, 4)
	ldd		[%o0 + 0x78], %f20
	AES_DROUND23(12, 4, 6, 2)
	ldd		[%o0 + 0x70], %f22
	AES_DROUND01(14, 4, 6, 0)
	ldd		[%o0 + 0x68], %f24
	AES_DROUND23(16, 0, 2, 6)
	ldd		[%o0 + 0x60], %f26
	AES_DROUND01(18, 0, 2, 4)
	ldd		[%o0 + 0x58], %f28
	AES_DROUND23(20, 4, 6, 2)
	ldd		[%o0 + 0x50], %f30
	AES_DROUND01(22, 4, 6, 0)
	ldd		[%o0 + 0x48], %f32
	AES_DROUND23(24, 0, 2, 6)
	ldd		[%o0 + 0x40], %f34
	AES_DROUND01(26, 0, 2, 4)
	ldd		[%o0 + 0x38], %f36
	AES_DROUND23(28, 4, 6, 2)
	ldd		[%o0 + 0x30], %f38
	AES_DROUND01(30, 4, 6, 0)
	ldd		[%o0 + 0x28], %f40
	AES_DROUND23(32, 0, 2, 6)
	ldd		[%o0 + 0x20], %f42
	AES_DROUND01(34, 0, 2, 4)
	ldd		[%o0 + 0x18], %f44
	AES_DROUND23(36, 4, 6, 2)
	ldd		[%o0 + 0x10], %f46
	AES_DROUND01(38, 4, 6, 0)
	ldd		[%o0 + 0x08], %f48
	AES_DROUND23(40, 0, 2, 6)
	ldd		[%o0 + 0x00], %f50
	AES_DROUND01(42, 0, 2, 4)
	AES_DROUND23(44, 4, 6, 2)
	AES_DROUND01(46, 4, 6, 0)
	AES_DROUND23_L(48, 0, 2, 6)
	AES_DROUND01_L(50, 0, 2, 4)
	st		%f4, [%o2 + 0x00]
	st		%f5, [%o2 + 0x04]
	st		%f6, [%o2 + 0x08]
	st		%f7, [%o2 + 0x0c]
	retl
	 VISExit
ENDPROC(aes_sparc64_decrypt_256)

	.align		32
ENTRY(aes_sparc64_load_encrypt_keys_128)
645
	/* %o0=key */
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
	VISEntry
	ldd		[%o0 + 0x10], %f8
	ldd		[%o0 + 0x18], %f10
	ldd		[%o0 + 0x20], %f12
	ldd		[%o0 + 0x28], %f14
	ldd		[%o0 + 0x30], %f16
	ldd		[%o0 + 0x38], %f18
	ldd		[%o0 + 0x40], %f20
	ldd		[%o0 + 0x48], %f22
	ldd		[%o0 + 0x50], %f24
	ldd		[%o0 + 0x58], %f26
	ldd		[%o0 + 0x60], %f28
	ldd		[%o0 + 0x68], %f30
	ldd		[%o0 + 0x70], %f32
	ldd		[%o0 + 0x78], %f34
	ldd		[%o0 + 0x80], %f36
	ldd		[%o0 + 0x88], %f38
	ldd		[%o0 + 0x90], %f40
	ldd		[%o0 + 0x98], %f42
	ldd		[%o0 + 0xa0], %f44
	retl
	 ldd		[%o0 + 0xa8], %f46
ENDPROC(aes_sparc64_load_encrypt_keys_128)
669

670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
	.align		32
ENTRY(aes_sparc64_load_encrypt_keys_192)
	/* %o0=key */
	VISEntry
	ldd		[%o0 + 0x10], %f8
	ldd		[%o0 + 0x18], %f10
	ldd		[%o0 + 0x20], %f12
	ldd		[%o0 + 0x28], %f14
	ldd		[%o0 + 0x30], %f16
	ldd		[%o0 + 0x38], %f18
	ldd		[%o0 + 0x40], %f20
	ldd		[%o0 + 0x48], %f22
	ldd		[%o0 + 0x50], %f24
	ldd		[%o0 + 0x58], %f26
	ldd		[%o0 + 0x60], %f28
	ldd		[%o0 + 0x68], %f30
	ldd		[%o0 + 0x70], %f32
	ldd		[%o0 + 0x78], %f34
	ldd		[%o0 + 0x80], %f36
	ldd		[%o0 + 0x88], %f38
	ldd		[%o0 + 0x90], %f40
	ldd		[%o0 + 0x98], %f42
	ldd		[%o0 + 0xa0], %f44
	ldd		[%o0 + 0xa8], %f46
	ldd		[%o0 + 0xb0], %f48
	ldd		[%o0 + 0xb8], %f50
	ldd		[%o0 + 0xc0], %f52
	retl
	 ldd		[%o0 + 0xc8], %f54
ENDPROC(aes_sparc64_load_encrypt_keys_192)

	.align		32
ENTRY(aes_sparc64_load_encrypt_keys_256)
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
	/* %o0=key */
	VISEntry
	ldd		[%o0 + 0x10], %f8
	ldd		[%o0 + 0x18], %f10
	ldd		[%o0 + 0x20], %f12
	ldd		[%o0 + 0x28], %f14
	ldd		[%o0 + 0x30], %f16
	ldd		[%o0 + 0x38], %f18
	ldd		[%o0 + 0x40], %f20
	ldd		[%o0 + 0x48], %f22
	ldd		[%o0 + 0x50], %f24
	ldd		[%o0 + 0x58], %f26
	ldd		[%o0 + 0x60], %f28
	ldd		[%o0 + 0x68], %f30
	ldd		[%o0 + 0x70], %f32
	ldd		[%o0 + 0x78], %f34
	ldd		[%o0 + 0x80], %f36
	ldd		[%o0 + 0x88], %f38
	ldd		[%o0 + 0x90], %f40
	ldd		[%o0 + 0x98], %f42
	ldd		[%o0 + 0xa0], %f44
	ldd		[%o0 + 0xa8], %f46
	ldd		[%o0 + 0xb0], %f48
	ldd		[%o0 + 0xb8], %f50
	ldd		[%o0 + 0xc0], %f52
	ldd		[%o0 + 0xc8], %f54
	ldd		[%o0 + 0xd0], %f56
	ldd		[%o0 + 0xd8], %f58
	ldd		[%o0 + 0xe0], %f60
	retl
	 ldd		[%o0 + 0xe8], %f62
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
ENDPROC(aes_sparc64_load_encrypt_keys_256)

	.align		32
ENTRY(aes_sparc64_load_decrypt_keys_128)
	/* %o0=key */
	VISEntry
	ldd		[%o0 + 0x98], %f8
	ldd		[%o0 + 0x90], %f10
	ldd		[%o0 + 0x88], %f12
	ldd		[%o0 + 0x80], %f14
	ldd		[%o0 + 0x78], %f16
	ldd		[%o0 + 0x70], %f18
	ldd		[%o0 + 0x68], %f20
	ldd		[%o0 + 0x60], %f22
	ldd		[%o0 + 0x58], %f24
	ldd		[%o0 + 0x50], %f26
	ldd		[%o0 + 0x48], %f28
	ldd		[%o0 + 0x40], %f30
	ldd		[%o0 + 0x38], %f32
	ldd		[%o0 + 0x30], %f34
	ldd		[%o0 + 0x28], %f36
	ldd		[%o0 + 0x20], %f38
	ldd		[%o0 + 0x18], %f40
	ldd		[%o0 + 0x10], %f42
	ldd		[%o0 + 0x08], %f44
	retl
	 ldd		[%o0 + 0x00], %f46
ENDPROC(aes_sparc64_load_decrypt_keys_128)
762

763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
	.align		32
ENTRY(aes_sparc64_load_decrypt_keys_192)
	/* %o0=key */
	VISEntry
	ldd		[%o0 + 0xb8], %f8
	ldd		[%o0 + 0xb0], %f10
	ldd		[%o0 + 0xa8], %f12
	ldd		[%o0 + 0xa0], %f14
	ldd		[%o0 + 0x98], %f16
	ldd		[%o0 + 0x90], %f18
	ldd		[%o0 + 0x88], %f20
	ldd		[%o0 + 0x80], %f22
	ldd		[%o0 + 0x78], %f24
	ldd		[%o0 + 0x70], %f26
	ldd		[%o0 + 0x68], %f28
	ldd		[%o0 + 0x60], %f30
	ldd		[%o0 + 0x58], %f32
	ldd		[%o0 + 0x50], %f34
	ldd		[%o0 + 0x48], %f36
	ldd		[%o0 + 0x40], %f38
	ldd		[%o0 + 0x38], %f40
	ldd		[%o0 + 0x30], %f42
	ldd		[%o0 + 0x28], %f44
	ldd		[%o0 + 0x20], %f46
	ldd		[%o0 + 0x18], %f48
	ldd		[%o0 + 0x10], %f50
	ldd		[%o0 + 0x08], %f52
	retl
	 ldd		[%o0 + 0x00], %f54
ENDPROC(aes_sparc64_load_decrypt_keys_192)

	.align		32
ENTRY(aes_sparc64_load_decrypt_keys_256)
	/* %o0=key */
	VISEntry
	ldd		[%o0 + 0xd8], %f8
	ldd		[%o0 + 0xd0], %f10
	ldd		[%o0 + 0xc8], %f12
	ldd		[%o0 + 0xc0], %f14
	ldd		[%o0 + 0xb8], %f16
	ldd		[%o0 + 0xb0], %f18
	ldd		[%o0 + 0xa8], %f20
	ldd		[%o0 + 0xa0], %f22
	ldd		[%o0 + 0x98], %f24
	ldd		[%o0 + 0x90], %f26
	ldd		[%o0 + 0x88], %f28
	ldd		[%o0 + 0x80], %f30
	ldd		[%o0 + 0x78], %f32
	ldd		[%o0 + 0x70], %f34
	ldd		[%o0 + 0x68], %f36
	ldd		[%o0 + 0x60], %f38
	ldd		[%o0 + 0x58], %f40
	ldd		[%o0 + 0x50], %f42
	ldd		[%o0 + 0x48], %f44
	ldd		[%o0 + 0x40], %f46
	ldd		[%o0 + 0x38], %f48
	ldd		[%o0 + 0x30], %f50
	ldd		[%o0 + 0x28], %f52
	ldd		[%o0 + 0x20], %f54
	ldd		[%o0 + 0x18], %f56
	ldd		[%o0 + 0x10], %f58
	ldd		[%o0 + 0x08], %f60
	retl
	 ldd		[%o0 + 0x00], %f62
ENDPROC(aes_sparc64_load_decrypt_keys_256)

	.align		32
ENTRY(aes_sparc64_ecb_encrypt_128)
	/* %o0=key, %o1=input, %o2=output, %o3=len */
832 833
	ldx		[%o0 + 0x00], %g1
	ldx		[%o0 + 0x08], %g2
834
1:	ldx		[%o1 + 0x00], %g3
835 836 837 838 839 840
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
841
	ENCRYPT_128(8, 4, 6, 0, 2)
842 843
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
844 845
	subcc		%o3, 0x10, %o3
	bne,pt		%xcc, 1b
846 847 848
	 add		%o2, 0x10, %o2
	retl
	 nop
849
ENDPROC(aes_sparc64_ecb_encrypt_128)
850

851 852 853 854 855 856
	.align		32
ENTRY(aes_sparc64_ecb_encrypt_192)
	/* %o0=key, %o1=input, %o2=output, %o3=len */
	ldx		[%o0 + 0x00], %g1
	ldx		[%o0 + 0x08], %g2
1:	ldx		[%o1 + 0x00], %g3
857 858 859 860 861 862 863 864 865
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
	ENCRYPT_192(8, 4, 6, 0, 2)
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
866
	subcc		%o3, 0x10, %o3
867 868 869 870
	bne,pt		%xcc, 1b
	 add		%o2, 0x10, %o2
	retl
	 nop
871
ENDPROC(aes_sparc64_ecb_encrypt_192)
872

873 874 875 876 877 878
	.align		32
ENTRY(aes_sparc64_ecb_encrypt_256)
	/* %o0=key, %o1=input, %o2=output, %o3=len */
	ldx		[%o0 + 0x00], %g1
	ldx		[%o0 + 0x08], %g2
1:	ldx		[%o1 + 0x00], %g3
879 880 881 882 883 884
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
885
	ENCRYPT_256(8, 4, 6, 0, 2)
886 887
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
888 889
	subcc		%o3, 0x10, %o3
	bne,pt		%xcc, 1b
890 891 892
	 add		%o2, 0x10, %o2
	retl
	 nop
893
ENDPROC(aes_sparc64_ecb_encrypt_256)
894

895 896 897
	.align		32
ENTRY(aes_sparc64_ecb_decrypt_128)
	/* %o0=&key[key_len], %o1=input, %o2=output, %o3=len */
898 899
	ldx		[%o0 - 0x10], %g1
	ldx		[%o0 - 0x08], %g2
900
1:	ldx		[%o1 + 0x00], %g3
901 902 903 904 905 906
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
907
	DECRYPT_128(8, 4, 6, 0, 2)
908 909
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
910 911
	subcc		%o3, 0x10, %o3
	bne,pt		%xcc, 1b
912 913 914
	 add		%o2, 0x10, %o2
	retl
	 nop
915
ENDPROC(aes_sparc64_ecb_decrypt_128)
916

917 918 919 920 921 922
	.align		32
ENTRY(aes_sparc64_ecb_decrypt_192)
	/* %o0=&key[key_len], %o1=input, %o2=output, %o3=len */
	ldx		[%o0 - 0x10], %g1
	ldx		[%o0 - 0x08], %g2
1:	ldx		[%o1 + 0x00], %g3
923 924 925 926 927 928
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
929
	DECRYPT_192(8, 4, 6, 0, 2)
930 931
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
932
	subcc		%o3, 0x10, %o3
933 934 935 936
	bne,pt		%xcc, 1b
	 add		%o2, 0x10, %o2
	retl
	 nop
937
ENDPROC(aes_sparc64_ecb_decrypt_192)
938

939 940 941 942 943 944
	.align		32
ENTRY(aes_sparc64_ecb_decrypt_256)
	/* %o0=&key[key_len], %o1=input, %o2=output, %o3=len */
	ldx		[%o0 - 0x10], %g1
	ldx		[%o0 - 0x08], %g2
1:	ldx		[%o1 + 0x00], %g3
945 946 947 948 949 950
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
951
	DECRYPT_256(8, 4, 6, 0, 2)
952 953
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
954 955
	subcc		%o3, 0x10, %o3
	bne,pt		%xcc, 1b
956 957 958
	 add		%o2, 0x10, %o2
	retl
	 nop
959
ENDPROC(aes_sparc64_ecb_decrypt_256)
960

961 962 963 964 965
	.align		32
ENTRY(aes_sparc64_cbc_encrypt_128)
	/* %o0=key, %o1=input, %o2=output, %o3=len, %o4=IV */
	ldd		[%o4 + 0x00], %f4
	ldd		[%o4 + 0x08], %f6
966 967
	ldx		[%o0 + 0x00], %g1
	ldx		[%o0 + 0x08], %g2
968
1:	ldx		[%o1 + 0x00], %g3
969 970 971 972 973 974 975 976
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F0
	MOVXTOD_G7_F2
	fxor		%f4, %f0, %f4
	fxor		%f6, %f2, %f6
977
	ENCRYPT_128(8, 4, 6, 0, 2)
978 979
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
980 981
	subcc		%o3, 0x10, %o3
	bne,pt		%xcc, 1b
982
	 add		%o2, 0x10, %o2
983 984
	std		%f4, [%o4 + 0x00]
	std		%f6, [%o4 + 0x08]
985 986
	retl
	 nop
987
ENDPROC(aes_sparc64_cbc_encrypt_128)
988

989 990 991 992 993 994 995 996
	.align		32
ENTRY(aes_sparc64_cbc_encrypt_192)
	/* %o0=key, %o1=input, %o2=output, %o3=len, %o4=IV */
	ldd		[%o4 + 0x00], %f4
	ldd		[%o4 + 0x08], %f6
	ldx		[%o0 + 0x00], %g1
	ldx		[%o0 + 0x08], %g2
1:	ldx		[%o1 + 0x00], %g3
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F0
	MOVXTOD_G7_F2
	fxor		%f4, %f0, %f4
	fxor		%f6, %f2, %f6
	ENCRYPT_192(8, 4, 6, 0, 2)
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
1008
	subcc		%o3, 0x10, %o3
1009 1010
	bne,pt		%xcc, 1b
	 add		%o2, 0x10, %o2
1011 1012
	std		%f4, [%o4 + 0x00]
	std		%f6, [%o4 + 0x08]
1013 1014
	retl
	 nop
1015
ENDPROC(aes_sparc64_cbc_encrypt_192)
1016

1017 1018 1019 1020 1021 1022 1023 1024
	.align		32
ENTRY(aes_sparc64_cbc_encrypt_256)
	/* %o0=key, %o1=input, %o2=output, %o3=len, %o4=IV */
	ldd		[%o4 + 0x00], %f4
	ldd		[%o4 + 0x08], %f6
	ldx		[%o0 + 0x00], %g1
	ldx		[%o0 + 0x08], %g2
1:	ldx		[%o1 + 0x00], %g3
1025 1026 1027 1028 1029 1030 1031 1032
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F0
	MOVXTOD_G7_F2
	fxor		%f4, %f0, %f4
	fxor		%f6, %f2, %f6
1033
	ENCRYPT_256(8, 4, 6, 0, 2)
1034 1035
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
1036 1037
	subcc		%o3, 0x10, %o3
	bne,pt		%xcc, 1b
1038
	 add		%o2, 0x10, %o2
1039 1040
	std		%f4, [%o4 + 0x00]
	std		%f6, [%o4 + 0x08]
1041 1042
	retl
	 nop
1043
ENDPROC(aes_sparc64_cbc_encrypt_256)
1044

1045 1046 1047
	.align		32
ENTRY(aes_sparc64_cbc_decrypt_128)
	/* %o0=&key[key_len], %o1=input, %o2=output, %o3=len, %o4=iv */
1048 1049
	ldx		[%o0 - 0x10], %g1
	ldx		[%o0 - 0x08], %g2
1050 1051 1052 1053 1054
	ldx		[%o4 + 0x00], %o0
	ldx		[%o4 + 0x08], %o5
1:	ldx		[%o1 + 0x00], %g3
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
1055 1056 1057 1058
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
1059
	DECRYPT_128(8, 4, 6, 0, 2)
1060
	MOVXTOD_O0_F0
1061
	MOVXTOD_O5_F2
1062
	xor		%g1, %g3, %o0
1063
	xor		%g2, %g7, %o5
1064 1065
	fxor		%f4, %f0, %f4
	fxor		%f6, %f2, %f6
1066 1067 1068 1069 1070 1071 1072
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
	subcc		%o3, 0x10, %o3
	bne,pt		%xcc, 1b
	 add		%o2, 0x10, %o2
	stx		%o0, [%o4 + 0x00]
	stx		%o5, [%o4 + 0x08]
1073 1074
	retl
	 nop
1075
ENDPROC(aes_sparc64_cbc_decrypt_128)
1076

1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
	.align		32
ENTRY(aes_sparc64_cbc_decrypt_192)
	/* %o0=&key[key_len], %o1=input, %o2=output, %o3=len, %o4=iv */
	ldx		[%o0 - 0x10], %g1
	ldx		[%o0 - 0x08], %g2
	ldx		[%o4 + 0x00], %o0
	ldx		[%o4 + 0x08], %o5
1:	ldx		[%o1 + 0x00], %g3
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
1087 1088 1089 1090
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
1091
	DECRYPT_192(8, 4, 6, 0, 2)
1092
	MOVXTOD_O0_F0
1093
	MOVXTOD_O5_F2
1094
	xor		%g1, %g3, %o0
1095
	xor		%g2, %g7, %o5
1096 1097
	fxor		%f4, %f0, %f4
	fxor		%f6, %f2, %f6
1098 1099 1100
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
	subcc		%o3, 0x10, %o3
1101
	bne,pt		%xcc, 1b
1102 1103 1104
	 add		%o2, 0x10, %o2
	stx		%o0, [%o4 + 0x00]
	stx		%o5, [%o4 + 0x08]
1105 1106
	retl
	 nop
1107
ENDPROC(aes_sparc64_cbc_decrypt_192)
1108

1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
	.align		32
ENTRY(aes_sparc64_cbc_decrypt_256)
	/* %o0=&key[key_len], %o1=input, %o2=output, %o3=len, %o4=iv */
	ldx		[%o0 - 0x10], %g1
	ldx		[%o0 - 0x08], %g2
	ldx		[%o4 + 0x00], %o0
	ldx		[%o4 + 0x08], %o5
1:	ldx		[%o1 + 0x00], %g3
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
1119 1120 1121 1122
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
1123
	DECRYPT_256(8, 4, 6, 0, 2)
1124
	MOVXTOD_O0_F0
1125
	MOVXTOD_O5_F2
1126
	xor		%g1, %g3, %o0
1127
	xor		%g2, %g7, %o5
1128 1129
	fxor		%f4, %f0, %f4
	fxor		%f6, %f2, %f6
1130 1131 1132 1133 1134 1135 1136
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
	subcc		%o3, 0x10, %o3
	bne,pt		%xcc, 1b
	 add		%o2, 0x10, %o2
	stx		%o0, [%o4 + 0x00]
	stx		%o5, [%o4 + 0x08]
1137 1138
	retl
	 nop
1139
ENDPROC(aes_sparc64_cbc_decrypt_256)