aes_asm.S 33.3 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_F0		\
	.word	0x81b0230d;
49 50
#define MOVXTOD_O5_F2		\
	.word	0x85b0230d;
51 52 53 54
#define MOVXTOD_G3_F60		\
	.word	0xbbb02303;
#define MOVXTOD_G7_F62		\
	.word	0xbfb02307;
55 56 57 58 59 60 61

#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)

62 63 64 65 66 67 68 69 70 71
#define ENCRYPT_TWO_ROUNDS_2(KEY_BASE, I0, I1, I2, I3, T0, T1, T2, T3) \
	AES_EROUND01(KEY_BASE +  0, I0, I1, T0) \
	AES_EROUND23(KEY_BASE +  2, I0, I1, T1) \
	AES_EROUND01(KEY_BASE +  0, I2, I3, T2) \
	AES_EROUND23(KEY_BASE +  2, I2, I3, T3) \
	AES_EROUND01(KEY_BASE +  4, T0, T1, I0) \
	AES_EROUND23(KEY_BASE +  6, T0, T1, I1) \
	AES_EROUND01(KEY_BASE +  4, T2, T3, I2) \
	AES_EROUND23(KEY_BASE +  6, T2, T3, I3)

72 73 74 75 76 77
#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)

78 79 80 81 82 83 84 85 86 87
#define ENCRYPT_TWO_ROUNDS_LAST_2(KEY_BASE, I0, I1, I2, I3, T0, T1, T2, T3) \
	AES_EROUND01(KEY_BASE +  0, I0, I1, T0) \
	AES_EROUND23(KEY_BASE +  2, I0, I1, T1) \
	AES_EROUND01(KEY_BASE +  0, I2, I3, T2) \
	AES_EROUND23(KEY_BASE +  2, I2, I3, T3) \
	AES_EROUND01_L(KEY_BASE +  4, T0, T1, I0) \
	AES_EROUND23_L(KEY_BASE +  6, T0, T1, I1) \
	AES_EROUND01_L(KEY_BASE +  4, T2, T3, I2) \
	AES_EROUND23_L(KEY_BASE +  6, T2, T3, I3)

