22#include "crypto/cipher/blockCipher.hpp"
27#ifdef ANCH_CPU_DETECTION
28#include "device/cpu.hpp"
37# if defined (__GNUC__)
38# define ALIGN16 __attribute__ ( (aligned (16)))
40# define ALIGN16 __declspec (align (16))
49 template<std::
size_t S>
51 ALIGN16 __m128i cipherKey[S];
52 ALIGN16 __m128i decipherKey[S];
66 template<std::
size_t K, std::
size_t R>
70#if defined ANCH_CPU_DETECTION || !defined(ANCH_CPU_AES)
77#ifdef ANCH_CPU_DETECTION
78 uint32_t swKey[4 * (R + 1)];
83 uint32_t swKey[4 * (R + 1)];
97 AES(
const uint8_t key[4*K]);
125 void cipher(
const std::array<uint8_t,16>& input, std::array<uint8_t,16>& output);
133 void decipher(
const std::array<uint8_t,16>& input, std::array<uint8_t,16>& output);
143 void aesniCipher(
const std::array<uint8_t,16>& input, std::array<uint8_t,16>& output);
151 void aesniDecipher(
const std::array<uint8_t,16>& input, std::array<uint8_t,16>& output);
161 __m128i aes128assist(__m128i& temp1, __m128i& temp2);
168 void aesni128ExpandKey(uint8_t key[4 * K]);
177 void aes192assist(__m128i& temp1, __m128i& temp2, __m128i& temp3);
184 void aesni192ExpandKey(uint8_t key[4 * K]);
192 void aes256assist1(__m128i& temp1, __m128i& temp2);
200 void aes256assist2(__m128i& temp1, __m128i& temp3);
207 void aesni256ExpandKey(uint8_t key[4 * K]);
214 void aesniExpandKey(uint8_t key[4 * K]);
217#if defined ANCH_CPU_DETECTION || !defined(ANCH_CPU_AES)
224 void swCipher(
const std::array<uint8_t,16>& input, std::array<uint8_t,16>& output);
232 void swDecipher(
const std::array<uint8_t,16>& input, std::array<uint8_t,16>& output);
239 void expandKey(
const uint8_t key[4 * K]);
249 uint32_t subWord(
const uint32_t& word);
258 uint32_t rotateWord(
const uint32_t& word);
264 void cipherSubBytes();
270 void decipherSubBytes();
275 void cipherShiftRows();
280 void decipherShiftRows();
285 void cipherMixColumns();
290 void decipherMixColumns();
297 void addRoundKey(
const uint32_t& round);
304 template<std::
size_t K, std::
size_t R>
306#ifdef ANCH_CPU_DETECTION
309 std::memcpy(aesKey, key, 4*K);
310 aesniExpandKey(aesKey);
316 std::memcpy(aesKey, key, 4*K);
317 aesniExpandKey(aesKey);
323 template<std::
size_t K, std::
size_t R>
325#ifdef ANCH_CPU_DETECTION
327 std::memcpy(_expKey.hwKey.cipherKey, other._expKey.hwKey.cipherKey, (R + 1) *
sizeof(__m128i));
328 std::memcpy(_expKey.hwKey.decipherKey, other._expKey.hwKey.decipherKey, (R + 1) *
sizeof(__m128i));
330 std::memcpy(_expKey.swKey, other._expKey.swKey, 4 * (R + 1) *
sizeof(uint32_t));
333 std::memcpy(_expKey.hwKey.cipherKey, other._expKey.hwKey.cipherKey, (R + 1) *
sizeof(__m128i));
334 std::memcpy(_expKey.hwKey.decipherKey, other._expKey.hwKey.decipherKey, (R + 1) *
sizeof(__m128i));
336 std::memcpy(_expKey.swKey, other._expKey.swKey, 4 * (R + 1) *
sizeof(uint32_t));
343 template<std::
size_t K, std::
size_t R>
351 template<std::
size_t K, std::
size_t R>
354#ifdef ANCH_CPU_DETECTION
356 aesniCipher(input, output);
358 swCipher(input, output);
361 aesniCipher(input, output);
363 swCipher(input, output);
367 template<std::
size_t K, std::
size_t R>
370#ifdef ANCH_CPU_DETECTION
372 aesniDecipher(input, output);
374 swDecipher(input, output);
377 aesniDecipher(input, output);
379 swDecipher(input, output);
384 template<std::
size_t K, std::
size_t R>
386 AES<K,R>::aesniCipher(
const std::array<uint8_t,16>& input, std::array<uint8_t,16>& output) {
389 ALIGN16 uint8_t in[16];
390 std::memcpy(in, input.data(), 16);
401 tmp = _mm_loadu_si128(
reinterpret_cast<__m128i*
>(in));
402 tmp = _mm_xor_si128(tmp, _expKey.hwKey.cipherKey[0]);
403 for(j = 1 ; j < R ; ++j) {
404 tmp = _mm_aesenc_si128(tmp, _expKey.hwKey.cipherKey[j]);
406 tmp = _mm_aesenclast_si128(tmp, _expKey.hwKey.cipherKey[j]);
407 _mm_storeu_si128(&out, tmp);
408 std::memcpy(output.data(),
reinterpret_cast<uint8_t*
>(&out), 16);
411 template<std::
size_t K, std::
size_t R>
413 AES<K,R>::aesniDecipher(
const std::array<uint8_t,16>& input, std::array<uint8_t,16>& output) {
416 ALIGN16 uint8_t in[16];
417 std::memcpy(in, input.data(), 16);
428 tmp = _mm_loadu_si128(
reinterpret_cast<__m128i*
>(in));
429 tmp = _mm_xor_si128(tmp, _expKey.hwKey.decipherKey[0]);
430 for(j = 1 ; j < R ; ++j) {
431 tmp = _mm_aesdec_si128(tmp, _expKey.hwKey.decipherKey[j]);
433 tmp = _mm_aesdeclast_si128(tmp, _expKey.hwKey.decipherKey[j]);
434 _mm_storeu_si128(&out, tmp);
435 std::memcpy(output.data(),
reinterpret_cast<uint8_t*
>(&out), 16);
438 template<std::
size_t K, std::
size_t R>
440 AES<K,R>::aes128assist(__m128i& temp1, __m128i& temp2) {
442 temp2 = _mm_shuffle_epi32(temp2 ,0xff);
443 temp3 = _mm_slli_si128(temp1, 0x4);
444 temp1 = _mm_xor_si128(temp1, temp3);
445 temp3 = _mm_slli_si128(temp3, 0x4);
446 temp1 = _mm_xor_si128(temp1, temp3);
447 temp3 = _mm_slli_si128(temp3, 0x4);
448 temp1 = _mm_xor_si128(temp1, temp3);
449 temp1 = _mm_xor_si128(temp1, temp2);
453 template<std::
size_t K, std::
size_t R>
455 AES<K,R>::aesni128ExpandKey([[maybe_unused]] uint8_t key[4 * K]) {
456 if constexpr (K == 4) {
457 __m128i temp1, temp2;
458 temp1 = _mm_loadu_si128(
reinterpret_cast<__m128i*
>(key));
459 _expKey.hwKey.cipherKey[0] = temp1;
460 temp2 = _mm_aeskeygenassist_si128(temp1, 0x1);
461 temp1 = aes128assist(temp1, temp2);
462 _expKey.hwKey.cipherKey[1] = temp1;
463 temp2 = _mm_aeskeygenassist_si128(temp1, 0x2);
464 temp1 = aes128assist(temp1, temp2);
465 _expKey.hwKey.cipherKey[2] = temp1;
466 temp2 = _mm_aeskeygenassist_si128(temp1, 0x4);
467 temp1 = aes128assist(temp1, temp2);
468 _expKey.hwKey.cipherKey[3] = temp1;
469 temp2 = _mm_aeskeygenassist_si128(temp1, 0x8);
470 temp1 = aes128assist(temp1, temp2);
471 _expKey.hwKey.cipherKey[4] = temp1;
472 temp2 = _mm_aeskeygenassist_si128(temp1, 0x10);
473 temp1 = aes128assist(temp1, temp2);
474 _expKey.hwKey.cipherKey[5] = temp1;
475 temp2 = _mm_aeskeygenassist_si128(temp1, 0x20);
476 temp1 = aes128assist(temp1, temp2);
477 _expKey.hwKey.cipherKey[6] = temp1;
478 temp2 = _mm_aeskeygenassist_si128(temp1, 0x40);
479 temp1 = aes128assist(temp1, temp2);
480 _expKey.hwKey.cipherKey[7] = temp1;
481 temp2 = _mm_aeskeygenassist_si128(temp1, 0x80);
482 temp1 = aes128assist(temp1, temp2);
483 _expKey.hwKey.cipherKey[8] = temp1;
484 temp2 = _mm_aeskeygenassist_si128(temp1, 0x1b);
485 temp1 = aes128assist(temp1, temp2);
486 _expKey.hwKey.cipherKey[9] = temp1;
487 temp2 = _mm_aeskeygenassist_si128(temp1, 0x36);
488 temp1 = aes128assist(temp1, temp2);
489 _expKey.hwKey.cipherKey[10] = temp1;
493 template<std::
size_t K, std::
size_t R>
495 AES<K,R>::aes192assist(__m128i& temp1, __m128i& temp2, __m128i& temp3) {
497 temp2 = _mm_shuffle_epi32(temp2, 0x55);
498 temp4 = _mm_slli_si128(temp1, 0x4);
499 temp1 = _mm_xor_si128(temp1, temp4);
500 temp4 = _mm_slli_si128(temp4, 0x4);
501 temp1 = _mm_xor_si128(temp1, temp4);
502 temp4 = _mm_slli_si128(temp4, 0x4);
503 temp1 = _mm_xor_si128(temp1, temp4);
504 temp1 = _mm_xor_si128(temp1, temp2);
505 temp2 = _mm_shuffle_epi32(temp1, 0xff);
506 temp4 = _mm_slli_si128(temp3, 0x4);
507 temp3 = _mm_xor_si128(temp3, temp4);
508 temp3 = _mm_xor_si128(temp3, temp2);
511 template<std::
size_t K, std::
size_t R>
513 AES<K,R>::aesni192ExpandKey([[maybe_unused]] uint8_t key[4 * K]) {
514 if constexpr (K == 6) {
515 __m128i temp1, temp2, temp3;
516 temp1 = _mm_loadu_si128(
reinterpret_cast<__m128i*
>(key));
517 temp3 = _mm_loadu_si128(
reinterpret_cast<__m128i*
>((key + 16)));
518 _expKey.hwKey.cipherKey[0] = temp1;
519 _expKey.hwKey.cipherKey[1] = temp3;
520 temp2 = _mm_aeskeygenassist_si128(temp3, 0x1);
521 aes192assist(temp1, temp2, temp3);
522 _expKey.hwKey.cipherKey[1] =
reinterpret_cast<__m128i
>(_mm_shuffle_pd(
reinterpret_cast<__m128d
>(_expKey.hwKey.cipherKey[1]),
523 reinterpret_cast<__m128d
>(temp1), 0));
524 _expKey.hwKey.cipherKey[2] =
reinterpret_cast<__m128i
>(_mm_shuffle_pd(
reinterpret_cast<__m128d
>(temp1),
525 reinterpret_cast<__m128d
>(temp3), 1));
526 temp2 = _mm_aeskeygenassist_si128(temp3, 0x2);
527 aes192assist(temp1, temp2, temp3);
528 _expKey.hwKey.cipherKey[3] = temp1;
529 _expKey.hwKey.cipherKey[4] = temp3;
530 temp2 = _mm_aeskeygenassist_si128(temp3, 0x4);
531 aes192assist(temp1, temp2, temp3);
532 _expKey.hwKey.cipherKey[4] =
reinterpret_cast<__m128i
>(_mm_shuffle_pd(
reinterpret_cast<__m128d
>(_expKey.hwKey.cipherKey[4]),
533 reinterpret_cast<__m128d
>(temp1), 0));
534 _expKey.hwKey.cipherKey[5] =
reinterpret_cast<__m128i
>(_mm_shuffle_pd(
reinterpret_cast<__m128d
>(temp1),
535 reinterpret_cast<__m128d
>(temp3), 1));
536 temp2 = _mm_aeskeygenassist_si128(temp3, 0x8);
537 aes192assist(temp1, temp2, temp3);
538 _expKey.hwKey.cipherKey[6] = temp1;
539 _expKey.hwKey.cipherKey[7] = temp3;
540 temp2 = _mm_aeskeygenassist_si128(temp3, 0x10);
541 aes192assist(temp1, temp2, temp3);
542 _expKey.hwKey.cipherKey[7] =
reinterpret_cast<__m128i
>(_mm_shuffle_pd(
reinterpret_cast<__m128d
>(_expKey.hwKey.cipherKey[7]),
543 reinterpret_cast<__m128d
>(temp1), 0));
544 _expKey.hwKey.cipherKey[8] =
reinterpret_cast<__m128i
>(_mm_shuffle_pd(
reinterpret_cast<__m128d
>(temp1),
545 reinterpret_cast<__m128d
>(temp3), 1));
546 temp2 = _mm_aeskeygenassist_si128 (temp3, 0x20);
547 aes192assist(temp1, temp2, temp3);
548 _expKey.hwKey.cipherKey[9] = temp1;
549 _expKey.hwKey.cipherKey[10] = temp3;
550 temp2 = _mm_aeskeygenassist_si128(temp3, 0x40);
551 aes192assist(temp1, temp2, temp3);
552 _expKey.hwKey.cipherKey[10] =
reinterpret_cast<__m128i
>(_mm_shuffle_pd(
reinterpret_cast<__m128d
>(_expKey.hwKey.cipherKey[10]),
553 reinterpret_cast<__m128d
>(temp1), 0));
554 _expKey.hwKey.cipherKey[11] =
reinterpret_cast<__m128i
>(_mm_shuffle_pd(
reinterpret_cast<__m128d
>(temp1),
555 reinterpret_cast<__m128d
>(temp3), 1));
556 temp2 = _mm_aeskeygenassist_si128(temp3, 0x80);
557 aes192assist(temp1, temp2, temp3);
558 _expKey.hwKey.cipherKey[12] = temp1;
562 template<std::
size_t K, std::
size_t R>
564 AES<K,R>::aes256assist1(__m128i& temp1, __m128i& temp2) {
566 temp2 = _mm_shuffle_epi32(temp2, 0xff);
567 temp4 = _mm_slli_si128(temp1, 0x4);
568 temp1 = _mm_xor_si128(temp1, temp4);
569 temp4 = _mm_slli_si128(temp4, 0x4);
570 temp1 = _mm_xor_si128(temp1, temp4);
571 temp4 = _mm_slli_si128(temp4, 0x4);
572 temp1 = _mm_xor_si128(temp1, temp4);
573 temp1 = _mm_xor_si128(temp1, temp2);
576 template<std::
size_t K, std::
size_t R>
578 AES<K,R>::aes256assist2(__m128i& temp1, __m128i& temp3) {
580 temp4 = _mm_aeskeygenassist_si128(temp1, 0x0);
581 temp2 = _mm_shuffle_epi32(temp4, 0xaa);
582 temp4 = _mm_slli_si128(temp3, 0x4);
583 temp3 = _mm_xor_si128(temp3, temp4);
584 temp4 = _mm_slli_si128(temp4, 0x4);
585 temp3 = _mm_xor_si128(temp3, temp4);
586 temp4 = _mm_slli_si128(temp4, 0x4);
587 temp3 = _mm_xor_si128(temp3, temp4);
588 temp3 = _mm_xor_si128(temp3, temp2);
591 template<std::
size_t K, std::
size_t R>
593 AES<K,R>::aesni256ExpandKey([[maybe_unused]] uint8_t key[4 * K]) {
594 if constexpr (K == 8) {
595 __m128i temp1, temp2, temp3;
596 temp1 = _mm_loadu_si128(
reinterpret_cast<__m128i*
>(key));
597 temp3 = _mm_loadu_si128(
reinterpret_cast<__m128i*
>(key + 16));
598 _expKey.hwKey.cipherKey[0] = temp1;
599 _expKey.hwKey.cipherKey[1] = temp3;
600 temp2 = _mm_aeskeygenassist_si128(temp3, 0x01);
601 aes256assist1(temp1, temp2);
602 _expKey.hwKey.cipherKey[2] = temp1;
603 aes256assist2(temp1, temp3);
604 _expKey.hwKey.cipherKey[3] = temp3;
605 temp2 = _mm_aeskeygenassist_si128(temp3, 0x02);
606 aes256assist1(temp1, temp2);
607 _expKey.hwKey.cipherKey[4] = temp1;
608 aes256assist2(temp1, temp3);
609 _expKey.hwKey.cipherKey[5] = temp3;
610 temp2 = _mm_aeskeygenassist_si128(temp3, 0x04);
611 aes256assist1(temp1, temp2);
612 _expKey.hwKey.cipherKey[6] = temp1;
613 aes256assist2(temp1, temp3);
614 _expKey.hwKey.cipherKey[7] = temp3;
615 temp2 = _mm_aeskeygenassist_si128(temp3, 0x08);
616 aes256assist1(temp1, temp2);
617 _expKey.hwKey.cipherKey[8] = temp1;
618 aes256assist2(temp1, temp3);
619 _expKey.hwKey.cipherKey[9] = temp3;
620 temp2 = _mm_aeskeygenassist_si128(temp3, 0x10);
621 aes256assist1(temp1, temp2);
622 _expKey.hwKey.cipherKey[10] = temp1;
623 aes256assist2(temp1, temp3);
624 _expKey.hwKey.cipherKey[11] = temp3;
625 temp2 = _mm_aeskeygenassist_si128(temp3, 0x20);
626 aes256assist1(temp1, temp2);
627 _expKey.hwKey.cipherKey[12] = temp1;
628 aes256assist2(temp1, temp3);
629 _expKey.hwKey.cipherKey[13] = temp3;
630 temp2 = _mm_aeskeygenassist_si128(temp3, 0x40);
631 aes256assist1(temp1, temp2);
632 _expKey.hwKey.cipherKey[14] = temp1;
636 template<std::
size_t K, std::
size_t R>
638 AES<K,R>::aesniExpandKey(uint8_t key[4 * K]) {
640 aesni128ExpandKey(key);
641 aesni192ExpandKey(key);
642 aesni256ExpandKey(key);
646 _expKey.hwKey.decipherKey[R] = _expKey.hwKey.cipherKey[0];
647 _expKey.hwKey.decipherKey[R - 1] = _mm_aesimc_si128(_expKey.hwKey.cipherKey[1]);
648 _expKey.hwKey.decipherKey[R - 2] = _mm_aesimc_si128(_expKey.hwKey.cipherKey[2]);
649 _expKey.hwKey.decipherKey[R - 3] = _mm_aesimc_si128(_expKey.hwKey.cipherKey[3]);
650 _expKey.hwKey.decipherKey[R - 4] = _mm_aesimc_si128(_expKey.hwKey.cipherKey[4]);
651 _expKey.hwKey.decipherKey[R - 5] = _mm_aesimc_si128(_expKey.hwKey.cipherKey[5]);
652 _expKey.hwKey.decipherKey[R - 6] = _mm_aesimc_si128(_expKey.hwKey.cipherKey[6]);
653 _expKey.hwKey.decipherKey[R - 7] = _mm_aesimc_si128(_expKey.hwKey.cipherKey[7]);
654 _expKey.hwKey.decipherKey[R - 8] = _mm_aesimc_si128(_expKey.hwKey.cipherKey[8]);
655 _expKey.hwKey.decipherKey[R - 9] = _mm_aesimc_si128(_expKey.hwKey.cipherKey[9]);
656 if constexpr (R > 10) {
657 _expKey.hwKey.decipherKey[R - 10] = _mm_aesimc_si128(_expKey.hwKey.cipherKey[10]);
658 _expKey.hwKey.decipherKey[R - 11] = _mm_aesimc_si128(_expKey.hwKey.cipherKey[11]);
660 if constexpr (R > 12) {
661 _expKey.hwKey.decipherKey[R - 12] = _mm_aesimc_si128(_expKey.hwKey.cipherKey[12]);
662 _expKey.hwKey.decipherKey[R - 13] = _mm_aesimc_si128(_expKey.hwKey.cipherKey[13]);
664 _expKey.hwKey.decipherKey[0] = _expKey.hwKey.cipherKey[R];
669#if defined ANCH_CPU_DETECTION || !defined(ANCH_CPU_AES)
679 template<std::
size_t K, std::
size_t R>
681 AES<K,R>::swCipher(
const std::array<uint8_t,16>& input, std::array<uint8_t,16>& output) {
682 std::memcpy(&_state, input.data(), 16);
683 unsigned int round = 0;
690 for(round = 1 ; round < R ; ++round) {
704 std::memcpy(output.data(), &_state, 16);
707 template<std::
size_t K, std::
size_t R>
709 AES<K,R>::swDecipher(
const std::array<uint8_t,16>& input, std::array<uint8_t,16>& output) {
710 std::memcpy(&_state, input.data(), 16);
711 unsigned int round = R;
720 for(round = R - 1 ; round > 0 ; --round) {
722 decipherMixColumns();
732 std::memcpy(output.data(), &_state, 16);
735 template<std::
size_t K, std::
size_t R>
737 AES<K,R>::expandKey(
const uint8_t key[4 * K]) {
738 std::memcpy(_expKey.swKey, key, 4 * K);
739 for(std::size_t i = K ; i < 4 * (R + 1) ; ++i) {
740 uint32_t mod =
static_cast<uint32_t
>(i % K);
742 _expKey.swKey[i] = _expKey.swKey[i - K] ^ (subWord(rotateWord(_expKey.swKey[i - 1])) ^
ANCH_AES_RCON[i / K]);
743 }
else if(K > 6 && mod == 4) {
744 _expKey.swKey[i] = _expKey.swKey[i - K] ^ subWord(_expKey.swKey[i - 1]);
746 _expKey.swKey[i] = _expKey.swKey[i - K] ^ _expKey.swKey[i - 1];
751 template<std::
size_t K, std::
size_t R>
753 AES<K,R>::subWord(
const uint32_t& word) {
755 uint8_t* resBytes =
reinterpret_cast<uint8_t*
>(&res);
756 const uint8_t*
const bytes =
reinterpret_cast<const uint8_t* const
>(&word);
764 template<std::
size_t K, std::
size_t R>
766 AES<K,R>::rotateWord(
const uint32_t& word) {
767 return ((word << 24) | (word >> 8));
770 template<std::
size_t K, std::
size_t R>
772 AES<K,R>::cipherSubBytes() {
791 template<std::
size_t K, std::
size_t R>
793 AES<K,R>::decipherSubBytes() {
812 template<std::
size_t K, std::
size_t R>
814 AES<K,R>::cipherShiftRows() {
815 uint8_t tmp = _state[0][1];
816 _state[0][1] = _state[1][1];
817 _state[1][1] = _state[2][1];
818 _state[2][1] = _state[3][1];
821 _state[1][2] = _state[3][2];
824 _state[2][2] = _state[0][2];
827 _state[3][3] = _state[2][3];
828 _state[2][3] = _state[1][3];
829 _state[1][3] = _state[0][3];
833 template<std::
size_t K, std::
size_t R>
835 AES<K,R>::decipherShiftRows() {
836 uint8_t tmp = _state[3][1];
837 _state[3][1] = _state[2][1];
838 _state[2][1] = _state[1][1];
839 _state[1][1] = _state[0][1];
842 _state[1][2] = _state[3][2];
845 _state[2][2] = _state[0][2];
848 _state[0][3] = _state[1][3];
849 _state[1][3] = _state[2][3];
850 _state[2][3] = _state[3][3];
854 template<std::
size_t K, std::
size_t R>
856 AES<K,R>::cipherMixColumns() {
859 state[0] = _state[0][0];
860 state[1] = _state[0][1];
861 state[2] = _state[0][2];
862 state[3] = _state[0][3];
868 state[0] = _state[1][0];
869 state[1] = _state[1][1];
870 state[2] = _state[1][2];
871 state[3] = _state[1][3];
877 state[0] = _state[2][0];
878 state[1] = _state[2][1];
879 state[2] = _state[2][2];
880 state[3] = _state[2][3];
886 state[0] = _state[3][0];
887 state[1] = _state[3][1];
888 state[2] = _state[3][2];
889 state[3] = _state[3][3];
896 template<std::
size_t K, std::
size_t R>
898 AES<K,R>::decipherMixColumns() {
901 state[0] = _state[0][0];
902 state[1] = _state[0][1];
903 state[2] = _state[0][2];
904 state[3] = _state[0][3];
910 state[0] = _state[1][0];
911 state[1] = _state[1][1];
912 state[2] = _state[1][2];
913 state[3] = _state[1][3];
919 state[0] = _state[2][0];
920 state[1] = _state[2][1];
921 state[2] = _state[2][2];
922 state[3] = _state[2][3];
928 state[0] = _state[3][0];
929 state[1] = _state[3][1];
930 state[2] = _state[3][2];
931 state[3] = _state[3][3];
938 template<std::
size_t K, std::
size_t R>
940 AES<K,R>::addRoundKey(
const uint32_t& round) {
941 uint32_t* key = _expKey.swKey + 4 * round;
942 uint32_t* state =
reinterpret_cast<uint32_t*
>(_state);
static CPU & getInstance()
AES(const AES &other)
Definition aes.hpp:324
void cipher(const std::array< uint8_t, 16 > &input, std::array< uint8_t, 16 > &output)
Definition aes.hpp:353
virtual ~AES()
Definition aes.hpp:344
void decipher(const std::array< uint8_t, 16 > &input, std::array< uint8_t, 16 > &output)
Definition aes.hpp:369
AES(const uint8_t key[4 *K])
Definition aes.hpp:305
Block cipher interface.
Definition blockCipher.hpp:58
Cryptography namespace.
Definition base64.hpp:28
const uint8_t ANCH_AES_CIPHER_SBOX[256]
const uint8_t ANCH_GALOIS_MULT11[256]
const uint8_t ANCH_GALOIS_MULT9[256]
const uint32_t ANCH_AES_RCON[11]
const uint8_t ANCH_AES_DECIPHER_SBOX[256]
const uint8_t ANCH_GALOIS_MULT3[256]
const uint8_t ANCH_GALOIS_MULT14[256]
const uint8_t ANCH_GALOIS_MULT13[256]
const uint8_t ANCH_GALOIS_MULT2[256]
AnCH framework base namespace.
Definition app.hpp:28