|
| 1 | +/** @file |
| 2 | + * Copyright (c) 2025, Arm Limited or its affiliates. All rights reserved. |
| 3 | + * SPDX-License-Identifier : Apache-2.0 |
| 4 | + * |
| 5 | + * Copyright (c) 2025, STMicroelectronics. |
| 6 | + * SPDX-License-Identifier : Apache-2.0 |
| 7 | + * |
| 8 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | + * you may not use this file except in compliance with the License. |
| 10 | + * You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, software |
| 15 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | + * See the License for the specific language governing permissions and |
| 18 | + * limitations under the License. |
| 19 | +**/ |
| 20 | + |
| 21 | +#ifndef _PAL_ATTESTATION_CONFIG_H_ |
| 22 | +#define _PAL_ATTESTATION_CONFIG_H_ |
| 23 | + |
| 24 | +#define COSE_ALGORITHM_ES256 -7 |
| 25 | +#define COSE_ALG_SHA256_PROPRIETARY -72000 |
| 26 | + |
| 27 | +#define USEFUL_BUF_MAKE_STACK_UB UsefulBuf_MAKE_STACK_UB |
| 28 | + |
| 29 | +#define COSE_SIG_CONTEXT_STRING_SIGNATURE1 "Signature1" |
| 30 | + |
| 31 | +/* Private value. Intentionally not documented for Doxygen. |
| 32 | + * This is the size allocated for the encoded protected headers. It |
| 33 | + * needs to be big enough for make_protected_header() to succeed. It |
| 34 | + * currently sized for one header with an algorithm ID up to 32 bits |
| 35 | + * long -- one byte for the wrapping map, one byte for the label, 5 |
| 36 | + * bytes for the ID. If this is made accidentially too small, QCBOR will |
| 37 | + * only return an error, and not overrun any buffers. |
| 38 | + * |
| 39 | + * 9 extra bytes are added, rounding it up to 16 total, in case some |
| 40 | + * other protected header is to be added. |
| 41 | + */ |
| 42 | +#define T_COSE_SIGN1_MAX_PROT_HEADER (1+1+5+9) |
| 43 | + |
| 44 | +/** |
| 45 | + * This is the size of the first part of the CBOR encoded TBS |
| 46 | + * bytes. It is around 20 bytes. See create_tbs_hash(). |
| 47 | + */ |
| 48 | +#define T_COSE_SIZE_OF_TBS \ |
| 49 | + 1 + /* For opening the array */ \ |
| 50 | + sizeof(COSE_SIG_CONTEXT_STRING_SIGNATURE1) + /* "Signature1" */ \ |
| 51 | + 2 + /* Overhead for encoding string */ \ |
| 52 | + T_COSE_SIGN1_MAX_PROT_HEADER + /* entire protected headers */ \ |
| 53 | + 3 * (/* 3 NULL bstrs for fields not used */ \ |
| 54 | + 1 /* size of a NULL bstr */ \ |
| 55 | + ) |
| 56 | +#define NULL_USEFUL_BUF_C NULLUsefulBufC |
| 57 | + |
| 58 | +#define ATTEST_PUBLIC_KEY_SLOT 4 |
| 59 | +#define ECC_CURVE_SECP256R1_PULBIC_KEY_LENGTH (1 + 2 * PSA_BITS_TO_BYTES(256)) |
| 60 | + |
| 61 | +typedef struct { |
| 62 | + uint8_t *pubx_key; |
| 63 | + size_t pubx_key_size; |
| 64 | + uint8_t *puby_key; |
| 65 | + size_t puby_key_size; |
| 66 | +} ecc_key_t; |
| 67 | + |
| 68 | +struct ecc_public_key_t { |
| 69 | + const uint8_t a; |
| 70 | + uint8_t public_key[]; /* X-coordinate || Y-coordinate */ |
| 71 | +}; |
| 72 | + |
| 73 | +static const struct ecc_public_key_t attest_public_key = { |
| 74 | + /* Constant byte */ |
| 75 | + 0x04, |
| 76 | + /* X-coordinate */ |
| 77 | + {0x79, 0xEB, 0xA9, 0x0E, 0x8B, 0xF4, 0x50, 0xA6, |
| 78 | + 0x75, 0x15, 0x76, 0xAD, 0x45, 0x99, 0xB0, 0x7A, |
| 79 | + 0xDF, 0x93, 0x8D, 0xA3, 0xBB, 0x0B, 0xD1, 0x7D, |
| 80 | + 0x00, 0x36, 0xED, 0x49, 0xA2, 0xD0, 0xFC, 0x3F, |
| 81 | + /* Y-coordinate */ |
| 82 | + 0xBF, 0xCD, 0xFA, 0x89, 0x56, 0xB5, 0x68, 0xBF, |
| 83 | + 0xDB, 0x86, 0x73, 0xE6, 0x48, 0xD8, 0xB5, 0x8D, |
| 84 | + 0x92, 0x99, 0x55, 0xB1, 0x4A, 0x26, 0xC3, 0x08, |
| 85 | + 0x0F, 0x34, 0x11, 0x7D, 0x97, 0x1D, 0x68, 0x64}, |
| 86 | +}; |
| 87 | + |
| 88 | +static const uint8_t initial_attestation_public_x_key[] = { |
| 89 | + 0x79, 0xEB, 0xA9, 0x0E, 0x8B, 0xF4, 0x50, 0xA6, |
| 90 | + 0x75, 0x15, 0x76, 0xAD, 0x45, 0x99, 0xB0, 0x7A, |
| 91 | + 0xDF, 0x93, 0x8D, 0xA3, 0xBB, 0x0B, 0xD1, 0x7D, |
| 92 | + 0x00, 0x36, 0xED, 0x49, 0xA2, 0xD0, 0xFC, 0x3F |
| 93 | +}; |
| 94 | + |
| 95 | +static const uint8_t initial_attestation_public_y_key[] = { |
| 96 | + 0xBF, 0xCD, 0xFA, 0x89, 0x56, 0xB5, 0x68, 0xBF, |
| 97 | + 0xDB, 0x86, 0x73, 0xE6, 0x48, 0xD8, 0xB5, 0x8D, |
| 98 | + 0x92, 0x99, 0x55, 0xB1, 0x4A, 0x26, 0xC3, 0x08, |
| 99 | + 0x0F, 0x34, 0x11, 0x7D, 0x97, 0x1D, 0x68, 0x64 |
| 100 | +}; |
| 101 | + |
| 102 | +/* Initialize the structure with given public key */ |
| 103 | +static const ecc_key_t attest_key = { |
| 104 | + (uint8_t *)initial_attestation_public_x_key, |
| 105 | + sizeof(initial_attestation_public_x_key), |
| 106 | + (uint8_t *)initial_attestation_public_y_key, |
| 107 | + sizeof(initial_attestation_public_y_key) |
| 108 | +}; |
| 109 | + |
| 110 | +#endif /* _PAL_ATTESTATION_CONFIG_H_ */ |
0 commit comments