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/sig/aienos_sig.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 / sig / aienos_sig.h` 70 lines ยท 2946 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 /* AIENOS in-house signatures in C: Ed25519 (RFC 8032 Section 5.1, pure 18 * Ed25519 only: no Ed25519ph, no Ed25519ctx) and SHA-512 (FIPS 180-4). 19 * 20 * No heap, no clock, no I/O. Signing and public-key derivation are written 21 * to run in constant time with respect to the secret key and the nonce. 22 * Verification handles only public data and is NOT constant time. 23 */ 24 #ifndef AIENOS_SIG_H 25 #define AIENOS_SIG_H 26 27 #include 28 #include 29 30 #define AIENOS_SIG_OK 0 31 #define AIENOS_SIG_ERR_INVALID (-1) /* signature or public key rejected */ 32 #define AIENOS_SIG_ERR_ARG (-2) /* NULL buffer */ 33 34 #define AIENOS_ED25519_SECRET_KEY_LEN 32 35 #define AIENOS_ED25519_PUBLIC_KEY_LEN 32 36 #define AIENOS_ED25519_SIGNATURE_LEN 64 37 38 /* SHA-512 */ 39 #define AIENOS_SHA512_DIGEST_LEN 64 40 typedef struct { 41 uint64_t h[8]; 42 uint64_t bytes; /* total bytes absorbed (messages up to 2^64 - 1 bytes) */ 43 uint8_t buf[128]; 44 size_t n; /* bytes waiting in buf */ 45 } aienos_sha512_ctx; 46 47 void aienos_sha512_init(aienos_sha512_ctx *c); 48 void aienos_sha512_update(aienos_sha512_ctx *c, const uint8_t *p, size_t len); 49 /* Writes the digest and wipes the context. */ 50 void aienos_sha512_final(aienos_sha512_ctx *c, uint8_t out[AIENOS_SHA512_DIGEST_LEN]); 51 void aienos_sha512(const uint8_t *p, size_t len, uint8_t out[AIENOS_SHA512_DIGEST_LEN]); 52 53 /* Ed25519. sk is the 32-byte RFC 8032 secret key (seed). */ 54 int aienos_`ed25519`_public_key(uint8_t pk[32], const uint8_t sk[32]); 55 56 /* Derives the public key from sk itself (no caller-supplied public key, so 57 * a mismatched pair cannot leak the key). msg may be NULL when msg_len is 0. 58 * sig may overlap msg. */ 59 int aienos_`ed25519`_sign(uint8_t sig[64], const uint8_t *msg, size_t msg_len, 60 const uint8_t sk[32]); 61 62 /* Returns AIENOS_SIG_OK only if sig is a valid signature of msg under pk. 63 * Rejects (AIENOS_SIG_ERR_INVALID): S >= L, a non-canonical or off-curve 64 * encoding of A or R, x = 0 with the sign bit set, and A or R of small order 65 * (order dividing 8). Equation checked: encode([S]B - [k]A) == R bytes 66 * (cofactorless, RFC 8032 Section 5.1.7 without the optional factor 8). */ 67 int aienos_`ed25519`_verify(const uint8_t sig[64], const uint8_t *msg, size_t msg_len, 68 const uint8_t pk[32]); 69 70 #endif