• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018, VIXL authors
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 //   * Redistributions of source code must retain the above copyright notice,
8 //     this list of conditions and the following disclaimer.
9 //   * Redistributions in binary form must reproduce the above copyright notice,
10 //     this list of conditions and the following disclaimer in the documentation
11 //     and/or other materials provided with the distribution.
12 //   * Neither the name of ARM Limited nor the names of its contributors may be
13 //     used to endorse or promote products derived from this software without
14 //     specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 #ifdef VIXL_INCLUDE_SIMULATOR_AARCH64
28 
29 #include "test-runner.h"
30 #include "aarch64/simulator-aarch64.h"
31 
32 #define TEST(name) TEST_(AARCH64_POINTER_AUTH_##name)
33 
34 namespace vixl {
35 namespace aarch64 {
36 
37 
TEST(compute_pac)38 TEST(compute_pac) {
39   Decoder decoder;
40   Simulator sim(&decoder);
41 
42   uint64_t data1 = 0xfb623599da6e8127;
43   uint64_t data2 = 0x27979fadf7d53cb7;
44   uint64_t context = 0x477d469dec0b8762;
45   Simulator::PACKey key = {0x84be85ce9804e94b, 0xec2802d4e0a488e9, -1};
46 
47   uint64_t pac1 = sim.ComputePAC(data1, context, key);
48   uint64_t pac2 = sim.ComputePAC(data2, context, key);
49 
50   // NOTE: If the PAC implementation is changed, this may fail due to a hash
51   // collision.
52   VIXL_CHECK(pac1 != pac2);
53 }
54 
TEST(add_and_auth_pac)55 TEST(add_and_auth_pac) {
56   Decoder decoder;
57   Simulator sim(&decoder);
58 
59   uint64_t ptr = 0x0000000012345678;
60   uint64_t context = 0x477d469dec0b8762;
61   Simulator::PACKey key_a = {0x84be85ce9804e94b, 0xec2802d4e0a488e9, 0};
62   Simulator::PACKey key_b = {0xec1119e288704d13, 0xd7f6b76e1cea585e, 1};
63 
64   uint64_t ptr_a =
65       sim.AddPAC(ptr, context, key_a, Simulator::kInstructionPointer);
66 
67   // Attempt to authenticate the pointer with PAC using different keys.
68   uint64_t success =
69       sim.AuthPAC(ptr_a, context, key_a, Simulator::kInstructionPointer);
70   uint64_t fail =
71       sim.AuthPAC(ptr_a, context, key_b, Simulator::kInstructionPointer);
72 
73   uint64_t pac_mask =
74       sim.CalculatePACMask(ptr, Simulator::kInstructionPointer, 0);
75 
76   // NOTE: If the PAC implementation is changed, this may fail due to a hash
77   // collision.
78   VIXL_CHECK((ptr_a & pac_mask) != 0x0);
79   VIXL_CHECK(success == ptr);
80   VIXL_CHECK(fail != ptr);
81 }
82 
TEST(add_and_strip_pac)83 TEST(add_and_strip_pac) {
84   Decoder decoder;
85   Simulator sim(&decoder);
86 
87   uint64_t ptr = 0xff00000012345678;
88   uint64_t pac_mask =
89       sim.CalculatePACMask(ptr, Simulator::kInstructionPointer, 0);
90   uint64_t ptr_a = ptr | pac_mask;
91 
92 
93   VIXL_CHECK(sim.StripPAC(ptr_a, Simulator::kInstructionPointer) == ptr);
94 }
95 }
96 }  // namespace vixl::aarch64
97 
98 #endif  // VIXL_INCLUDE_SIMULATOR_AARCH64
99