12#include <botan/internal/aes.h>
14#include <botan/internal/cpuid.h>
30 const Altivec8x16 mask = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
32 return vec_perm(src, zero, mask);
43 return reinterpret_cast<Altivec64x2>(reverse_vec(vec_vsx_ld(0, src)));
47 vec_vsx_st(reverse_vec(
reinterpret_cast<Altivec8x16>(src)), 0, dest);
52 store_block(B1, out + 16);
53 store_block(B2, out + 16 * 2);
54 store_block(B3, out + 16 * 3);
57#define AES_XOR_4(B0, B1, B2, B3, K) \
59 B0 = vec_xor(B0, K); \
60 B1 = vec_xor(B1, K); \
61 B2 = vec_xor(B2, K); \
62 B3 = vec_xor(B3, K); \
65#define AES_ENCRYPT_4(B0, B1, B2, B3, K) \
67 B0 = __builtin_crypto_vcipher(B0, K); \
68 B1 = __builtin_crypto_vcipher(B1, K); \
69 B2 = __builtin_crypto_vcipher(B2, K); \
70 B3 = __builtin_crypto_vcipher(B3, K); \
73#define AES_ENCRYPT_4_LAST(B0, B1, B2, B3, K) \
75 B0 = __builtin_crypto_vcipherlast(B0, K); \
76 B1 = __builtin_crypto_vcipherlast(B1, K); \
77 B2 = __builtin_crypto_vcipherlast(B2, K); \
78 B3 = __builtin_crypto_vcipherlast(B3, K); \
81#define AES_DECRYPT_4(B0, B1, B2, B3, K) \
83 B0 = __builtin_crypto_vncipher(B0, K); \
84 B1 = __builtin_crypto_vncipher(B1, K); \
85 B2 = __builtin_crypto_vncipher(B2, K); \
86 B3 = __builtin_crypto_vncipher(B3, K); \
89#define AES_DECRYPT_4_LAST(B0, B1, B2, B3, K) \
91 B0 = __builtin_crypto_vncipherlast(B0, K); \
92 B1 = __builtin_crypto_vncipherlast(B1, K); \
93 B2 = __builtin_crypto_vncipherlast(B2, K); \
94 B3 = __builtin_crypto_vncipherlast(B3, K); \
99BOTAN_FUNC_ISA(
"crypto,vsx") void AES_128::hw_aes_encrypt_n(const uint8_t in[], uint8_t out[],
size_t blocks)
const {
130 store_blocks(B0, B1, B2, B3, out);
137 for(
size_t i = 0; i != blocks; ++i) {
141 B = __builtin_crypto_vcipher(B, K1);
142 B = __builtin_crypto_vcipher(B, K2);
143 B = __builtin_crypto_vcipher(B, K3);
144 B = __builtin_crypto_vcipher(B, K4);
145 B = __builtin_crypto_vcipher(B, K5);
146 B = __builtin_crypto_vcipher(B, K6);
147 B = __builtin_crypto_vcipher(B, K7);
148 B = __builtin_crypto_vcipher(B, K8);
149 B = __builtin_crypto_vcipher(B, K9);
150 B = __builtin_crypto_vcipherlast(B, K10);
159BOTAN_FUNC_ISA(
"crypto,vsx") void AES_128::hw_aes_decrypt_n(const uint8_t in[], uint8_t out[],
size_t blocks)
const {
190 store_blocks(B0, B1, B2, B3, out);
197 for(
size_t i = 0; i != blocks; ++i) {
201 B = __builtin_crypto_vncipher(B, K1);
202 B = __builtin_crypto_vncipher(B, K2);
203 B = __builtin_crypto_vncipher(B, K3);
204 B = __builtin_crypto_vncipher(B, K4);
205 B = __builtin_crypto_vncipher(B, K5);
206 B = __builtin_crypto_vncipher(B, K6);
207 B = __builtin_crypto_vncipher(B, K7);
208 B = __builtin_crypto_vncipher(B, K8);
209 B = __builtin_crypto_vncipher(B, K9);
210 B = __builtin_crypto_vncipherlast(B, K10);
219BOTAN_FUNC_ISA(
"crypto,vsx") void AES_192::hw_aes_encrypt_n(const uint8_t in[], uint8_t out[],
size_t blocks)
const {
254 store_blocks(B0, B1, B2, B3, out);
261 for(
size_t i = 0; i != blocks; ++i) {
265 B = __builtin_crypto_vcipher(B, K1);
266 B = __builtin_crypto_vcipher(B, K2);
267 B = __builtin_crypto_vcipher(B, K3);
268 B = __builtin_crypto_vcipher(B, K4);
269 B = __builtin_crypto_vcipher(B, K5);
270 B = __builtin_crypto_vcipher(B, K6);
271 B = __builtin_crypto_vcipher(B, K7);
272 B = __builtin_crypto_vcipher(B, K8);
273 B = __builtin_crypto_vcipher(B, K9);
274 B = __builtin_crypto_vcipher(B, K10);
275 B = __builtin_crypto_vcipher(B, K11);
276 B = __builtin_crypto_vcipherlast(B, K12);
285BOTAN_FUNC_ISA(
"crypto,vsx") void AES_192::hw_aes_decrypt_n(const uint8_t in[], uint8_t out[],
size_t blocks)
const {
320 store_blocks(B0, B1, B2, B3, out);
327 for(
size_t i = 0; i != blocks; ++i) {
331 B = __builtin_crypto_vncipher(B, K1);
332 B = __builtin_crypto_vncipher(B, K2);
333 B = __builtin_crypto_vncipher(B, K3);
334 B = __builtin_crypto_vncipher(B, K4);
335 B = __builtin_crypto_vncipher(B, K5);
336 B = __builtin_crypto_vncipher(B, K6);
337 B = __builtin_crypto_vncipher(B, K7);
338 B = __builtin_crypto_vncipher(B, K8);
339 B = __builtin_crypto_vncipher(B, K9);
340 B = __builtin_crypto_vncipher(B, K10);
341 B = __builtin_crypto_vncipher(B, K11);
342 B = __builtin_crypto_vncipherlast(B, K12);
351BOTAN_FUNC_ISA(
"crypto,vsx") void AES_256::hw_aes_encrypt_n(const uint8_t in[], uint8_t out[],
size_t blocks)
const {
390 store_blocks(B0, B1, B2, B3, out);
397 for(
size_t i = 0; i != blocks; ++i) {
401 B = __builtin_crypto_vcipher(B, K1);
402 B = __builtin_crypto_vcipher(B, K2);
403 B = __builtin_crypto_vcipher(B, K3);
404 B = __builtin_crypto_vcipher(B, K4);
405 B = __builtin_crypto_vcipher(B, K5);
406 B = __builtin_crypto_vcipher(B, K6);
407 B = __builtin_crypto_vcipher(B, K7);
408 B = __builtin_crypto_vcipher(B, K8);
409 B = __builtin_crypto_vcipher(B, K9);
410 B = __builtin_crypto_vcipher(B, K10);
411 B = __builtin_crypto_vcipher(B, K11);
412 B = __builtin_crypto_vcipher(B, K12);
413 B = __builtin_crypto_vcipher(B, K13);
414 B = __builtin_crypto_vcipherlast(B, K14);
423BOTAN_FUNC_ISA(
"crypto,vsx") void AES_256::hw_aes_decrypt_n(const uint8_t in[], uint8_t out[],
size_t blocks)
const {
462 store_blocks(B0, B1, B2, B3, out);
469 for(
size_t i = 0; i != blocks; ++i) {
473 B = __builtin_crypto_vncipher(B, K1);
474 B = __builtin_crypto_vncipher(B, K2);
475 B = __builtin_crypto_vncipher(B, K3);
476 B = __builtin_crypto_vncipher(B, K4);
477 B = __builtin_crypto_vncipher(B, K5);
478 B = __builtin_crypto_vncipher(B, K6);
479 B = __builtin_crypto_vncipher(B, K7);
480 B = __builtin_crypto_vncipher(B, K8);
481 B = __builtin_crypto_vncipher(B, K9);
482 B = __builtin_crypto_vncipher(B, K10);
483 B = __builtin_crypto_vncipher(B, K11);
484 B = __builtin_crypto_vncipher(B, K12);
485 B = __builtin_crypto_vncipher(B, K13);
486 B = __builtin_crypto_vncipherlast(B, K14);
497#undef AES_ENCRYPT_4_LAST
499#undef AES_DECRYPT_4_LAST
#define AES_ENCRYPT_4_LAST(B0, B1, B2, B3, K)
#define AES_ENCRYPT_4(B0, B1, B2, B3, K)
#define AES_XOR_4(B0, B1, B2, B3, K)
#define AES_DECRYPT_4_LAST(B0, B1, B2, B3, K)
#define AES_DECRYPT_4(B0, B1, B2, B3, K)
static bool is_little_endian()
#define BOTAN_FUNC_ISA(isa)
std::unique_ptr< Private_Key > load_key(DataSource &source, const std::function< std::string()> &get_pass)
__vector unsigned long long Altivec64x2
__vector unsigned char Altivec8x16
__vector unsigned int Altivec32x4