summaryrefslogtreecommitdiff
path: root/src/core/hw/aes/arithmetic128.cpp
diff options
context:
space:
mode:
authorGravatar wwylele2017-01-01 14:58:02 +0200
committerGravatar wwylele2017-02-21 23:57:31 +0200
commitea1ea0224c04753402e0b6472080f0c5d90a7a46 (patch)
treed6823e52d913418d63ec3f0b7ed12eb763a98899 /src/core/hw/aes/arithmetic128.cpp
parentMerge pull request #2562 from yuriks/pica-refactor3 (diff)
downloadyuzu-ea1ea0224c04753402e0b6472080f0c5d90a7a46.tar.gz
yuzu-ea1ea0224c04753402e0b6472080f0c5d90a7a46.tar.xz
yuzu-ea1ea0224c04753402e0b6472080f0c5d90a7a46.zip
HW: add AES engine & implement AES-CCM
Diffstat (limited to 'src/core/hw/aes/arithmetic128.cpp')
-rw-r--r--src/core/hw/aes/arithmetic128.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/core/hw/aes/arithmetic128.cpp b/src/core/hw/aes/arithmetic128.cpp
new file mode 100644
index 000000000..55b954a52
--- /dev/null
+++ b/src/core/hw/aes/arithmetic128.cpp
@@ -0,0 +1,47 @@
1// Copyright 2017 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <algorithm>
6#include <functional>
7#include "core/hw/aes/arithmetic128.h"
8
9namespace HW {
10namespace AES {
11
12AESKey Lrot128(const AESKey& in, u32 rot) {
13 AESKey out;
14 rot %= 128;
15 const u32 byte_shift = rot / 8;
16 const u32 bit_shift = rot % 8;
17
18 for (u32 i = 0; i < 16; i++) {
19 const u32 wrap_index_a = (i + byte_shift) % 16;
20 const u32 wrap_index_b = (i + byte_shift + 1) % 16;
21 out[i] = ((in[wrap_index_a] << bit_shift) | (in[wrap_index_b] >> (8 - bit_shift))) & 0xFF;
22 }
23 return out;
24}
25
26AESKey Add128(const AESKey& a, const AESKey& b) {
27 AESKey out;
28 u32 carry = 0;
29 u32 sum = 0;
30
31 for (int i = 15; i >= 0; i--) {
32 sum = a[i] + b[i] + carry;
33 carry = sum >> 8;
34 out[i] = static_cast<u8>(sum & 0xff);
35 }
36
37 return out;
38}
39
40AESKey Xor128(const AESKey& a, const AESKey& b) {
41 AESKey out;
42 std::transform(a.cbegin(), a.cend(), b.cbegin(), out.begin(), std::bit_xor<>());
43 return out;
44}
45
46} // namespace AES
47} // namespace HW