NdsForge.NET 1.0.1
Read, validate, edit, compare, and build Nintendo DS and DSi images from .NET
Loading...
Searching...
No Matches
NdsDsiIntegrityOptions.cs
1namespace NdsForge;
2
8public sealed class NdsDsiIntegrityOptions
9{
11 private readonly byte[]? _hmacKey;
13 private readonly INdsDsiSignatureProvider? _signatureProvider;
14
16 public static NdsDsiIntegrityOptions Unauthenticated { get; } = new(null, NdsDsiSignatureMode.Cleared, null);
17
22 public static NdsDsiIntegrityOptions NdstoolHomebrew { get; } = new(
23 [
24 0x21, 0x06, 0xC0, 0xDE, 0xBA, 0x98, 0xCE, 0x3F, 0xA6, 0x92, 0xE3, 0x9D, 0x46, 0xF2, 0xED, 0x01,
25 0x76, 0xE3, 0xCC, 0x08, 0x56, 0x23, 0x63, 0xFA, 0xCA, 0xD4, 0xEC, 0xDF, 0x9A, 0x62, 0x78, 0x34,
26 0x8F, 0x6D, 0x63, 0x3C, 0xFE, 0x22, 0xCA, 0x92, 0x20, 0x88, 0x97, 0x23, 0xD2, 0xCF, 0xAE, 0xC2,
27 0x32, 0x67, 0x8D, 0xFE, 0xCA, 0x83, 0x64, 0x98, 0xAC, 0xFD, 0x3E, 0x37, 0x87, 0x46, 0x58, 0x24,
28 ],
29 NdsDsiSignatureMode.NoGbaDevelopmentMarker,
30 null);
31
37 byte[]? hmacKey,
38 NdsDsiSignatureMode signatureMode,
39 INdsDsiSignatureProvider? signatureProvider)
40 {
41 _hmacKey = hmacKey;
42 SignatureMode = signatureMode;
43 _signatureProvider = signatureProvider;
44 }
45
53 public static NdsDsiIntegrityOptions CreateHmacSha1(
54 ReadOnlySpan<byte> key,
55 NdsDsiSignatureMode signatureMode = NdsDsiSignatureMode.Cleared)
56 {
57 if (key.IsEmpty)
58 {
59 throw new ArgumentException("A DSi HMAC-SHA1 key cannot be empty.", nameof(key));
60 }
61
62 if (signatureMode == NdsDsiSignatureMode.RsaSha1)
63 {
64 throw new ArgumentException("RSA signature mode requires CreateSignedHmacSha1 and a signing provider.", nameof(signatureMode));
65 }
66
67 return new(key.ToArray(), signatureMode, null);
68 }
69
77 public static NdsDsiIntegrityOptions CreateSignedHmacSha1(
78 ReadOnlySpan<byte> hmacKey,
79 INdsDsiSignatureProvider signatureProvider)
80 {
81 if (hmacKey.IsEmpty)
82 {
83 throw new ArgumentException("A DSi HMAC-SHA1 key cannot be empty.", nameof(hmacKey));
84 }
85
86 ArgumentNullException.ThrowIfNull(signatureProvider);
87 return new(hmacKey.ToArray(), NdsDsiSignatureMode.RsaSha1, signatureProvider);
88 }
89
91 public bool ComputesHmacSha1 => _hmacKey is not null;
92
95
97 internal ReadOnlyMemory<byte> HmacKey => _hmacKey;
98
100 internal INdsDsiSignatureProvider? SignatureProvider => _signatureProvider;
101}
Defines which DSi authentication fields a build can honestly produce. Component HMACs use caller-sele...
NdsDsiSignatureMode SignatureMode
Controls only the signature field and never upgrades a development marker into an authenticity claim.
static NdsDsiIntegrityOptions NdstoolHomebrew
Reproduces the public 64-byte HMAC-SHA1 key and no$gba development marker used by modern ndstool buil...
bool ComputesHmacSha1
Indicates whether component HMAC fields are recomputed instead of deliberately cleared.
static NdsDsiIntegrityOptions CreateHmacSha1(ReadOnlySpan< byte > key, NdsDsiSignatureMode signatureMode=NdsDsiSignatureMode.Cleared)
Copies an application-supplied HMAC-SHA1 key without assigning it any implicit provenance....
static NdsDsiIntegrityOptions CreateSignedHmacSha1(ReadOnlySpan< byte > hmacKey, INdsDsiSignatureProvider signatureProvider)
Combines component HMAC generation with a real header signature supplied by a caller-controlled autho...
static NdsDsiIntegrityOptions Unauthenticated
Uses zeroed HMAC and signature fields for a clearly unauthenticated DSi image.
Abstracts DSi header signing so build pipelines may use a managed private key, hardware-backed key,...
NdsDsiSignatureMode
Selects how a DSi build populates the 128-byte signature field under an explicit authenticity policy.