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/crypto/README.md # 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 / crypto / README.md` 61 lines ยท 3372 bytes Raw Blame History Rendered 1 # native/crypto: in-house AES-256, POLYVAL, AES-256-GCM-SIV in C 2 3 A C (gnu11) port of `crates/aienos-crypto`: AES-256 encryption (FIPS 197), 4 POLYVAL and AEAD_AES_256_GCM_SIV (RFC 8452), plus HMAC-SHA-256 with a 32-byte 5 key. SHA-256 is the existing in-house copy in `native/argus/sha256.c`; there 6 is no second SHA-256 here. No outside library. The library objects use no 7 heap, no clock and no I/O (checked by `make lib-checks` with `nm -u`). 8 9 API: one header, `aienos_crypto.h`. Library: `out/libaienos_crypto.a` 10 (includes the SHA-256 object). 11 12 ## Test 13 14 make -C native/crypto test # lib-checks + known-answer + negative tests 15 make -C native/crypto sanitize # same tests under ASan + UBSan 16 make -C native/crypto mutants # optional: each GUARD rule removed must fail the tests 17 make -C native/crypto clean 18 19 `OUT=` moves build output. The test's last line 20 is `AIENOS_CRYPTO_NATIVE: PASS` (exit 0) or `AIENOS_CRYPTO_NATIVE: FAIL` (exit 1). 21 22 Vectors are hard-coded in `tests/crypto_test.c`: all 24 RFC 8452 Appendix C.2 23 AES-256-GCM-SIV vectors and both C.3 counter-wrap vectors (each checked for 24 record keys, POLYVAL result, tag and sealed output, then opened, opened in 25 place, and tampered), RFC 8452 Section 7 and Appendix A POLYVAL examples, 26 the FIPS 197 AES-256 block and full S-box, FIPS 180-2 SHA-256 examples, 27 RFC 4231 HMAC cases 1 and 2, and every vector in the Rust crate's unit tests. 28 29 ## Behaviour worth knowing 30 31 - **Open on failure.** RFC 8452 computes the tag over the plaintext, so open 32 decrypts into the caller's buffer, recomputes the tag, compares it in 33 constant time, and on a mismatch zeroes the whole output buffer (volatile 34 writes) before returning `AIENOS_CRYPTO_ERR_AUTH`. Callers must not read 35 the output unless the return is `AIENOS_CRYPTO_OK`. Tests check the buffer 36 is all zero after each failed open (tag, ciphertext, AAD, nonce, key flips). 37 - **Lengths.** Plaintext and AAD above 2^36 bytes, ciphertext above 38 2^36 + 16, input shorter than a tag, a size mismatch or a NULL buffer with 39 a nonzero length return `AIENOS_CRYPTO_ERR_LENGTH` before any byte is read 40 or written. 41 - **In place.** `out == pt` (seal) and `out == in` (open) are supported; any 42 other overlap is undefined. 43 - **Wiping.** Derived keys, key schedules, keystream, padded tails and 44 POLYVAL/HMAC state are wiped before return. 45 46 ## Limitations 47 48 - This library's own tests run on the build machine only. The C kernel links 49 it through the sealed Store (`native/kernel/Makefile`, `native/kernel/stage.mk`), so it also 50 runs in the QEMU Store gates and in the Pi 5 Store runs with throwaway 51 secrets (`docs/native/PI5-4-UNLOCK-RUNS.md`). No timing or side-channel 52 measurement was made in any of those runs. 53 - Constant-time by construction (computed S-box, no tables; masks instead of 54 branches behind compiler barriers). Checked by reading the source and 55 spot-checking AArch64 `-O2` disassembly. Not measured with timing tools and 56 not independently reviewed for side channels. Another compiler or flag set 57 could still introduce branches. 58 - Slow: no hardware AES (ARMv8 AESE/AESMC) or PMULL POLYVAL yet. 59 - AES decryption is not implemented (GCM-SIV does not need it). 60 - Mutants that remove a length limit are killed by a crash (the test then 61 reads past a small buffer), not by a clean assertion.