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/m5/m5_internal.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 / m5 / m5_internal.h` 61 lines ยท 2037 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 /* Internal helpers for native/m5. Not part of the API. */ 18 #ifndef AIENOS_M5_INTERNAL_H 19 #define AIENOS_M5_INTERNAL_H 20 21 #include 22 #include 23 24 #include "../crypto/aienos_crypto.h" 25 #include "m5.h" 26 27 static inline void m5_put16(uint8_t *p, uint16_t v) { p[0] = (uint8_t)v; p[1] = (uint8_t)(v >> 8); } 28 static inline void m5_put32(uint8_t *p, uint32_t v) 29 { 30 for (int i = 0; i < 4; i++) p[i] = (uint8_t)(v >> (8 * i)); 31 } 32 static inline void m5_put64(uint8_t *p, uint64_t v) 33 { 34 for (int i = 0; i < 8; i++) p[i] = (uint8_t)(v >> (8 * i)); 35 } 36 static inline uint16_t m5_get16(const uint8_t *p) { return (uint16_t)(p[0] | (p[1] << 8)); } 37 static inline uint32_t m5_get32(const uint8_t *p) 38 { 39 uint32_t v = 0; 40 for (int i = 0; i < 4; i++) v |= (uint32_t)p[i] << (8 * i); 41 return v; 42 } 43 static inline uint64_t m5_get64(const uint8_t *p) 44 { 45 uint64_t v = 0; 46 for (int i = 0; i < 8; i++) v |= (uint64_t)p[i] << (8 * i); 47 return v; 48 } 49 static inline int m5_all_zero(const uint8_t *p, size_t n) 50 { 51 uint8_t acc = 0; 52 for (size_t i = 0; i < n; i++) acc |= p[i]; 53 return acc == 0; 54 } 55 static inline int m5_valid_class(uint8_t c) { return c == M5_ID_PRODUCTION || c == M5_ID_TEST; } 56 57 /* HMAC(key, domain || body) */ 58 void m5_mac(const uint8_t key[32], const char *domain, size_t domain_len, 59 const uint8_t *body, size_t body_len, uint8_t out[32]); 60 61 #endif