88 89 90 91 92 93 94 95
	/* 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)

96 97 98 99 100 101 102
#define ENCRYPT_128_2(KEY_BASE, I0, I1, I2, I3, T0, T1, T2, T3) \
	ENCRYPT_TWO_ROUNDS_2(KEY_BASE +  0, I0, I1, I2, I3, T0, T1, T2, T3) \
	ENCRYPT_TWO_ROUNDS_2(KEY_BASE +  8, I0, I1, I2, I3, T0, T1, T2, T3) \
	ENCRYPT_TWO_ROUNDS_2(KEY_BASE + 16, I0, I1, I2, I3, T0, T1, T2, T3) \
	ENCRYPT_TWO_ROUNDS_2(KEY_BASE + 24, I0, I1, I2, I3, T0, T1, T2, T3) \
	ENCRYPT_TWO_ROUNDS_LAST_2(KEY_BASE + 32, I0, I1, I2, I3, T0, T1, T2, T3)

103 104 105 106 107 108 109 110 111
	/* 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)

112 113 114 115 116 117 118 119
#define ENCRYPT_192_2(KEY_BASE, I0, I1, I2, I3, T0, T1, T2, T3) \
	ENCRYPT_TWO_ROUNDS_2(KEY_BASE +  0, I0, I1, I2, I3, T0, T1, T2, T3) \
	ENCRYPT_TWO_ROUNDS_2(KEY_BASE +  8, I0, I1, I2, I3, T0, T1, T2, T3) \
	ENCRYPT_TWO_ROUNDS_2(KEY_BASE + 16, I0, I1, I2, I3, T0, T1, T2, T3) \
	ENCRYPT_TWO_ROUNDS_2(KEY_BASE + 24, I0, I1, I2, I3, T0, T1, T2, T3) \
	ENCRYPT_TWO_ROUNDS_2(KEY_BASE + 32, I0, I1, I2, I3, T0, T1, T2, T3) \
	ENCRYPT_TWO_ROUNDS_LAST_2(KEY_BASE + 40, I0, I1, I2, I3, T0, T1, T2, T3)

120 121 122 123 124 125 126 127 128 129
	/* 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)

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
#define ENCRYPT_256_TWO_ROUNDS_2(KEY_BASE, I0, I1, I2, I3, TMP_BASE) \
	ENCRYPT_TWO_ROUNDS_2(KEY_BASE, I0, I1, I2, I3, \
			     TMP_BASE + 0, TMP_BASE + 2, TMP_BASE + 4, TMP_BASE + 6)

#define ENCRYPT_256_2(KEY_BASE, I0, I1, I2, I3) \
	ENCRYPT_256_TWO_ROUNDS_2(KEY_BASE +  0, I0, I1, I2, I3, KEY_BASE + 48) \
	ldd	[%o0 + 0xd0], %f56; \
	ldd	[%o0 + 0xd8], %f58; \
	ENCRYPT_256_TWO_ROUNDS_2(KEY_BASE +  8, I0, I1, I2, I3, KEY_BASE +  0) \
	ldd	[%o0 + 0xe0], %f60; \
	ldd	[%o0 + 0xe8], %f62; \
	ENCRYPT_256_TWO_ROUNDS_2(KEY_BASE + 16, I0, I1, I2, I3, KEY_BASE +  0) \
	ENCRYPT_256_TWO_ROUNDS_2(KEY_BASE + 24, I0, I1, I2, I3, KEY_BASE +  0) \
	ENCRYPT_256_TWO_ROUNDS_2(KEY_BASE + 32, I0, I1, I2, I3, KEY_BASE +  0) \
	ENCRYPT_256_TWO_ROUNDS_2(KEY_BASE + 40, I0, I1, I2, I3, KEY_BASE +  0) \
	AES_EROUND01(KEY_BASE +  48, I0, I1, KEY_BASE + 0) \
	AES_EROUND23(KEY_BASE +  50, I0, I1, KEY_BASE + 2) \
	AES_EROUND01(KEY_BASE +  48, I2, I3, KEY_BASE + 4) \
	AES_EROUND23(KEY_BASE +  50, I2, I3, KEY_BASE + 6) \
	AES_EROUND01_L(KEY_BASE +  52, KEY_BASE + 0, KEY_BASE + 2, I0) \
	AES_EROUND23_L(KEY_BASE +  54, KEY_BASE + 0, KEY_BASE + 2, I1) \
	ldd	[%o0 + 0x10], %f8; \
	ldd	[%o0 + 0x18], %f10; \
	AES_EROUND01_L(KEY_BASE +  52, KEY_BASE + 4, KEY_BASE + 6, I2) \
	AES_EROUND23_L(KEY_BASE +  54, KEY_BASE + 4, KEY_BASE + 6, I3) \
	ldd	[%o0 + 0x20], %f12; \
	ldd	[%o0 + 0x28], %f14;

158 159 160 161 162
#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)
163

164 165 166 167 168
#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)
169 170

	/* 10 rounds */
171 172 173 174 175 176
#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)
177 178

	/* 12 rounds */
179 180 181 182 183 184 185
#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)
186 187

	/* 14 rounds */
188 189 190 191 192 193 194 195 196 197
#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
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 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
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)

387 388 389
	.align		32
ENTRY(aes_sparc64_encrypt_128)
	/* %o0=key, %o1=input, %o2=output */
390 391 392 393 394 395 396
	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
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
	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
417
	fxor		%f8, %f4, %f4
418 419 420 421 422 423 424 425 426
	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)
427

428 429 430 431 432 433 434 435
	.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
436

437 438
	ldd		[%o0 + 0x00], %f8
	ldd		[%o0 + 0x08], %f10
439

440 441
	fxor		%f8, %f4, %f4
	fxor		%f10, %f6, %f6
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 470 471 472 473 474 475 476 477 478 479 480 481

	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
