Files
DomiStream/tools/vectors/gcm_vectors.cs
T
mnovak 7326767f37 [domistream] Tests: vector generator and shared test helpers
tools/vectors/gen_vectors.py makes the crypto vectors with tools independent of
RustCrypto: Python hashlib (SHA-256), the OpenSSL 3.5 CLI (RSA-2048 test-only
keys, X.509 certs, PKCS#1 v1.5 SHA-256 signatures, AES-128-ECB -nopad,
AES-128-CBC) and .NET 10 AesGcm (gcm_vectors.cs). Output goes to
crates/domistream/tests/fixtures (text only); not generated in this commit.

tests/common: seeded and scripted RandomSource, fixture reader, an independent
GF(2^8)/0x11D reference with Cauchy matrices, and test hosts that packetize
video (PROTOCOL.md 5.2-5.3) and audio (6.2-6.4).

Dev-dependencies: proptest (std only, no fork/timeout) and peak_alloc (MIT,
counting allocator for the allocation-cap test).
2026-11-25 12:51:00 +01:00

33 lines
1.3 KiB
C#

// AES-128-GCM test vectors for DomiStream (control frames and video packets), computed with .NET's AesGcm, a
// crypto implementation independent of the RustCrypto crates DomiStream uses.
//
// Run by gen_vectors.py (`dotnet run gcm_vectors.cs -- <input> <output>`), never by hand. Input lines:
// <name> <key hex> <nonce hex> <plaintext hex>
// Output lines:
// <name> <ciphertext hex> <tag hex>
// No associated data, 16-byte tags (docs/PROTOCOL.md 3.2 and 7). Keys are fixed test-only values.
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
var input = File.ReadAllLines(args[0]);
var output = new StringBuilder();
foreach (var line in input)
{
if (line.Trim().Length == 0) continue;
var parts = line.Split(' ');
var key = Convert.FromHexString(parts[1]);
var nonce = Convert.FromHexString(parts[2]);
var plaintext = parts[3] == "-" ? Array.Empty<byte>() : Convert.FromHexString(parts[3]);
var ciphertext = new byte[plaintext.Length];
var tag = new byte[16];
using var gcm = new AesGcm(key, 16);
gcm.Encrypt(nonce, plaintext, ciphertext, tag);
output.Append(parts[0]).Append(' ')
.Append(ciphertext.Length == 0 ? "-" : Convert.ToHexString(ciphertext)).Append(' ')
.Append(Convert.ToHexString(tag)).Append('\n');
}
File.WriteAllText(args[1], output.ToString());