mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-28 13:44:11 -04:00
vapours: new include style, add crypto
This commit is contained in:
parent
081bd0aefc
commit
eb75d54b2b
36 changed files with 198 additions and 80 deletions
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours/defines.hpp>
|
||||
#include <vapours/util.hpp>
|
||||
|
||||
#ifdef ATMOSPHERE_ARCH_ARM64
|
||||
|
||||
#include <vapours/crypto/impl/crypto_memory_compare.arch.arm64.hpp>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours/defines.hpp>
|
||||
#include <vapours/util.hpp>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue