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

Applies the DSi AES-CTR transform with little-endian counter advancement. Encryption and decryption are the same operation; overloads support isolated buffers, arbitrary slices, and bounded caller-owned streams. More...

Static Public Member Functions

static byte[] Transform (ReadOnlySpan< byte > data, NdsModcryptContext context, NdsModcryptArea area, long byteOffset=0)
 Transforms an independent buffer using one area from an immutable header-derived context.
static byte[] Transform (ReadOnlySpan< byte > data, ReadOnlySpan< byte > key, ReadOnlySpan< byte > initialCounter, long byteOffset=0)
 Transforms an independent buffer using explicit AES normal-key and initial-counter bytes.
static async ValueTask TransformAsync (Stream source, Stream destination, long length, NdsModcryptContext context, NdsModcryptArea area, long byteOffset=0, CancellationToken cancellationToken=default)
 Transforms exactly length bytes without closing either stream. If a late source truncation occurs, already completed chunks remain in the destination so callers can diagnose progress.
static async ValueTask TransformAsync (Stream source, Stream destination, long length, ReadOnlyMemory< byte > key, ReadOnlyMemory< byte > initialCounter, long byteOffset=0, CancellationToken cancellationToken=default)
 Transforms an exact stream interval with explicit normal-key and counter material. This overload is useful for tooling that obtains counters outside a parsed image while preserving bounded, allocation-stable I/O.

Static Public Attributes

const int BlockSize = 16
 Defines the AES-128 key, counter, and keystream block width imposed by the cartridge format.

Detailed Description

Applies the DSi AES-CTR transform with little-endian counter advancement. Encryption and decryption are the same operation; overloads support isolated buffers, arbitrary slices, and bounded caller-owned streams.

Definition at line 9 of file NdsModcrypt.cs.

Member Function Documentation

◆ Transform() [1/2]

byte[] NdsForge.NdsModcrypt.Transform ( ReadOnlySpan< byte > data,
NdsModcryptContext context,
NdsModcryptArea area,
long byteOffset = 0 )
inlinestatic

Transforms an independent buffer using one area from an immutable header-derived context.

Parameters
dataCiphertext or plaintext bytes beginning at byteOffset .
contextResolved key material and HMAC-derived counters.
areaFirst or second modcrypt area.
byteOffsetLogical byte offset within that area, allowing correct unaligned slice processing.
Returns
A new array; the input and context remain unchanged.

Definition at line 22 of file NdsModcrypt.cs.

◆ Transform() [2/2]

byte[] NdsForge.NdsModcrypt.Transform ( ReadOnlySpan< byte > data,
ReadOnlySpan< byte > key,
ReadOnlySpan< byte > initialCounter,
long byteOffset = 0 )
inlinestatic

Transforms an independent buffer using explicit AES normal-key and initial-counter bytes.

Parameters
dataCiphertext or plaintext bytes beginning at byteOffset .
keyExactly sixteen bytes containing a normal AES key.
initialCounterExactly sixteen bytes in DSi counter order.
byteOffsetLogical byte offset from the beginning of the encrypted area.
Returns
A transformed copy suitable for encryption or decryption.

Definition at line 38 of file NdsModcrypt.cs.

◆ TransformAsync() [1/2]

async ValueTask NdsForge.NdsModcrypt.TransformAsync ( Stream source,
Stream destination,
long length,
NdsModcryptContext context,
NdsModcryptArea area,
long byteOffset = 0,
CancellationToken cancellationToken = default )
inlinestatic

Transforms exactly length bytes without closing either stream. If a late source truncation occurs, already completed chunks remain in the destination so callers can diagnose progress.

Parameters
sourceReadable stream positioned at the requested area slice.
destinationWritable stream receiving the same number of transformed bytes.
lengthExact number of bytes to consume; trailing source bytes are left unread.
contextResolved key material and both initial counters.
areaFirst or second modcrypt area.
byteOffsetLogical slice offset within the selected area.
cancellationTokenCancels reads, cryptographic chunk processing, or writes.
Returns
A task-like value that completes after exactly length bytes have been transformed.

Definition at line 63 of file NdsModcrypt.cs.

◆ TransformAsync() [2/2]

async ValueTask NdsForge.NdsModcrypt.TransformAsync ( Stream source,
Stream destination,
long length,
ReadOnlyMemory< byte > key,
ReadOnlyMemory< byte > initialCounter,
long byteOffset = 0,
CancellationToken cancellationToken = default )
inlinestatic

Transforms an exact stream interval with explicit normal-key and counter material. This overload is useful for tooling that obtains counters outside a parsed image while preserving bounded, allocation-stable I/O.

Parameters
sourceReadable stream positioned at the requested encrypted or plaintext slice.
destinationDistinct writable stream receiving exactly length bytes.
lengthExact byte count; a shorter source raises EndOfStreamException.
keyExactly sixteen bytes containing a normal AES key.
initialCounterExactly sixteen initial counter bytes.
byteOffsetLogical source position relative to the area's first byte.
cancellationTokenCancels reads, cryptographic chunk processing, or writes.
Returns
A task-like value that completes after exactly length bytes have been transformed.

Definition at line 95 of file NdsModcrypt.cs.

Member Data Documentation

◆ BlockSize

const int NdsForge.NdsModcrypt.BlockSize = 16
static

Defines the AES-128 key, counter, and keystream block width imposed by the cartridge format.

Definition at line 12 of file NdsModcrypt.cs.


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