482
ENDPROC(aes_sparc64_encrypt_192)
483

484 485 486
	.align		32
ENTRY(aes_sparc64_encrypt_256)
	/* %o0=key, %o1=input, %o2=output */
487 488 489 490 491 492
	VISEntry
	ld		[%o1 + 0x00], %f4
	ld		[%o1 + 0x04], %f5
	ld		[%o1 + 0x08], %f6
	ld		[%o1 + 0x0c], %f7

493 494
	ldd		[%o0 + 0x00], %f8
	ldd		[%o0 + 0x08], %f10
495

496 497
	fxor		%f8, %f4, %f4
	fxor		%f10, %f6, %f6
498

499
	ldd		[%o0 + 0x10], %f8
500

501 502 503 504
	ldd		[%o0 + 0x18], %f10
	ldd		[%o0 + 0x20], %f12
	ldd		[%o0 + 0x28], %f14
	add		%o0, 0x20, %o0
505

506
	ENCRYPT_TWO_ROUNDS(8, 4, 6, 0, 2)
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
	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)
539 540 541 542 543 544 545 546

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

	retl
	 VISExit
547
ENDPROC(aes_sparc64_encrypt_256)
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 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 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 703 704 705 706 707 708 709 710 711 712 713
	.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)
714
	/* %o0=key */
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
	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)
738

739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
	.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)
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
	/* %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
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
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)
831

832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
	.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 */
901
	ldx		[%o0 + 0x00], %g1
902 903 904
	subcc		%o3, 0x10, %o3
	be		10f
	 ldx		[%o0 + 0x08], %g2
905
1:	ldx		[%o1 + 0x00], %g3
906
	ldx		[%o1 + 0x08], %g7
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
	ldx		[%o1 + 0x10], %o4
	ldx		[%o1 + 0x18], %o5
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
	xor		%g1, %o4, %g3
	xor		%g2, %o5, %g7
	MOVXTOD_G3_F60
	MOVXTOD_G7_F62
	ENCRYPT_128_2(8, 4, 6, 60, 62, 0, 2, 56, 58)
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
	std		%f60, [%o2 + 0x10]
	std		%f62, [%o2 + 0x18]
	sub		%o3, 0x20, %o3
	add		%o1, 0x20, %o1
	brgz		%o3, 1b
	 add		%o2, 0x20, %o2
	brlz,pt		%o3, 11f
	 nop
10:	ldx		[%o1 + 0x00], %g3
	ldx		[%o1 + 0x08], %g7
930 931 932 933
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
934
	ENCRYPT_128(8, 4, 6, 0, 2)
935 936
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
937
11:	retl
938
	 nop
939
ENDPROC(aes_sparc64_ecb_encrypt_128)
940

941 942 943 944
	.align		32
ENTRY(aes_sparc64_ecb_encrypt_192)
	/* %o0=key, %o1=input, %o2=output, %o3=len */
	ldx		[%o0 + 0x00], %g1
945 946 947
	subcc		%o3, 0x10, %o3
	be		10f
	 ldx		[%o0 + 0x08], %g2
948
1:	ldx		[%o1 + 0x00], %g3
949
	ldx		[%o1 + 0x08], %g7
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
	ldx		[%o1 + 0x10], %o4
	ldx		[%o1 + 0x18], %o5
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
	xor		%g1, %o4, %g3
	xor		%g2, %o5, %g7
	MOVXTOD_G3_F60
	MOVXTOD_G7_F62
	ENCRYPT_192_2(8, 4, 6, 60, 62, 0, 2, 56, 58)
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
	std		%f60, [%o2 + 0x10]
	std		%f62, [%o2 + 0x18]
	sub		%o3, 0x20, %o3
	add		%o1, 0x20, %o1
	brgz		%o3, 1b
	 add		%o2, 0x20, %o2
	brlz,pt		%o3, 11f
	 nop
10:	ldx		[%o1 + 0x00], %g3
	ldx		[%o1 + 0x08], %g7
