interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / crates / aienos-artifact / src / canonical.rs

60 lines · 2191 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
16use aienos_crypto::sha256::{hash, Digest, Sha256};
17
18use crate::format::Artifact;
19
20pub const REQUESTS_DOMAIN: &[u8] = b"AIENOS-ARTIFACT-CAP-REQUESTS-V1\0";
21pub const GRANTS_DOMAIN: &[u8] = b"AIENOS-ADMISSION-CAP-GRANTS-V1\0";
22pub const RESOURCES_DOMAIN: &[u8] = b"AIENOS-ARTIFACT-RESOURCES-V1\0";
23pub const POLICY_DOMAIN: &[u8] = b"AIENOS-ADMISSION-POLICY-V1\0";
24pub const MACHINE_ID_DOMAIN: &[u8] = b"AIENOS-MACHINE-ID-V1\0";
25pub const VERIFIER_IDENTITY_DOMAIN: &[u8] = b"AIENOS-VERIFIER-IDENTITY-V1\0";
26
27pub fn payload_digest(artifact: &Artifact<'_>) -> Digest {
28 hash(artifact.payload)
29}
30
31pub fn requested_capability_digest(canonical_records: &[u8]) -> Digest {
32 digest_domain(REQUESTS_DOMAIN, canonical_records)
33}
34
35pub fn granted_capability_digest(canonical_records: &[u8]) -> Digest {
36 digest_domain(GRANTS_DOMAIN, canonical_records)
37}
38
39pub fn resource_envelope_digest(canonical_envelope: &[u8]) -> Digest {
40 digest_domain(RESOURCES_DOMAIN, canonical_envelope)
41}
42
43pub fn policy_digest(canonical_policy: &[u8]) -> Digest {
44 digest_domain(POLICY_DOMAIN, canonical_policy)
45}
46
47pub fn machine_id_digest(canonical_machine_id: &[u8]) -> Digest {
48 digest_domain(MACHINE_ID_DOMAIN, canonical_machine_id)
49}
50
51pub fn verifier_identity_digest(build_identity: &[u8]) -> Digest {
52 digest_domain(VERIFIER_IDENTITY_DOMAIN, build_identity)
53}
54
55fn digest_domain(domain: &[u8], canonical_bytes: &[u8]) -> Digest {
56 let mut digest = Sha256::new();
57 digest.update(domain);
58 digest.update(canonical_bytes);
59 digest.finalize()
60}