aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / core / fact_req.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 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 | /* fact_req.c -- see fact_req.h. */ |
| 18 | #include "fact_req.h" |
| 19 | |
| 20 | struct ck_fact_req_boot ck_fact_req_boot; |
| 21 | |
| 22 | int ck_fact_req_check(const struct ck_fact_req *q, const char **why) |
| 23 | { |
| 24 | const char *w = 0; |
| 25 | const uint8_t *p = (const uint8_t *)q; |
| 26 | if (!q) { |
| 27 | w = "no request"; |
| 28 | goto out; |
| 29 | } |
| 30 | for (unsigned i = 0; i < 8; i++) |
| 31 | if (q->magic[i] != (uint8_t)CK_FACT_REQ_MAGIC[i]) { |
| 32 | w = "bad magic"; |
| 33 | goto out; |
| 34 | } |
| 35 | if (q->version != CK_FACT_REQ_VERSION) { |
| 36 | w = "bad version"; |
| 37 | goto out; |
| 38 | } |
| 39 | if (q->flags != 0) { |
| 40 | w = "flags must be zero"; |
| 41 | goto out; |
| 42 | } |
| 43 | for (unsigned i = 0; i < 16; i++) |
| 44 | if (q->tag[i] != (uint8_t)CK_FACT_REQ_TAG[i]) { |
| 45 | w = "tier tag is not QUALIF-FACT-DATA"; |
| 46 | goto out; |
| 47 | } |
| 48 | if (q->len < 1 || q->len > CK_FACT_REQ_TEXT_MAX) { |
| 49 | w = "fact length must be 1..48"; |
| 50 | goto out; |
| 51 | } |
| 52 | if (q->reserved != 0) { |
| 53 | w = "reserved must be zero"; |
| 54 | goto out; |
| 55 | } |
| 56 | for (unsigned i = 0; i < CK_FACT_REQ_TEXT_MAX; i++) { |
| 57 | if (i < q->len) { |
| 58 | if (q->text[i] < 0x20 || q->text[i] > 0x7e) { |
| 59 | w = "fact text must be printable ASCII"; |
| 60 | goto out; |
| 61 | } |
| 62 | } else if (q->text[i] != 0) { |
| 63 | w = "text past the length is not zero"; |
| 64 | goto out; |
| 65 | } |
| 66 | } |
| 67 | for (unsigned i = 88; i < CK_FACT_REQ_SIZE; i++) |
| 68 | if (p[i] != 0) { |
| 69 | w = "padding is not zero"; |
| 70 | goto out; |
| 71 | } |
| 72 | out: |
| 73 | if (why) |
| 74 | *why = w; |
| 75 | return w ? -1 : 0; |
| 76 | } |
| 77 | |
| 78 | void ck_fact_req_store(const struct ck_fact_req *q) |
| 79 | { |
| 80 | ck_fact_req_boot.len = q->len; |
| 81 | for (unsigned i = 0; i < CK_FACT_REQ_TEXT_MAX; i++) |
| 82 | ck_fact_req_boot.text[i] = q->text[i]; |
| 83 | ck_fact_req_boot.state = CK_FACT_REQ_FOUND; |
| 84 | } |
| 85 | |
| 86 | void ck_fact_req_clear(void) |
| 87 | { |
| 88 | ck_fact_req_boot.len = 0; |
| 89 | for (unsigned i = 0; i < CK_FACT_REQ_TEXT_MAX; i++) |
| 90 | ck_fact_req_boot.text[i] = 0; |
| 91 | if (ck_fact_req_boot.state == CK_FACT_REQ_FOUND) |
| 92 | ck_fact_req_boot.state = CK_FACT_REQ_NONE; |
| 93 | } |