Raghu Krishnamurthy | c11b60e | 2024-06-03 19:02:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2024, NVIDIA Corporation. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef RMM_EL3_TOKEN_SIGN_H |
| 8 | #define RMM_EL3_TOKEN_SIGN_H |
| 9 | |
| 10 | #include <stdint.h> |
| 11 | #include <lib/cassert.h> |
| 12 | #include <services/rmmd_svc.h> |
| 13 | |
| 14 | /* |
| 15 | * Defines member of structure and reserves space |
| 16 | * for the next member with specified offset. |
| 17 | */ |
| 18 | /* cppcheck-suppress [misra-c2012-20.7] */ |
| 19 | #define SET_MEMBER(member, start, end) \ |
| 20 | union { \ |
| 21 | member; \ |
| 22 | unsigned char reserved##end[((end) - (start))]; \ |
| 23 | } |
| 24 | |
| 25 | #define EL3_TOKEN_RESPONSE_MAX_SIG_LEN U(512) |
| 26 | |
| 27 | struct el3_token_sign_request { |
| 28 | SET_MEMBER(uint32_t sig_alg_id, 0x0, 0x8); |
| 29 | SET_MEMBER(uint64_t rec_granule, 0x8, 0x10); |
| 30 | SET_MEMBER(uint64_t req_ticket, 0x10, 0x18); |
| 31 | SET_MEMBER(uint32_t hash_alg_id, 0x18, 0x20); |
| 32 | SET_MEMBER(uint8_t hash_buf[SHA512_DIGEST_SIZE], 0x20, 0x60); |
| 33 | }; |
| 34 | |
| 35 | CASSERT(__builtin_offsetof(struct el3_token_sign_request, sig_alg_id) == 0x0U, |
| 36 | assert_el3_token_sign_request_sig_alg_mismatch); |
| 37 | CASSERT(__builtin_offsetof(struct el3_token_sign_request, rec_granule) == 0x8U, |
| 38 | assert_el3_token_sign_request_rec_granule_mismatch); |
| 39 | CASSERT(__builtin_offsetof(struct el3_token_sign_request, req_ticket) == 0x10U, |
| 40 | assert_el3_token_sign_request_req_ticket_mismatch); |
| 41 | CASSERT(__builtin_offsetof(struct el3_token_sign_request, hash_alg_id) == 0x18U, |
| 42 | assert_el3_token_sign_request_hash_alg_id_mismatch); |
| 43 | CASSERT(__builtin_offsetof(struct el3_token_sign_request, hash_buf) == 0x20U, |
| 44 | assert_el3_token_sign_request_hash_buf_mismatch); |
| 45 | |
| 46 | |
| 47 | struct el3_token_sign_response { |
| 48 | SET_MEMBER(uint64_t rec_granule, 0x0, 0x8); |
| 49 | SET_MEMBER(uint64_t req_ticket, 0x8, 0x10); |
| 50 | SET_MEMBER(uint16_t sig_len, 0x10, 0x12); |
| 51 | SET_MEMBER(uint8_t signature_buf[EL3_TOKEN_RESPONSE_MAX_SIG_LEN], 0x12, 0x212); |
| 52 | }; |
| 53 | |
| 54 | CASSERT(__builtin_offsetof(struct el3_token_sign_response, rec_granule) == 0x0U, |
| 55 | assert_el3_token_sign_resp_rec_granule_mismatch); |
| 56 | CASSERT(__builtin_offsetof(struct el3_token_sign_response, req_ticket) == 0x8U, |
| 57 | assert_el3_token_sign_resp_req_ticket_mismatch); |
| 58 | CASSERT(__builtin_offsetof(struct el3_token_sign_response, sig_len) == 0x10U, |
| 59 | assert_el3_token_sign_resp_sig_len_mismatch); |
| 60 | CASSERT(__builtin_offsetof(struct el3_token_sign_response, signature_buf) == 0x12U, |
| 61 | assert_el3_token_sign_resp_sig_buf_mismatch); |
| 62 | |
| 63 | #endif /* RMM_EL3_TOKEN_SIGN_H */ |