12#include <botan/internal/aes.h>
14#include <botan/compiler.h>
15#include <botan/internal/cpuid.h>
31 const Altivec8x16 mask = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
33 return vec_perm(src, zero, mask);
44 return reinterpret_cast<Altivec64x2>(reverse_vec(vec_vsx_ld(0, src)));
48 vec_vsx_st(reverse_vec(
reinterpret_cast<Altivec8x16>(src)), 0, dest);
53 store_block(B1, out + 16);
54 store_block(B2, out + 16 * 2);
55 store_block(B3, out + 16 * 3);
58#define AES_XOR_4(B0, B1, B2, B3, K) \
60 B0 = vec_xor(B0, K); \
61 B1 = vec_xor(B1, K); \
62 B2 = vec_xor(B2, K); \
63 B3 = vec_xor(B3, K); \
58#define AES_XOR_4(B0, B1, B2, B3, K) \ …
66#define AES_ENCRYPT_4(B0, B1, B2, B3, K) \
68 B0 = __builtin_crypto_vcipher(B0, K); \
69 B1 = __builtin_crypto_vcipher(B1, K); \
70 B2 = __builtin_crypto_vcipher(B2, K); \
71 B3 = __builtin_crypto_vcipher(B3, K); \
66#define AES_ENCRYPT_4(B0, B1, B2, B3, K) \ …
74#define AES_ENCRYPT_4_LAST(B0, B1, B2, B3, K) \
76 B0 = __builtin_crypto_vcipherlast(B0, K); \
77 B1 = __builtin_crypto_vcipherlast(B1, K); \
78 B2 = __builtin_crypto_vcipherlast(B2, K); \
79 B3 = __builtin_crypto_vcipherlast(B3, K); \
74#define AES_ENCRYPT_4_LAST(B0, B1, B2, B3, K) \ …
82#define AES_DECRYPT_4(B0, B1, B2, B3, K) \
84 B0 = __builtin_crypto_vncipher(B0, K); \
85 B1 = __builtin_crypto_vncipher(B1, K); \
86 B2 = __builtin_crypto_vncipher(B2, K); \
87 B3 = __builtin_crypto_vncipher(B3, K); \
82#define AES_DECRYPT_4(B0, B1, B2, B3, K) \ …
90#define AES_DECRYPT_4_LAST(B0, B1, B2, B3, K) \
92 B0 = __builtin_crypto_vncipherlast(B0, K); \
93 B1 = __builtin_crypto_vncipherlast(B1, K); \
94 B2 = __builtin_crypto_vncipherlast(B2, K); \
95 B3 = __builtin_crypto_vncipherlast(B3, K); \
90#define AES_DECRYPT_4_LAST(B0, B1, B2, B3, K) \ …
100BOTAN_FUNC_ISA(
"crypto,vsx") void AES_128::hw_aes_encrypt_n(const uint8_t in[], uint8_t out[],
size_t blocks)
const {
131 store_blocks(B0, B1, B2, B3, out);
138 for(
size_t i = 0; i != blocks; ++i) {
142 B = __builtin_crypto_vcipher(B, K1);
143 B = __builtin_crypto_vcipher(B, K2);
144 B = __builtin_crypto_vcipher(B, K3);
145 B = __builtin_crypto_vcipher(B, K4);
146 B = __builtin_crypto_vcipher(B, K5);
147 B = __builtin_crypto_vcipher(B, K6);
148 B = __builtin_crypto_vcipher(B, K7);
149 B = __builtin_crypto_vcipher(B, K8);
150 B = __builtin_crypto_vcipher(B, K9);
151 B = __builtin_crypto_vcipherlast(B, K10);
160BOTAN_FUNC_ISA(
"crypto,vsx") void AES_128::hw_aes_decrypt_n(const uint8_t in[], uint8_t out[],
size_t blocks)
const {
191 store_blocks(B0, B1, B2, B3, out);
198 for(
size_t i = 0; i != blocks; ++i) {
202 B = __builtin_crypto_vncipher(B, K1);
203 B = __builtin_crypto_vncipher(B, K2);
204 B = __builtin_crypto_vncipher(B, K3);
205 B = __builtin_crypto_vncipher(B, K4);
206 B = __builtin_crypto_vncipher(B, K5);
207 B = __builtin_crypto_vncipher(B, K6);
208 B = __builtin_crypto_vncipher(B, K7);
209 B = __builtin_crypto_vncipher(B, K8);
210 B = __builtin_crypto_vncipher(B, K9);
211 B = __builtin_crypto_vncipherlast(B, K10);
220BOTAN_FUNC_ISA(
"crypto,vsx") void AES_192::hw_aes_encrypt_n(const uint8_t in[], uint8_t out[],
size_t blocks)
const {
255 store_blocks(B0, B1, B2, B3, out);
262 for(
size_t i = 0; i != blocks; ++i) {
266 B = __builtin_crypto_vcipher(B, K1);
267 B = __builtin_crypto_vcipher(B, K2);
268 B = __builtin_crypto_vcipher(B, K3);
269 B = __builtin_crypto_vcipher(B, K4);
270 B = __builtin_crypto_vcipher(B, K5);
271 B = __builtin_crypto_vcipher(B, K6);
272 B = __builtin_crypto_vcipher(B, K7);
273 B = __builtin_crypto_vcipher(B, K8);
274 B = __builtin_crypto_vcipher(B, K9);
275 B = __builtin_crypto_vcipher(B, K10);
276 B = __builtin_crypto_vcipher(B, K11);
277 B = __builtin_crypto_vcipherlast(B, K12);
286BOTAN_FUNC_ISA(
"crypto,vsx") void AES_192::hw_aes_decrypt_n(const uint8_t in[], uint8_t out[],
size_t blocks)
const {
321 store_blocks(B0, B1, B2, B3, out);
328 for(
size_t i = 0; i != blocks; ++i) {
332 B = __builtin_crypto_vncipher(B, K1);
333 B = __builtin_crypto_vncipher(B, K2);
334 B = __builtin_crypto_vncipher(B, K3);
335 B = __builtin_crypto_vncipher(B, K4);
336 B = __builtin_crypto_vncipher(B, K5);
337 B = __builtin_crypto_vncipher(B, K6);
338 B = __builtin_crypto_vncipher(B, K7);
339 B = __builtin_crypto_vncipher(B, K8);
340 B = __builtin_crypto_vncipher(B, K9);
341 B = __builtin_crypto_vncipher(B, K10);
342 B = __builtin_crypto_vncipher(B, K11);
343 B = __builtin_crypto_vncipherlast(B, K12);
352BOTAN_FUNC_ISA(
"crypto,vsx") void AES_256::hw_aes_encrypt_n(const uint8_t in[], uint8_t out[],
size_t blocks)
const {
391 store_blocks(B0, B1, B2, B3, out);
398 for(
size_t i = 0; i != blocks; ++i) {
402 B = __builtin_crypto_vcipher(B, K1);
403 B = __builtin_crypto_vcipher(B, K2);
404 B = __builtin_crypto_vcipher(B, K3);
405 B = __builtin_crypto_vcipher(B, K4);
406 B = __builtin_crypto_vcipher(B, K5);
407 B = __builtin_crypto_vcipher(B, K6);
408 B = __builtin_crypto_vcipher(B, K7);
409 B = __builtin_crypto_vcipher(B, K8);
410 B = __builtin_crypto_vcipher(B, K9);
411 B = __builtin_crypto_vcipher(B, K10);
412 B = __builtin_crypto_vcipher(B, K11);
413 B = __builtin_crypto_vcipher(B, K12);
414 B = __builtin_crypto_vcipher(B, K13);
415 B = __builtin_crypto_vcipherlast(B, K14);
424BOTAN_FUNC_ISA(
"crypto,vsx") void AES_256::hw_aes_decrypt_n(const uint8_t in[], uint8_t out[],
size_t blocks)
const {
463 store_blocks(B0, B1, B2, B3, out);
470 for(
size_t i = 0; i != blocks; ++i) {
474 B = __builtin_crypto_vncipher(B, K1);
475 B = __builtin_crypto_vncipher(B, K2);
476 B = __builtin_crypto_vncipher(B, K3);
477 B = __builtin_crypto_vncipher(B, K4);
478 B = __builtin_crypto_vncipher(B, K5);
479 B = __builtin_crypto_vncipher(B, K6);
480 B = __builtin_crypto_vncipher(B, K7);
481 B = __builtin_crypto_vncipher(B, K8);
482 B = __builtin_crypto_vncipher(B, K9);
483 B = __builtin_crypto_vncipher(B, K10);
484 B = __builtin_crypto_vncipher(B, K11);
485 B = __builtin_crypto_vncipher(B, K12);
486 B = __builtin_crypto_vncipher(B, K13);
487 B = __builtin_crypto_vncipherlast(B, K14);
498#undef AES_ENCRYPT_4_LAST
500#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