973 974 975 976 977 978 979
	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]
980
11:	retl
981
	 nop
982
ENDPROC(aes_sparc64_ecb_encrypt_192)
983

984 985 986 987
	.align		32
ENTRY(aes_sparc64_ecb_encrypt_256)
	/* %o0=key, %o1=input, %o2=output, %o3=len */
	ldx		[%o0 + 0x00], %g1
988 989 990
	subcc		%o3, 0x10, %o3
	be		10f
	 ldx		[%o0 + 0x08], %g2
991
1:	ldx		[%o1 + 0x00], %g3
992
	ldx		[%o1 + 0x08], %g7
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
	ldx		[%o1 + 0x10], %o4
	ldx		[%o1 + 0x18], %o5
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
	xor		%g1, %o4, %g3
	xor		%g2, %o5, %g7
	MOVXTOD_G3_F0
	MOVXTOD_G7_F2
	ENCRYPT_256_2(8, 4, 6, 0, 2)
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
	std		%f0, [%o2 + 0x10]
	std		%f2, [%o2 + 0x18]
	sub		%o3, 0x20, %o3
	add		%o1, 0x20, %o1
	brgz		%o3, 1b
	 add		%o2, 0x20, %o2
	brlz,pt		%o3, 11f
	 nop
10:	ldx		[%o1 + 0x00], %g3
	ldx		[%o1 + 0x08], %g7
1016 1017 1018 1019
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
1020
	ENCRYPT_256(8, 4, 6, 0, 2)
1021 1022
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
1023
11:	retl
1024
	 nop
1025
ENDPROC(aes_sparc64_ecb_encrypt_256)
1026

1027 1028 1029
	.align		32
ENTRY(aes_sparc64_ecb_decrypt_128)
	/* %o0=&key[key_len], %o1=input, %o2=output, %o3=len */
1030 1031
	ldx		[%o0 - 0x10], %g1
	ldx		[%o0 - 0x08], %g2
1032
1:	ldx		[%o1 + 0x00], %g3
1033 1034 1035 1036 1037 1038
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
1039
	DECRYPT_128(8, 4, 6, 0, 2)
1040 1041
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
1042 1043
	subcc		%o3, 0x10, %o3
	bne,pt		%xcc, 1b
1044 1045 1046
	 add		%o2, 0x10, %o2
	retl
	 nop
1047
ENDPROC(aes_sparc64_ecb_decrypt_128)
1048

1049 1050 1051 1052 1053 1054
	.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
1055 1056 1057 1058 1059 1060
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
1061
	DECRYPT_192(8, 4, 6, 0, 2)
1062 1063
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
1064
	subcc		%o3, 0x10, %o3
1065 1066 1067 1068
	bne,pt		%xcc, 1b
	 add		%o2, 0x10, %o2
	retl
	 nop
1069
ENDPROC(aes_sparc64_ecb_decrypt_192)
1070

1071 1072 1073 1074 1075 1076
	.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
1077 1078 1079 1080 1081 1082
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
1083
	DECRYPT_256(8, 4, 6, 0, 2)
1084 1085
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
1086 1087
	subcc		%o3, 0x10, %o3
	bne,pt		%xcc, 1b
1088 1089 1090
	 add		%o2, 0x10, %o2
	retl
	 nop
1091
ENDPROC(aes_sparc64_ecb_decrypt_256)
1092

1093 1094 1095 1096 1097
	.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
1098 1099
	ldx		[%o0 + 0x00], %g1
	ldx		[%o0 + 0x08], %g2
1100
1:	ldx		[%o1 + 0x00], %g3
1101 1102 1103 1104 1105 1106 1107 1108
	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
1109
	ENCRYPT_128(8, 4, 6, 0, 2)
1110 1111
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
1112 1113
	subcc		%o3, 0x10, %o3
	bne,pt		%xcc, 1b
1114
	 add		%o2, 0x10, %o2
