Symbian platform (C++)
SDK native APIs, runtime and tooling
Loading...
Searching...
No Matches
veneer.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2#ifndef SYMBIAN_ENTROPY_VENEER_H_
3#define SYMBIAN_ENTROPY_VENEER_H_
4
5#include <cstdint>
6#include <span>
7
8namespace symbian::entropy {
9
10// Recognize the original EUSER Thumb wrappers, including the leaving wrapper's
11// subsequent BL to LeaveIfError. Returns the ARM-state secure RNG veneer, or
12// zero for an unsupported wrapper. Callers must independently validate that
13// both wrapper spans and the resulting veneer belong to readable native ROM.
14inline std::uintptr_t SecureRandomVeneer(std::uintptr_t address,
15 std::span<const std::uint16_t> code,
16 bool leaving) {
17 if (const std::size_t words = leaving ? 6 : 4;
18 (address & 1) == 0 || code.size() != words || code[0] != 0xb510 ||
19 (code[1] & 0xf800) != 0xf000 || (code[2] & 0xf801) != 0xe800 ||
20 code[words - 1] != 0xbd10) {
21 return 0;
22 }
23 if (leaving &&
24 ((code[3] & 0xf800) != 0xf000 || (code[4] & 0xf800) != 0xf800)) {
25 return 0;
26 }
27 const std::uint32_t raw =
28 ((code[1] & 0x7ffu) << 12) | ((code[2] & 0x7ffu) << 1);
29 const std::int64_t displacement =
30 (raw & 0x400000u) ? std::int64_t{raw} - 0x800000 : std::int64_t{raw};
31 const std::int64_t target =
32 static_cast<std::int64_t>(((address & ~std::uintptr_t{1}) + 6) &
33 ~std::uintptr_t{3}) +
34 displacement;
35 if (target <= 0 || target > UINT32_MAX || (target & 3) != 0) {
36 return 0;
37 }
38 return static_cast<std::uintptr_t>(target);
39}
40
41inline bool IsSecureRandomVeneer(std::span<const std::uint32_t> code) {
42 // ARM SVC (OS-selected executive number) followed by BX LR. The semantics
43 // come from the two EUSER export contracts, not a device/syscall table.
44 return code.size() == 2 && (code[0] & 0xff000000u) == 0xef000000u &&
45 code[1] == 0xe12fff1eu;
46}
47
48} // namespace symbian::entropy
49#endif // SYMBIAN_ENTROPY_VENEER_H_
std::vector< uint32_t > code
Definition e32.cc:74
Definition native_camera_stream.cc:19
Definition veneer.h:8
std::uintptr_t SecureRandomVeneer(std::uintptr_t address, std::span< const std::uint16_t > code, bool leaving)
Definition veneer.h:14
bool IsSecureRandomVeneer(std::span< const std::uint32_t > code)
Definition veneer.h:41
uint32_t address
Definition exports.cc:71
std::string_view raw
Definition sis.cc:141
std::string target
Definition sis.cc:296