NdsForge.NET 1.0.1
Read, validate, edit, compare, and build Nintendo DS and DSi images from .NET
Loading...
Searching...
No Matches
NdsForge.NdsModcryptContext Class Referencesealed

Captures the AES-128 normal key and both HMAC-derived initial counters needed to transform DSi modcrypt areas. Every byte array is copied so a reviewed context cannot change when its source buffers are reused or cleared. More...

Public Member Functions

 NdsModcryptContext (ReadOnlySpan< byte > key, ReadOnlySpan< byte > area1Counter, ReadOnlySpan< byte > area2Counter, NdsModcryptKeyMode keyMode=NdsModcryptKeyMode.SecureNormalKey)
 Copies already resolved key and counter material after enforcing the fixed AES block boundary.
ReadOnlyMemory< byte > ExportKey ()
 Returns an independent copy of the resolved AES key so callers can persist or clear it on their own terms.
ReadOnlyMemory< byte > ExportCounter (NdsModcryptArea area)
 Returns an independent copy of the initial counter selected for one declared modcrypt area.

Static Public Member Functions

static NdsModcryptContext FromHeader (NdsHeader header)
 Resolves public header-key mode automatically and otherwise derives the normal key from the public modcrypt KeyX recipe and the stored ARM9i HMAC KeyY bytes. The result makes no authentication claim about that HMAC.
static NdsModcryptContext FromHeader (NdsHeader header, ReadOnlySpan< byte > secureNormalKey)
 Uses an explicitly resolved secure normal key instead of applying the built-in modcrypt KeyX/KeyY recipe. This is intended for independently verified vectors and future variants; insecure headers reject overrides.

Properties

NdsModcryptKeyMode KeyMode [get]
 Preserves whether the normal key was public header data or supplied by an external secure-key authority.

Detailed Description

Captures the AES-128 normal key and both HMAC-derived initial counters needed to transform DSi modcrypt areas. Every byte array is copied so a reviewed context cannot change when its source buffers are reused or cleared.

Definition at line 7 of file NdsModcryptContext.cs.

Constructor & Destructor Documentation

◆ NdsModcryptContext()

NdsForge.NdsModcryptContext.NdsModcryptContext ( ReadOnlySpan< byte > key,
ReadOnlySpan< byte > area1Counter,
ReadOnlySpan< byte > area2Counter,
NdsModcryptKeyMode keyMode = NdsModcryptKeyMode::SecureNormalKey )
inline

Copies already resolved key and counter material after enforcing the fixed AES block boundary.

Parameters
keyExactly sixteen bytes containing an AES-128 normal key, not a KeyX or KeyY component.
area1CounterExactly sixteen initial counter bytes for the first area.
area2CounterExactly sixteen initial counter bytes for the second area.
keyModeProvenance label retained for diagnostics and policy decisions.

Definition at line 21 of file NdsModcryptContext.cs.

Member Function Documentation

◆ ExportCounter()

ReadOnlyMemory< byte > NdsForge.NdsModcryptContext.ExportCounter ( NdsModcryptArea area)
inline

Returns an independent copy of the initial counter selected for one declared modcrypt area.

Parameters
areaHeader area whose HMAC-derived counter is required.
Returns
Sixteen counter bytes safe for caller mutation.

Definition at line 51 of file NdsModcryptContext.cs.

◆ ExportKey()

ReadOnlyMemory< byte > NdsForge.NdsModcryptContext.ExportKey ( )
inline

Returns an independent copy of the resolved AES key so callers can persist or clear it on their own terms.

Returns
Sixteen normal-key bytes backed by a new array that does not expose the context's retained key.

Definition at line 46 of file NdsModcryptContext.cs.

◆ FromHeader() [1/2]

NdsModcryptContext NdsForge.NdsModcryptContext.FromHeader ( NdsHeader header)
inlinestatic

Resolves public header-key mode automatically and otherwise derives the normal key from the public modcrypt KeyX recipe and the stored ARM9i HMAC KeyY bytes. The result makes no authentication claim about that HMAC.

Parameters
headerParsed DSi-family header containing flags, title bytes, and HMAC counters.
Returns
A detached context that remains valid after the image is disposed.

Definition at line 59 of file NdsModcryptContext.cs.

◆ FromHeader() [2/2]

NdsModcryptContext NdsForge.NdsModcryptContext.FromHeader ( NdsHeader header,
ReadOnlySpan< byte > secureNormalKey )
inlinestatic

Uses an explicitly resolved secure normal key instead of applying the built-in modcrypt KeyX/KeyY recipe. This is intended for independently verified vectors and future variants; insecure headers reject overrides.

Parameters
headerParsed DSi-family header supplying both area counters.
secureNormalKeyExactly sixteen already scrambled normal-key bytes.
Returns
A detached context retaining a copy of every cryptographic input.

Definition at line 87 of file NdsModcryptContext.cs.

Property Documentation

◆ KeyMode

NdsModcryptKeyMode NdsForge.NdsModcryptContext.KeyMode
get

Preserves whether the normal key was public header data or supplied by an external secure-key authority.

Definition at line 42 of file NdsModcryptContext.cs.


The documentation for this class was generated from the following file: