summaryrefslogtreecommitdiffstats
path: root/src/core/hw/aes/arithmetic128.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2017-02-25 06:12:33 +0100
committerGitHub <noreply@github.com>2017-02-25 06:12:33 +0100
commit892888ed9e7c683150493c7c17f567d3c569e62e (patch)
treefffbfb393fc1da4b6c69a9c0593d2fe8ef9a10a7 /src/core/hw/aes/arithmetic128.cpp
parentMerge pull request #2421 from Subv/timers (diff)
parentexternals: remove -march=native for crypto++ (diff)
downloadyuzu-892888ed9e7c683150493c7c17f567d3c569e62e.tar
yuzu-892888ed9e7c683150493c7c17f567d3c569e62e.tar.gz
yuzu-892888ed9e7c683150493c7c17f567d3c569e62e.tar.bz2
yuzu-892888ed9e7c683150493c7c17f567d3c569e62e.tar.lz
yuzu-892888ed9e7c683150493c7c17f567d3c569e62e.tar.xz
yuzu-892888ed9e7c683150493c7c17f567d3c569e62e.tar.zst
yuzu-892888ed9e7c683150493c7c17f567d3c569e62e.zip
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 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include <algorithm>
+#include <functional>
+#include "core/hw/aes/arithmetic128.h"
+
+namespace HW {
+namespace AES {
+
+AESKey Lrot128(const AESKey& in, u32 rot) {
+ AESKey out;
+ rot %= 128;
+ const u32 byte_shift = rot / 8;
+ const u32 bit_shift = rot % 8;
+
+ for (u32 i = 0; i < 16; i++) {
+ const u32 wrap_index_a = (i + byte_shift) % 16;
+ const u32 wrap_index_b = (i + byte_shift + 1) % 16;
+ out[i] = ((in[wrap_index_a] << bit_shift) | (in[wrap_index_b] >> (8 - bit_shift))) & 0xFF;
+ }
+ return out;
+}
+
+AESKey Add128(const AESKey& a, const AESKey& b) {
+ AESKey out;
+ u32 carry = 0;
+ u32 sum = 0;
+
+ for (int i = 15; i >= 0; i--) {
+ sum = a[i] + b[i] + carry;
+ carry = sum >> 8;
+ out[i] = static_cast<u8>(sum & 0xff);
+ }
+
+ return out;
+}
+
+AESKey Xor128(const AESKey& a, const AESKey& b) {
+ AESKey out;
+ std::transform(a.cbegin(), a.cend(), b.cbegin(), out.begin(), std::bit_xor<>());
+ return out;
+}
+
+} // namespace AES
+} // namespace HW