From 113236754315de718857edea23d7aaa513bbe5cf Mon Sep 17 00:00:00 2001
From: Ali Polatel <alip@hexsys.org>
Date: Tue, 9 Sep 2025 16:28:02 +0200
Subject: [PATCH] magic: recognize syd encrypted files

Documentation: https://man.exherbo.org/syd.7.html#Crypt_Sandboxing
Signed-off-by: Ali Polatel <alip@hexsys.org>
---
 magic/Magdir/syd  | 37 +++++++++++++++++++++++++++++++++++++
 magic/Makefile.am |  1 +
 2 files changed, 38 insertions(+)
 create mode 100644 magic/Magdir/syd

diff --git a/magic/Magdir/syd b/magic/Magdir/syd
new file mode 100644
index 00000000..0203d6f8
--- /dev/null
+++ b/magic/Magdir/syd
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+# $File: syd,v $
+# syd: file(1) magic for syd(1) encrypted files
+#
+# From: Ali Polatel <alip@chesswob.org>
+# Documentation: https://man.exherbo.org/syd.7.html#Crypt_Sandboxing
+# No defined extension yet; files are recognized by magic header only.
+#
+# Layout:
+#   0..3   : "\x7fSYD"
+#   4	   : version byte (current API: 3)
+#   5..36  : HMAC (32 bytes, SHA256)
+#   37..52 : IV (16 bytes)
+#   53..   : ciphertext (AES-256-CTR)
+#------------------------------------------------------------------------------
+
+# Header and version
+0		string		\x7fSYD		SYD encrypted file
+>4		ubyte		x		\b, version %u
+
+# Version 3: algorithm + HMAC/IV as hex blobs + ciphertext size
+>>4		ubyte		=3		\b, AES-256-CTR; HMAC-SHA256:
+>>>5		 belong		 x		\b%08x
+>>>9		 belong		 x		\b%08x
+>>>13		 belong		 x		\b%08x
+>>>17		 belong		 x		\b%08x
+>>>21		 belong		 x		\b%08x
+>>>25		 belong		 x		\b%08x
+>>>29		 belong		 x		\b%08x
+>>>33		 belong		 x		\b%08x
+>>>37		 belong		 x		\b, IV:%08x
+>>>41		 belong		 x		\b%08x
+>>>45		 belong		 x		\b%08x
+>>>49		 belong		 x		\b%08x
+>>>-0		 offset-53	 x		\b, ciphertext %llu bytes
+
+# End of syd
diff --git a/magic/Makefile.am b/magic/Makefile.am
index 0a99b836..49241d5b 100644
--- a/magic/Makefile.am
+++ b/magic/Makefile.am
@@ -304,6 +304,7 @@ $(MAGIC_FRAGMENT_DIR)/statistics \
 $(MAGIC_FRAGMENT_DIR)/subtitle \
 $(MAGIC_FRAGMENT_DIR)/sun \
 $(MAGIC_FRAGMENT_DIR)/svf \
+$(MAGIC_FRAGMENT_DIR)/syd \
 $(MAGIC_FRAGMENT_DIR)/sylk \
 $(MAGIC_FRAGMENT_DIR)/symbos \
 $(MAGIC_FRAGMENT_DIR)/sysex \
-- 
2.51.0

