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/store/tests/store_rig.h # 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 / store / tests / store_rig.h` 93 lines ยท 2916 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 /* File-backed test rig for the sealed store: one disk_file device holding a 18 * 4-unit torn_slot anchor region at LBA 0 and a 64-unit Store region after 19 * it. Hosted test code only. */ 20 #ifndef STORE_RIG_H 21 #define STORE_RIG_H 22 #include 23 #include 24 #include 25 #include 26 #include "disk_file.h" 27 #include "store_sealed.h" 28 29 #define RIG_ANCHOR_UNITS 4u 30 #define RIG_STORE_UNITS 64u 31 #define RIG_TOTAL_UNITS (RIG_ANCHOR_UNITS + RIG_STORE_UNITS) 32 #define RIG_BYTES ((size_t)RIG_TOTAL_UNITS * 4096u) 33 34 typedef struct { 35 disk_file f; 36 disk_dev d; 37 st_disk sd; 38 st_dev sdev; 39 ts_device tdev; 40 uint32_t bs, bpu; 41 } rig; 42 43 static inline int rig_open(rig *r, const char *path, uint32_t bs, int create) 44 { 45 memset(r, 0, sizeof *r); 46 r->bs = bs; 47 r->bpu = 4096u / bs; 48 if (create) unlink(path); 49 if (disk_file_open(&r->f, &r->d, path, bs, (uint64_t)RIG_TOTAL_UNITS * r->bpu, create) != 0) return -1; 50 if (st_disk_bind(&r->sd, &r->d, (uint64_t)RIG_ANCHOR_UNITS * r->bpu, RIG_STORE_UNITS, &r->sdev) != 0) { 51 disk_file_close(&r->f); 52 return -1; 53 } 54 ss_ts_device(&r->d, &r->tdev); 55 return 0; 56 } 57 static inline void rig_close(rig *r) { disk_file_close(&r->f); } 58 59 static inline int file_load(const char *path, uint8_t *buf, size_t n) 60 { 61 FILE *f = fopen(path, "rb"); 62 if (!f) return -1; 63 size_t got = fread(buf, 1, n, f); 64 fclose(f); 65 return got == n ? 0 : -1; 66 } 67 static inline int file_save(const char *path, const uint8_t *buf, size_t n) 68 { 69 FILE *f = fopen(path, "r+b"); 70 if (!f) f = fopen(path, "wb"); 71 if (!f) return -1; 72 size_t put = fwrite(buf, 1, n, f); 73 fclose(f); 74 return put == n ? 0 : -1; 75 } 76 77 static inline void rig_keys(uint8_t cls, uint8_t seed, ss_keys *k) 78 { 79 uint8_t kvol[32]; 80 memset(kvol, seed, 32); 81 m5_subkeys sk; 82 m5_derive_subkeys(kvol, cls, 0, &sk); 83 memset(k, 0, sizeof *k); 84 k->identity_class = cls; 85 k->key_generation = 1; 86 memcpy(k->k_root_auth, sk.k_root_auth, 32); 87 memcpy(k->k_domain, sk.k_artifact, 32); 88 m5_subkeys_wipe(&sk); 89 } 90 91 static const uint8_t RIG_UUID[16] = {0x5e, 0xa1, 0xed, 0x00, 0x11, 0x22, 0x33, 0x44, 92 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc}; 93 #endif