1115 1116
	std		%f4, [%o4 + 0x00]
	std		%f6, [%o4 + 0x08]
1117 1118
	retl
	 nop
1119
ENDPROC(aes_sparc64_cbc_encrypt_128)
1120

1121 1122 1123 1124 1125 1126 1127 1128
	.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
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139
	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]
1140
	subcc		%o3, 0x10, %o3
1141 1142
	bne,pt		%xcc, 1b
	 add		%o2, 0x10, %o2
1143 1144
	std		%f4, [%o4 + 0x00]
	std		%f6, [%o4 + 0x08]
1145 1146
	retl
	 nop
1147
ENDPROC(aes_sparc64_cbc_encrypt_192)
1148

1149 1150 1151 1152 1153 1154 1155 1156
	.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
1157 1158 1159 1160 1161 1162 1163 1164
	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
1165
	ENCRYPT_256(8, 4, 6, 0, 2)
1166 1167
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
1168 1169
	subcc		%o3, 0x10, %o3
	bne,pt		%xcc, 1b
1170
	 add		%o2, 0x10, %o2
1171 1172
	std		%f4, [%o4 + 0x00]
	std		%f6, [%o4 + 0x08]
1173 1174
	retl
	 nop
1175
ENDPROC(aes_sparc64_cbc_encrypt_256)
1176

1177 1178 1179
	.align		32
ENTRY(aes_sparc64_cbc_decrypt_128)
	/* %o0=&key[key_len], %o1=input, %o2=output, %o3=len, %o4=iv */
1180 1181
	ldx		[%o0 - 0x10], %g1
	ldx		[%o0 - 0x08], %g2
1182 1183 1184 1185 1186
	ldx		[%o4 + 0x00], %o0
	ldx		[%o4 + 0x08], %o5
1:	ldx		[%o1 + 0x00], %g3
	ldx		[%o1 + 0x08], %g7
	add		%o1, 0x10, %o1
1187 1188 1189 1190
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
1191
	DECRYPT_128(8, 4, 6, 0, 2)
1192
	MOVXTOD_O0_F0
1193
	MOVXTOD_O5_F2
1194
	xor		%g1, %g3, %o0
1195
	xor		%g2, %g7, %o5
1196 1197
	fxor		%f4, %f0, %f4
	fxor		%f6, %f2, %f6
1198 1199 1200 1201 1202 1203 1204
	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]
1205 1206
	retl
	 nop
1207
ENDPROC(aes_sparc64_cbc_decrypt_128)
1208

1209 1210 1211 1212 1213 1214 1215 1216 1217 1218
	.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
1219 1220 1221 1222
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
1223
	DECRYPT_192(8, 4, 6, 0, 2)
1224
	MOVXTOD_O0_F0
1225
	MOVXTOD_O5_F2
1226
	xor		%g1, %g3, %o0
1227
	xor		%g2, %g7, %o5
1228 1229
	fxor		%f4, %f0, %f4
	fxor		%f6, %f2, %f6
1230 1231 1232
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
	subcc		%o3, 0x10, %o3
1233
	bne,pt		%xcc, 1b
1234 1235 1236
	 add		%o2, 0x10, %o2
	stx		%o0, [%o4 + 0x00]
	stx		%o5, [%o4 + 0x08]
1237 1238
	retl
	 nop
1239
ENDPROC(aes_sparc64_cbc_decrypt_192)
1240

1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
	.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
1251 1252 1253 1254
	xor		%g1, %g3, %g3
	xor		%g2, %g7, %g7
	MOVXTOD_G3_F4
	MOVXTOD_G7_F6
1255
	DECRYPT_256(8, 4, 6, 0, 2)
1256
	MOVXTOD_O0_F0
1257
	MOVXTOD_O5_F2
1258
	xor		%g1, %g3, %o0
1259
	xor		%g2, %g7, %o5
1260 1261
	fxor		%f4, %f0, %f4
	fxor		%f6, %f2, %f6
1262 1263 1264 1265 1266 1267 1268
	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]
