From db3eb98b836bba63097e333a9fb61b04a634a20e Mon Sep 17 00:00:00 2001 From: Carl Niklas Rydberg Date: Mon, 22 Dec 2025 08:19:39 +0100 Subject: [PATCH] Added a concrete recognition path for TYPE_TAG_PEL_SCHEME_DESC_1 Artifacts by exposing canonical checks and wiring them into amduat-pel validate. --- include/amduat/pel/program_dag_desc.h | 7 ++ src/pel_stack/program_dag/program_dag_desc.c | 84 ++++++++++++++++---- src/tools/amduat_pel_cli.c | 2 +- 3 files changed, 76 insertions(+), 17 deletions(-) diff --git a/include/amduat/pel/program_dag_desc.h b/include/amduat/pel/program_dag_desc.h index 3c5b1d1..4039f21 100644 --- a/include/amduat/pel/program_dag_desc.h +++ b/include/amduat/pel/program_dag_desc.h @@ -2,6 +2,7 @@ #define AMDUAT_PEL_PROGRAM_DAG_DESC_H #include "amduat/asl/core.h" +#include "amduat/enc/pel_program_dag_desc.h" #include @@ -16,6 +17,12 @@ enum { amduat_reference_t amduat_pel_program_dag_scheme_ref(void); +bool amduat_pel_program_dag_desc_is_canonical( + const amduat_pel_dag_scheme_descriptor_t *desc); + +bool amduat_pel_program_dag_desc_is_canonical_artifact( + const amduat_artifact_t *artifact); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/pel_stack/program_dag/program_dag_desc.c b/src/pel_stack/program_dag/program_dag_desc.c index eddf849..3f7fbbc 100644 --- a/src/pel_stack/program_dag/program_dag_desc.c +++ b/src/pel_stack/program_dag/program_dag_desc.c @@ -2,28 +2,31 @@ #include "amduat/asl/ref_derive.h" #include "amduat/enc/asl1_core.h" +#include "amduat/enc/pel_program_dag.h" #include "amduat/hash/asl1.h" #include +static const char k_scheme_name[] = "PEL/PROGRAM-DAG/1"; +static const uint8_t k_descriptor_bytes[] = { + 0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x50, 0x45, + 0x4c, 0x2f, 0x50, 0x52, 0x4f, 0x47, 0x52, 0x41, + 0x4d, 0x2d, 0x44, 0x41, 0x47, 0x2f, 0x31, 0x00, + 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00 +}; +static uint8_t k_digest[] = { + 0xc5, 0x0f, 0xb2, 0xa7, 0x34, 0xa5, 0xcc, 0x23, + 0x3c, 0x38, 0x75, 0xb7, 0x0a, 0x7d, 0x96, 0xea, + 0xad, 0x37, 0x4f, 0x00, 0x00, 0x29, 0x77, 0x1d, + 0x8b, 0xef, 0x1a, 0xf2, 0xcd, 0x63, 0x84, 0xdd +}; + amduat_reference_t amduat_pel_program_dag_scheme_ref(void) { - static const uint8_t descriptor_bytes[] = { - 0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x50, 0x45, - 0x4c, 0x2f, 0x50, 0x52, 0x4f, 0x47, 0x52, 0x41, - 0x4d, 0x2d, 0x44, 0x41, 0x47, 0x2f, 0x31, 0x00, - 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00 - }; - static uint8_t digest[] = { - 0xc5, 0x0f, 0xb2, 0xa7, 0x34, 0xa5, 0xcc, 0x23, - 0x3c, 0x38, 0x75, 0xb7, 0x0a, 0x7d, 0x96, 0xea, - 0xad, 0x37, 0x4f, 0x00, 0x00, 0x29, 0x77, 0x1d, - 0x8b, 0xef, 0x1a, 0xf2, 0xcd, 0x63, 0x84, 0xdd - }; static bool initialized = false; if (!initialized) { amduat_artifact_t artifact = amduat_artifact_with_type( - amduat_octets(descriptor_bytes, sizeof(descriptor_bytes)), + amduat_octets(k_descriptor_bytes, sizeof(k_descriptor_bytes)), amduat_type_tag(AMDUAT_PEL_TYPE_TAG_SCHEME_DESC_1)); amduat_reference_t derived = amduat_reference(0u, amduat_octets(NULL, 0u)); @@ -33,13 +36,62 @@ amduat_reference_t amduat_pel_program_dag_scheme_ref(void) { &derived, NULL) && derived.digest.data != NULL && - derived.digest.len == sizeof(digest)) { - memcpy(digest, derived.digest.data, sizeof(digest)); + derived.digest.len == sizeof(k_digest)) { + memcpy(k_digest, derived.digest.data, sizeof(k_digest)); } amduat_reference_free(&derived); initialized = true; } return amduat_reference(AMDUAT_HASH_ASL1_ID_SHA256, - amduat_octets(digest, sizeof(digest))); + amduat_octets(k_digest, sizeof(k_digest))); +} + +bool amduat_pel_program_dag_desc_is_canonical( + const amduat_pel_dag_scheme_descriptor_t *desc) { + if (desc == NULL) { + return false; + } + if (desc->pel1_version != 1) { + return false; + } + if (desc->scheme_name.len != sizeof(k_scheme_name) - 1 || + desc->scheme_name.data == NULL || + memcmp(desc->scheme_name.data, + k_scheme_name, + sizeof(k_scheme_name) - 1) != 0) { + return false; + } + if (desc->program_type_tag.tag_id != AMDUAT_PEL_TYPE_TAG_PROGRAM_DAG_1) { + return false; + } + if (desc->program_enc_profile != AMDUAT_PEL_ENC_PROGRAM_DAG_V1) { + return false; + } + if (desc->has_trace_profile_ref || desc->has_opreg_ref) { + return false; + } + return true; +} + +bool amduat_pel_program_dag_desc_is_canonical_artifact( + const amduat_artifact_t *artifact) { + amduat_pel_dag_scheme_descriptor_t desc; + bool ok = false; + + if (artifact == NULL) { + return false; + } + if (!artifact->has_type_tag || + artifact->type_tag.tag_id != AMDUAT_PEL_TYPE_TAG_SCHEME_DESC_1) { + return false; + } + + memset(&desc, 0, sizeof(desc)); + if (!amduat_enc_pel_program_dag_desc_decode_v1(artifact->bytes, &desc)) { + return false; + } + ok = amduat_pel_program_dag_desc_is_canonical(&desc); + amduat_enc_pel_program_dag_desc_free(&desc); + return ok; } diff --git a/src/tools/amduat_pel_cli.c b/src/tools/amduat_pel_cli.c index 0f50517..f8fe76c 100644 --- a/src/tools/amduat_pel_cli.c +++ b/src/tools/amduat_pel_cli.c @@ -1171,8 +1171,8 @@ static int amduat_pel_cli_cmd_validate( amduat_asl_artifact_free(&artifact); return AMDUAT_PEL_CLI_EXIT_CODEC; } + valid = amduat_pel_program_dag_desc_is_canonical(&desc); amduat_enc_pel_program_dag_desc_free(&desc); - valid = true; } else { if (artifact.has_type_tag && artifact.type_tag.tag_id != AMDUAT_PEL_TYPE_TAG_PROGRAM_DAG_1) {