Software APIs
boot_svc_ownership_unlock_unittest.cc
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #include "sw/device/silicon_creator/lib/boot_svc/boot_svc_ownership_unlock.h"
6 
7 #include <string.h>
8 
9 #include "gtest/gtest.h"
10 #include "sw/device/silicon_creator/lib/boot_svc/mock_boot_svc_header.h"
11 #include "sw/device/silicon_creator/testing/rom_test.h"
12 
13 namespace boot_svc_ownership_unlock_unittest {
14 namespace {
15 using ::testing::ElementsAreArray;
16 
18  protected:
19  rom_test::MockBootSvcHeader boot_svc_header_;
20 };
21 
22 TEST_F(BootSvcOwnershipUnlockTest, ReqInit) {
24  constexpr uint32_t unlock_mode = kBootSvcUnlockAny;
25  constexpr nonce_t nonce = {0x55555555, 0xAAAAAAAA};
26  constexpr owner_key_t next_owner_key = {
27  {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}};
28  constexpr owner_signature_t signature = {{100, 101, 102, 103, 104, 105, 106,
29  107, 108, 109, 110, 111, 112, 113,
30  114, 115}};
31  EXPECT_CALL(boot_svc_header_, Finalize(kBootSvcOwnershipUnlockReqType,
32  sizeof(msg), &msg.header));
33 
34  boot_svc_ownership_unlock_req_init(unlock_mode, nonce, &next_owner_key,
35  &signature, &msg);
36 
37  EXPECT_EQ(msg.unlock_mode, unlock_mode);
38  EXPECT_EQ(msg.nonce.value[0], nonce.value[0]);
39  EXPECT_EQ(msg.nonce.value[1], nonce.value[1]);
40  EXPECT_EQ(
41  memcmp(&msg.next_owner_key, &next_owner_key, sizeof(next_owner_key)), 0);
42  EXPECT_EQ(memcmp(&msg.signature, &signature, sizeof(signature)), 0);
43 }
44 
45 TEST_F(BootSvcOwnershipUnlockTest, ResInit) {
47  constexpr rom_error_t kStatus = kErrorOk;
48  EXPECT_CALL(boot_svc_header_, Finalize(kBootSvcOwnershipUnlockResType,
49  sizeof(msg), &msg.header));
50 
51  boot_svc_ownership_unlock_res_init(kStatus, &msg);
52 
53  EXPECT_EQ(msg.status, kStatus);
54 }
55 
56 } // namespace
57 } // namespace boot_svc_ownership_unlock_unittest