1269 1270
	retl
	 nop
1271
ENDPROC(aes_sparc64_cbc_decrypt_256)
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364

	.align		32
ENTRY(aes_sparc64_ctr_crypt_128)
	/* %o0=key, %o1=input, %o2=output, %o3=len, %o4=IV */
	ldx		[%o4 + 0x00], %g3
	ldx		[%o4 + 0x08], %g7
	ldx		[%o0 + 0x00], %g1
	ldx		[%o0 + 0x08], %g2
1:	xor		%g1, %g3, %o5
	MOVXTOD_O5_F0
	xor		%g2, %g7, %o5
	MOVXTOD_O5_F2
	add		%g7, 1, %g7
	add		%g3, 1, %o5
	movrz		%g7, %o5, %g3
	ENCRYPT_128(8, 0, 2, 4, 6)
	ldd		[%o1 + 0x00], %f4
	ldd		[%o1 + 0x08], %f6
	fxor		%f4, %f0, %f4
	fxor		%f6, %f2, %f6
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
	subcc		%o3, 0x10, %o3
	add		%o1, 0x10, %o1
	bne,pt		%xcc, 1b
	 add		%o2, 0x10, %o2
	stx		%g3, [%o4 + 0x00]
	stx		%g7, [%o4 + 0x08]
	retl
	 nop
ENDPROC(aes_sparc64_ctr_crypt_128)

	.align		32
ENTRY(aes_sparc64_ctr_crypt_192)
	/* %o0=key, %o1=input, %o2=output, %o3=len, %o4=IV */
	ldx		[%o4 + 0x00], %g3
	ldx		[%o4 + 0x08], %g7
	ldx		[%o0 + 0x00], %g1
	ldx		[%o0 + 0x08], %g2
1:	xor		%g1, %g3, %o5
	MOVXTOD_O5_F0
	xor		%g2, %g7, %o5
	MOVXTOD_O5_F2
	add		%g7, 1, %g7
	add		%g3, 1, %o5
	movrz		%g7, %o5, %g3
	ENCRYPT_192(8, 0, 2, 4, 6)
	ldd		[%o1 + 0x00], %f4
	ldd		[%o1 + 0x08], %f6
	fxor		%f4, %f0, %f4
	fxor		%f6, %f2, %f6
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
	subcc		%o3, 0x10, %o3
	add		%o1, 0x10, %o1
	bne,pt		%xcc, 1b
	 add		%o2, 0x10, %o2
	stx		%g3, [%o4 + 0x00]
	stx		%g7, [%o4 + 0x08]
	retl
	 nop
ENDPROC(aes_sparc64_ctr_crypt_192)

	.align		32
ENTRY(aes_sparc64_ctr_crypt_256)
	/* %o0=key, %o1=input, %o2=output, %o3=len, %o4=IV */
	ldx		[%o4 + 0x00], %g3
	ldx		[%o4 + 0x08], %g7
	ldx		[%o0 + 0x00], %g1
	ldx		[%o0 + 0x08], %g2
1:	xor		%g1, %g3, %o5
	MOVXTOD_O5_F0
	xor		%g2, %g7, %o5
	MOVXTOD_O5_F2
	add		%g7, 1, %g7
	add		%g3, 1, %o5
	movrz		%g7, %o5, %g3
	ENCRYPT_256(8, 0, 2, 4, 6)
	ldd		[%o1 + 0x00], %f4
	ldd		[%o1 + 0x08], %f6
	fxor		%f4, %f0, %f4
	fxor		%f6, %f2, %f6
	std		%f4, [%o2 + 0x00]
	std		%f6, [%o2 + 0x08]
	subcc		%o3, 0x10, %o3
	add		%o1, 0x10, %o1
	bne,pt		%xcc, 1b
	 add		%o2, 0x10, %o2
	stx		%g3, [%o4 + 0x00]
	stx		%g7, [%o4 + 0x08]
	retl
	 nop
ENDPROC(aes_sparc64_ctr_crypt_256)