1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <lk/compiler.h> 20 #include <stdint.h> 21 22 __BEGIN_CDECLS 23 24 #define HWBCC_PORT "com.android.trusty.hwbcc" 25 26 /** 27 * enum hwbcc_cmd - BCC service commands. 28 * @HWBCC_CMD_REQ_SHIFT: Bitshift of the command index. 29 * @HWBCC_CMD_RESP_BIT: Bit indicating that this is a response. 30 * @HWBCC_CMD_SIGN_DATA: Sign the provided data. 31 * @HWBCC_CMD_GET_BCC: Get BCC. 32 * @HWBCC_CMD_GET_DICE_ARTIFACTS: Retrieves DICE artifacts for 33 * a child node in the DICE chain/tree. 34 * @HWBCC_CMD_NS_DEPRIVILEGE: Deprivilege hwbcc from serving calls 35 * to non-secure clients. 36 */ 37 enum hwbcc_cmd { 38 HWBCC_CMD_REQ_SHIFT = 1, 39 HWBCC_CMD_RESP_BIT = 1, 40 HWBCC_CMD_SIGN_DATA = 1 << HWBCC_CMD_REQ_SHIFT, 41 HWBCC_CMD_GET_BCC = 2 << HWBCC_CMD_REQ_SHIFT, 42 HWBCC_CMD_GET_DICE_ARTIFACTS = 3 << HWBCC_CMD_REQ_SHIFT, 43 HWBCC_CMD_NS_DEPRIVILEGE = 4 << HWBCC_CMD_REQ_SHIFT, 44 }; 45 46 /** 47 * struct hwbcc_req_hdr - Generic header for all hwbcc requests. 48 * @cmd: The command to be run. Commands are described in hwbcc_cmd. 49 * @test_mode: Whether or not RKP is making a test request. 50 * @context: Device specific context information passed in by the client. 51 * This is opaque to the generic Trusty code. This is required 52 * to make decisions about device specific behavior in the 53 * implementations of certain hwbcc interface methods. For e.g. 54 * w.r.t get_dice_artifacts, context can supply information 55 * about which secure/non-secure DICE child node is requesting 56 * the dice_artifacts and the implementations can use such 57 * information to derive dice artifacts specific to the 58 * particular child node. 59 */ 60 struct hwbcc_req_hdr { 61 uint32_t cmd; 62 uint32_t test_mode; 63 uint64_t context; 64 }; 65 STATIC_ASSERT(sizeof(struct hwbcc_req_hdr) == 16); 66 67 #define HWBCC_MAX_AAD_SIZE 512 68 #define HWBCC_MAX_DATA_TO_SIGN_SIZE 2048 69 #define HWBCC_MAX_ENCODED_KEY_SIZE HWBCC_MAX_DATA_TO_SIGN_SIZE 70 #define HWBCC_MAC_KEY_SIZE 32 71 72 /** 73 * enum hwbcc_algorithm - Signing algorithm options 74 * @HWBCC_ALGORITHM_ED25519: Ed25519 75 * 76 * We use COSE encodings. 77 */ 78 enum hwbcc_algorithm { 79 HWBCC_ALGORITHM_ED25519 = -8, 80 }; 81 82 /** 83 * struct hwbcc_req_sign_data - Request to sign data. Followed by a buffer 84 * containing (data || aad) 85 * @algorithm: Choice of signing algorithm, one of &enum hwbcc_algorithm. 86 * @data_size: Length of payload to be signed. Maximum size is bounded by 87 * HWBCC_MAX_DATA_TO_SIGN_SIZE. 88 * @aad_size: Size of AAD portion of the buffer that follows this struct. 89 */ 90 struct hwbcc_req_sign_data { 91 int16_t algorithm; 92 uint16_t data_size; 93 uint32_t aad_size; 94 }; 95 STATIC_ASSERT(sizeof(struct hwbcc_req_sign_data) == 8); 96 97 /** 98 * struct hwbcc_resp_hdr - Generic header for all hwbcc requests. 99 * @cmd: Command identifier - %HWBCC_CMD_RSP_BIT or'ed with the command 100 * identifier of the corresponding request. 101 * @status: Whether or not the cmd succeeded, or how it failed. 102 * @payload_size: Size of response payload that follows this struct. 103 */ 104 struct hwbcc_resp_hdr { 105 uint32_t cmd; 106 int32_t status; 107 uint32_t payload_size; 108 }; 109 STATIC_ASSERT(sizeof(struct hwbcc_resp_hdr) == 12); 110 111 #define HWBCC_MAX_RESP_PAYLOAD_SIZE 3072 112 113 __END_CDECLS 114