Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/kernel/core/unlock_req.c # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / kernel / core / unlock_req.c` 97 lines ยท 2842 bytes Raw Blame History 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 /* unlock_req.c -- see unlock_req.h. */ 18 #include "unlock_req.h" 19 20 struct ck_unlock_req_boot ck_unlock_req_boot; 21 22 static void wipe(void *p, size_t n) 23 { 24 volatile uint8_t *b = p; 25 while (n--) 26 *b++ = 0; 27 } 28 29 int ck_unlock_req_check(const struct ck_unlock_req *q, const char **why) 30 { 31 const char *w = 0; 32 const uint8_t *p = (const uint8_t *)q; 33 if (!q) { 34 w = "no request"; 35 goto out; 36 } 37 for (unsigned i = 0; i < 8; i++) 38 if (q->magic[i] != (uint8_t)CK_UNLOCK_REQ_MAGIC[i]) { 39 w = "bad magic"; 40 goto out; 41 } 42 if (q->version != CK_UNLOCK_REQ_VERSION) { 43 w = "bad version"; 44 goto out; 45 } 46 if (q->flags != 0) { 47 w = "flags must be zero"; 48 goto out; 49 } 50 for (unsigned i = 0; i < 16; i++) 51 if (q->tag[i] != (uint8_t)CK_UNLOCK_REQ_TAG[i]) { 52 w = "tier tag is not QUALIF-THROWAWAY"; 53 goto out; 54 } 55 { 56 unsigned zero = 1, same = 1; 57 for (unsigned i = 0; i < CK_UNLOCK_REQ_SECRET_LEN; i++) { 58 if (q->secret[i] != 0) 59 zero = 0; 60 if (q->secret[i] != q->secret[0]) 61 same = 0; 62 } 63 if (zero || same) { 64 w = "secret is all zero or one repeated byte"; 65 goto out; 66 } 67 } 68 for (unsigned i = 64; i < CK_UNLOCK_REQ_SIZE; i++) 69 if (p[i] != 0) { 70 w = "padding is not zero"; 71 goto out; 72 } 73 out: 74 if (why) 75 *why = w; 76 return w ? -1 : 0; 77 } 78 79 void ck_unlock_req_store(const struct ck_unlock_req *q) 80 { 81 for (unsigned i = 0; i < CK_UNLOCK_REQ_SECRET_LEN; i++) 82 ck_unlock_req_boot.secret[i] = q->secret[i]; 83 ck_unlock_req_boot.state = CK_UNLOCK_REQ_FOUND; 84 } 85 86 int ck_unlock_req_take(uint8_t out[CK_UNLOCK_REQ_SECRET_LEN]) 87 { 88 if (ck_unlock_req_boot.state != CK_UNLOCK_REQ_FOUND) { 89 wipe(out, CK_UNLOCK_REQ_SECRET_LEN); 90 return -1; 91 } 92 for (unsigned i = 0; i < CK_UNLOCK_REQ_SECRET_LEN; i++) 93 out[i] = ck_unlock_req_boot.secret[i]; 94 wipe(ck_unlock_req_boot.secret, CK_UNLOCK_REQ_SECRET_LEN); 95 ck_unlock_req_boot.state = CK_UNLOCK_REQ_NONE; 96 return 0; 97 }