/* * poison_inline_host.c — 验证 IGPoisonInline.h 内联核心与 IGPoison.c out-of-line 公共入口 * 语义等价(单一真源不漂移),且推荐接入形态 ig_poison_mix_key_inline 行为正确: * 健康→密钥不变(解密正常),毒化→密钥被扰动(解出乱码)。 * 退出码 0=全部用例通过。由 tests/test_poison_inline.py 编译运行。 */ #include #include #include #include "poison/IGPoison.h" #include "poison/IGPoisonInline.h" static int fails = 0; static void check(int cond, const char *msg) { printf("%s: %s\n", cond ? "ok" : "FAIL", msg); if (!cond) fails++; } int main(void) { ig_poison_init(); /* —— 健康态 —— */ check(ig_poison_mask() == 0, "healthy: public mask==0"); check(ig_poison_mask_inline() == 0, "healthy: inline mask==0"); check(ig_poison_mask_inline() == ig_poison_mask(), "healthy: inline mask==public mask"); uint8_t ref[16]; for (int i = 0; i < 16; ++i) ref[i] = (uint8_t)(i * 7 + 1); uint8_t key[16]; memcpy(key, ref, 16); ig_poison_mix_key_inline(key, 16); check(memcmp(key, ref, 16) == 0, "healthy: mix_key 恒等(密钥不变→解密正常)"); uint8_t o1[16], o2[16]; ig_poison_apply(ref, o1, 16); ig_poison_apply_inline(ref, o2, 16); check(memcmp(o1, o2, 16) == 0, "healthy: inline apply == public apply"); check(memcmp(o1, ref, 16) == 0, "healthy: apply 恒等"); /* —— 毒化态 —— */ ig_poison_mark(0xDEADBEEF12345678ULL); check(ig_poison_mask() != 0, "poisoned: public mask!=0"); check(ig_poison_mask_inline() == ig_poison_mask(), "poisoned: inline mask==public mask"); memcpy(key, ref, 16); ig_poison_mix_key_inline(key, 16); check(memcmp(key, ref, 16) != 0, "poisoned: mix_key 扰动密钥(→解出乱码)"); ig_poison_apply(ref, o1, 16); ig_poison_apply_inline(ref, o2, 16); check(memcmp(o1, o2, 16) == 0, "poisoned: inline apply == public apply"); check(memcmp(o1, ref, 16) != 0, "poisoned: apply 扰动输出"); printf("%d fail\n", fails); return fails ? 1 : 0; }