From eb75d54b2b5be59d629aba0714a99104fe8b8758 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 22 Feb 2020 19:47:08 -0800 Subject: [PATCH] vapours: new include style, add crypto --- libraries/libvapours/include/vapours.hpp | 15 ++--- .../libvapours/include/vapours/crypto.hpp | 20 +++++++ .../vapours/crypto/crypto_memory_compare.hpp | 37 ++++++++++++ .../impl/crypto_memory_compare.arch.arm64.hpp | 60 +++++++++++++++++++ .../libvapours/include/vapours/defines.hpp | 2 +- .../libvapours/include/vapours/includes.hpp | 2 +- .../libvapours/include/vapours/literals.hpp | 2 +- .../libvapours/include/vapours/results.hpp | 54 ++++++++--------- .../include/vapours/results/cal_results.hpp | 2 +- .../vapours/results/creport_results.hpp | 2 +- .../include/vapours/results/debug_results.hpp | 2 +- .../include/vapours/results/dmnt_results.hpp | 2 +- .../include/vapours/results/err_results.hpp | 2 +- .../vapours/results/exosphere_results.hpp | 2 +- .../include/vapours/results/fatal_results.hpp | 2 +- .../include/vapours/results/fs_results.hpp | 2 +- .../include/vapours/results/hipc_results.hpp | 2 +- .../include/vapours/results/i2c_results.hpp | 2 +- .../include/vapours/results/kvdb_results.hpp | 2 +- .../vapours/results/loader_results.hpp | 2 +- .../include/vapours/results/lr_results.hpp | 2 +- .../include/vapours/results/ncm_results.hpp | 2 +- .../include/vapours/results/os_results.hpp | 2 +- .../include/vapours/results/pm_results.hpp | 2 +- .../vapours/results/results_common.hpp | 2 +- .../include/vapours/results/ro_results.hpp | 2 +- .../vapours/results/settings_results.hpp | 2 +- .../include/vapours/results/sf_results.hpp | 2 +- .../include/vapours/results/sm_results.hpp | 2 +- .../include/vapours/results/spl_results.hpp | 2 +- .../include/vapours/results/svc_results.hpp | 2 +- .../vapours/results/updater_results.hpp | 2 +- .../include/vapours/results/vi_results.hpp | 2 +- libraries/libvapours/include/vapours/svc.hpp | 8 +-- .../libvapours/include/vapours/timespan.hpp | 2 +- libraries/libvapours/include/vapours/util.hpp | 26 ++++---- 36 files changed, 198 insertions(+), 80 deletions(-) create mode 100644 libraries/libvapours/include/vapours/crypto.hpp create mode 100644 libraries/libvapours/include/vapours/crypto/crypto_memory_compare.hpp create mode 100644 libraries/libvapours/include/vapours/crypto/impl/crypto_memory_compare.arch.arm64.hpp diff --git a/libraries/libvapours/include/vapours.hpp b/libraries/libvapours/include/vapours.hpp index 68cadda3e..c3b59686c 100644 --- a/libraries/libvapours/include/vapours.hpp +++ b/libraries/libvapours/include/vapours.hpp @@ -15,12 +15,13 @@ */ #pragma once -#include "vapours/includes.hpp" -#include "vapours/defines.hpp" -#include "vapours/literals.hpp" +#include +#include +#include -#include "vapours/timespan.hpp" +#include -#include "vapours/util.hpp" -#include "vapours/results.hpp" -#include "vapours/svc.hpp" +#include +#include +#include +#include diff --git a/libraries/libvapours/include/vapours/crypto.hpp b/libraries/libvapours/include/vapours/crypto.hpp new file mode 100644 index 000000000..274db7952 --- /dev/null +++ b/libraries/libvapours/include/vapours/crypto.hpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include + +#include diff --git a/libraries/libvapours/include/vapours/crypto/crypto_memory_compare.hpp b/libraries/libvapours/include/vapours/crypto/crypto_memory_compare.hpp new file mode 100644 index 000000000..e4af47985 --- /dev/null +++ b/libraries/libvapours/include/vapours/crypto/crypto_memory_compare.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include + +#ifdef ATMOSPHERE_ARCH_ARM64 + +#include + +#else + +#error "Unknown architecture for crypto::IsSameBytes" + +#endif + +namespace ams::crypto { + + bool IsSameBytes(const void *lhs, const void *rhs, size_t size) { + return impl::IsSameBytes(lhs, rhs, size); + } + +} diff --git a/libraries/libvapours/include/vapours/crypto/impl/crypto_memory_compare.arch.arm64.hpp b/libraries/libvapours/include/vapours/crypto/impl/crypto_memory_compare.arch.arm64.hpp new file mode 100644 index 000000000..0e655d722 --- /dev/null +++ b/libraries/libvapours/include/vapours/crypto/impl/crypto_memory_compare.arch.arm64.hpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include + +namespace ams::crypto::impl { + + bool IsSameBytes(const void *lhs, const void *rhs, size_t size) { + bool result; + u8 xor_acc, ltmp, rtmp; + size_t index; + + __asm__ __volatile__( + /* Clear registers and prepare for comparison. */ + " mov %w[xor_acc], #0\n" + " mov %w[index], #0\n" + " b 1f\n" + + /* Compare one byte in constant time. */ + "0:\n" + " ldrb %w[ltmp], [%[lhs]]\n" + " ldrb %w[rtmp], [%[rhs]]\n" + " adds %[lhs], %[lhs], #1\n" + " adds %[rhs], %[rhs], #1\n" + " eor %w[ltmp], %w[ltmp], %w[rtmp]\n" + " orr %w[xor_acc], %w[xor_acc], %w[ltmp]\n" + " adds %[index], %[index], #1\n" + + /* Check if there is still data to compare. */ + "1:\n" + " cmp %[index], %[size]\n" + " bcc 0b\n" + + /* We're done, set result. */ + " cmp %w[xor_acc], #0\n" + " cset %w[result], eq\n" + : [result]"=r"(result), [lhs]"+r"(lhs), [rhs]"+r"(rhs), [xor_acc]"=&r"(xor_acc), [index]"=&r"(index), [ltmp]"=&r"(ltmp), [rtmp]"=&r"(rtmp) + : [size]"r"(size) + : "cc" + ); + + return result; + } + +} \ No newline at end of file diff --git a/libraries/libvapours/include/vapours/defines.hpp b/libraries/libvapours/include/vapours/defines.hpp index 90a7396f0..b5ddcce6b 100644 --- a/libraries/libvapours/include/vapours/defines.hpp +++ b/libraries/libvapours/include/vapours/defines.hpp @@ -14,7 +14,7 @@ * along with this program. If not, see . */ #pragma once -#include "includes.hpp" +#include /* Any broadly useful language defines should go here. */ diff --git a/libraries/libvapours/include/vapours/includes.hpp b/libraries/libvapours/include/vapours/includes.hpp index 9180881e0..713d7d4c5 100644 --- a/libraries/libvapours/include/vapours/includes.hpp +++ b/libraries/libvapours/include/vapours/includes.hpp @@ -60,4 +60,4 @@ #endif /* ATMOSPHERE_IS_STRATOSPHERE */ /* Atmosphere meta. */ -#include "ams_version.h" +#include diff --git a/libraries/libvapours/include/vapours/literals.hpp b/libraries/libvapours/include/vapours/literals.hpp index 504ef6455..35a32e17f 100644 --- a/libraries/libvapours/include/vapours/literals.hpp +++ b/libraries/libvapours/include/vapours/literals.hpp @@ -14,7 +14,7 @@ * along with this program. If not, see . */ #pragma once -#include "defines.hpp" +#include namespace ams { inline namespace literals { diff --git a/libraries/libvapours/include/vapours/results.hpp b/libraries/libvapours/include/vapours/results.hpp index f8e668855..b3d6275d0 100644 --- a/libraries/libvapours/include/vapours/results.hpp +++ b/libraries/libvapours/include/vapours/results.hpp @@ -15,36 +15,36 @@ */ #pragma once -#include "defines.hpp" -#include "util.hpp" +#include +#include /* Utilities. */ -#include "results/results_common.hpp" +#include /* Official. */ -#include "results/cal_results.hpp" -#include "results/creport_results.hpp" -#include "results/debug_results.hpp" -#include "results/dmnt_results.hpp" -#include "results/err_results.hpp" -#include "results/fatal_results.hpp" -#include "results/fs_results.hpp" -#include "results/hipc_results.hpp" -#include "results/i2c_results.hpp" -#include "results/kvdb_results.hpp" -#include "results/loader_results.hpp" -#include "results/lr_results.hpp" -#include "results/os_results.hpp" -#include "results/ncm_results.hpp" -#include "results/pm_results.hpp" -#include "results/ro_results.hpp" -#include "results/settings_results.hpp" -#include "results/sf_results.hpp" -#include "results/sm_results.hpp" -#include "results/spl_results.hpp" -#include "results/svc_results.hpp" -#include "results/updater_results.hpp" -#include "results/vi_results.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* Unofficial. */ -#include "results/exosphere_results.hpp" +#include diff --git a/libraries/libvapours/include/vapours/results/cal_results.hpp b/libraries/libvapours/include/vapours/results/cal_results.hpp index 13db12ea3..e465e8f79 100644 --- a/libraries/libvapours/include/vapours/results/cal_results.hpp +++ b/libraries/libvapours/include/vapours/results/cal_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::cal { diff --git a/libraries/libvapours/include/vapours/results/creport_results.hpp b/libraries/libvapours/include/vapours/results/creport_results.hpp index 482373198..6a924b6c9 100644 --- a/libraries/libvapours/include/vapours/results/creport_results.hpp +++ b/libraries/libvapours/include/vapours/results/creport_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::creport { diff --git a/libraries/libvapours/include/vapours/results/debug_results.hpp b/libraries/libvapours/include/vapours/results/debug_results.hpp index 6ef5cdb64..da2ed6400 100644 --- a/libraries/libvapours/include/vapours/results/debug_results.hpp +++ b/libraries/libvapours/include/vapours/results/debug_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::dbg { diff --git a/libraries/libvapours/include/vapours/results/dmnt_results.hpp b/libraries/libvapours/include/vapours/results/dmnt_results.hpp index a233d912e..95e2ed3c6 100644 --- a/libraries/libvapours/include/vapours/results/dmnt_results.hpp +++ b/libraries/libvapours/include/vapours/results/dmnt_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::dmnt { diff --git a/libraries/libvapours/include/vapours/results/err_results.hpp b/libraries/libvapours/include/vapours/results/err_results.hpp index b1bb745a1..9aa60c016 100644 --- a/libraries/libvapours/include/vapours/results/err_results.hpp +++ b/libraries/libvapours/include/vapours/results/err_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::err { diff --git a/libraries/libvapours/include/vapours/results/exosphere_results.hpp b/libraries/libvapours/include/vapours/results/exosphere_results.hpp index a8dd043c7..c89c5d139 100644 --- a/libraries/libvapours/include/vapours/results/exosphere_results.hpp +++ b/libraries/libvapours/include/vapours/results/exosphere_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::exosphere { diff --git a/libraries/libvapours/include/vapours/results/fatal_results.hpp b/libraries/libvapours/include/vapours/results/fatal_results.hpp index 9821ebfaf..27105d88c 100644 --- a/libraries/libvapours/include/vapours/results/fatal_results.hpp +++ b/libraries/libvapours/include/vapours/results/fatal_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::fatal { diff --git a/libraries/libvapours/include/vapours/results/fs_results.hpp b/libraries/libvapours/include/vapours/results/fs_results.hpp index aa8d9e834..a731c5041 100644 --- a/libraries/libvapours/include/vapours/results/fs_results.hpp +++ b/libraries/libvapours/include/vapours/results/fs_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::fs { diff --git a/libraries/libvapours/include/vapours/results/hipc_results.hpp b/libraries/libvapours/include/vapours/results/hipc_results.hpp index db48bd64a..dec237e1a 100644 --- a/libraries/libvapours/include/vapours/results/hipc_results.hpp +++ b/libraries/libvapours/include/vapours/results/hipc_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::sf::hipc { diff --git a/libraries/libvapours/include/vapours/results/i2c_results.hpp b/libraries/libvapours/include/vapours/results/i2c_results.hpp index 32cd03fce..62cb26eb7 100644 --- a/libraries/libvapours/include/vapours/results/i2c_results.hpp +++ b/libraries/libvapours/include/vapours/results/i2c_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::i2c { diff --git a/libraries/libvapours/include/vapours/results/kvdb_results.hpp b/libraries/libvapours/include/vapours/results/kvdb_results.hpp index 423b4e2ec..ba6731b56 100644 --- a/libraries/libvapours/include/vapours/results/kvdb_results.hpp +++ b/libraries/libvapours/include/vapours/results/kvdb_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::kvdb { diff --git a/libraries/libvapours/include/vapours/results/loader_results.hpp b/libraries/libvapours/include/vapours/results/loader_results.hpp index 06bc9b7a8..3a4be5917 100644 --- a/libraries/libvapours/include/vapours/results/loader_results.hpp +++ b/libraries/libvapours/include/vapours/results/loader_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::ldr { diff --git a/libraries/libvapours/include/vapours/results/lr_results.hpp b/libraries/libvapours/include/vapours/results/lr_results.hpp index 0f9864780..693d6a9e6 100644 --- a/libraries/libvapours/include/vapours/results/lr_results.hpp +++ b/libraries/libvapours/include/vapours/results/lr_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::lr { diff --git a/libraries/libvapours/include/vapours/results/ncm_results.hpp b/libraries/libvapours/include/vapours/results/ncm_results.hpp index 8f95855f1..7148d0279 100644 --- a/libraries/libvapours/include/vapours/results/ncm_results.hpp +++ b/libraries/libvapours/include/vapours/results/ncm_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::ncm { diff --git a/libraries/libvapours/include/vapours/results/os_results.hpp b/libraries/libvapours/include/vapours/results/os_results.hpp index cb865d7ea..742b12c6d 100644 --- a/libraries/libvapours/include/vapours/results/os_results.hpp +++ b/libraries/libvapours/include/vapours/results/os_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::os { diff --git a/libraries/libvapours/include/vapours/results/pm_results.hpp b/libraries/libvapours/include/vapours/results/pm_results.hpp index 321250ed3..46d06c27a 100644 --- a/libraries/libvapours/include/vapours/results/pm_results.hpp +++ b/libraries/libvapours/include/vapours/results/pm_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::pm { diff --git a/libraries/libvapours/include/vapours/results/results_common.hpp b/libraries/libvapours/include/vapours/results/results_common.hpp index cb977ab99..936fa6deb 100644 --- a/libraries/libvapours/include/vapours/results/results_common.hpp +++ b/libraries/libvapours/include/vapours/results/results_common.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "../defines.hpp" +#include namespace ams { diff --git a/libraries/libvapours/include/vapours/results/ro_results.hpp b/libraries/libvapours/include/vapours/results/ro_results.hpp index d60bc045c..fc4dbe16f 100644 --- a/libraries/libvapours/include/vapours/results/ro_results.hpp +++ b/libraries/libvapours/include/vapours/results/ro_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::ro { diff --git a/libraries/libvapours/include/vapours/results/settings_results.hpp b/libraries/libvapours/include/vapours/results/settings_results.hpp index 98b15801f..e704371b7 100644 --- a/libraries/libvapours/include/vapours/results/settings_results.hpp +++ b/libraries/libvapours/include/vapours/results/settings_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::settings { diff --git a/libraries/libvapours/include/vapours/results/sf_results.hpp b/libraries/libvapours/include/vapours/results/sf_results.hpp index 75e010325..516cb24cd 100644 --- a/libraries/libvapours/include/vapours/results/sf_results.hpp +++ b/libraries/libvapours/include/vapours/results/sf_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::sf { diff --git a/libraries/libvapours/include/vapours/results/sm_results.hpp b/libraries/libvapours/include/vapours/results/sm_results.hpp index a5d584778..45d934985 100644 --- a/libraries/libvapours/include/vapours/results/sm_results.hpp +++ b/libraries/libvapours/include/vapours/results/sm_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::sm { diff --git a/libraries/libvapours/include/vapours/results/spl_results.hpp b/libraries/libvapours/include/vapours/results/spl_results.hpp index d8401220d..8ea794825 100644 --- a/libraries/libvapours/include/vapours/results/spl_results.hpp +++ b/libraries/libvapours/include/vapours/results/spl_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::spl { diff --git a/libraries/libvapours/include/vapours/results/svc_results.hpp b/libraries/libvapours/include/vapours/results/svc_results.hpp index 715232ed2..31672c97e 100644 --- a/libraries/libvapours/include/vapours/results/svc_results.hpp +++ b/libraries/libvapours/include/vapours/results/svc_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::svc { diff --git a/libraries/libvapours/include/vapours/results/updater_results.hpp b/libraries/libvapours/include/vapours/results/updater_results.hpp index e4f750771..ec0f0fdee 100644 --- a/libraries/libvapours/include/vapours/results/updater_results.hpp +++ b/libraries/libvapours/include/vapours/results/updater_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::updater { diff --git a/libraries/libvapours/include/vapours/results/vi_results.hpp b/libraries/libvapours/include/vapours/results/vi_results.hpp index 84c8ba6d1..833bdd5e9 100644 --- a/libraries/libvapours/include/vapours/results/vi_results.hpp +++ b/libraries/libvapours/include/vapours/results/vi_results.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "results_common.hpp" +#include namespace ams::vi { diff --git a/libraries/libvapours/include/vapours/svc.hpp b/libraries/libvapours/include/vapours/svc.hpp index 1c0641396..93d965956 100644 --- a/libraries/libvapours/include/vapours/svc.hpp +++ b/libraries/libvapours/include/vapours/svc.hpp @@ -15,8 +15,8 @@ */ #pragma once -#include "defines.hpp" -#include "results.hpp" +#include +#include -#include "svc/svc_types.hpp" -#include "svc/svc_definitions.hpp" +#include +#include diff --git a/libraries/libvapours/include/vapours/timespan.hpp b/libraries/libvapours/include/vapours/timespan.hpp index b269e5d4b..dbe6a0055 100644 --- a/libraries/libvapours/include/vapours/timespan.hpp +++ b/libraries/libvapours/include/vapours/timespan.hpp @@ -15,7 +15,7 @@ */ #pragma once -#include "defines.hpp" +#include #include namespace ams { diff --git a/libraries/libvapours/include/vapours/util.hpp b/libraries/libvapours/include/vapours/util.hpp index ef2fae4c5..8cdae1847 100644 --- a/libraries/libvapours/include/vapours/util.hpp +++ b/libraries/libvapours/include/vapours/util.hpp @@ -15,17 +15,17 @@ */ #pragma once -#include "defines.hpp" +#include -#include "util/util_alignment.hpp" -#include "util/util_size.hpp" -#include "util/util_fourcc.hpp" -#include "util/util_bitpack.hpp" -#include "util/util_bitset.hpp" -#include "util/util_scope_guard.hpp" -#include "util/util_specialization_of.hpp" -#include "util/util_typed_storage.hpp" -#include "util/util_intrusive_list.hpp" -#include "util/util_intrusive_red_black_tree.hpp" -#include "util/util_tinymt.hpp" -#include "util/util_bitutil.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include