libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
Loading...
Searching...
No Matches
lfg.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  ngc_lfg_ctx
 LFG context holding the 521-word circular buffer and byte position. More...

Macros

#define NGC_LFG_K   521
 LFG buffer size (number of uint32 words in state).
#define NGC_LFG_J   32
 LFG second tap.
#define NGC_LFG_SEED_SIZE   17
 Number of uint32 words needed to seed the LFG.

Functions

void ngc_lfg_set_seed (struct ngc_lfg_ctx *ctx, const uint32_t seed[17])
 Initialize the LFG from a 17-word big-endian seed.
void ngc_lfg_get_bytes (struct ngc_lfg_ctx *ctx, uint8_t *out, size_t count)
 Generate count bytes of junk data into out.
size_t ngc_lfg_get_seed (const uint8_t *data, size_t size, size_t data_offset, uint32_t seed_out[17])
 Try to extract the LFG seed from a chunk of data.

Macro Definition Documentation

◆ NGC_LFG_J

#define NGC_LFG_J   32

LFG second tap.

Definition at line 35 of file lfg.h.

Referenced by lfg_backward(), and lfg_forward().

◆ NGC_LFG_K

#define NGC_LFG_K   521

LFG buffer size (number of uint32 words in state).

Definition at line 34 of file lfg.h.

Referenced by lfg_backward(), lfg_forward(), lfg_initialize(), lfg_reinitialize(), ngc_lfg_get_bytes(), and ngc_lfg_get_seed().

◆ NGC_LFG_SEED_SIZE

#define NGC_LFG_SEED_SIZE   17

Function Documentation

◆ ngc_lfg_get_bytes()

void ngc_lfg_get_bytes ( struct ngc_lfg_ctx * ctx,
uint8_t * out,
size_t count )

Generate count bytes of junk data into out.

Parameters
ctxLFG context (must be initialized via ngc_lfg_set_seed).
outOutput buffer to fill.
countNumber of bytes to generate.

< LFG buffer size (number of uint32 words in state).

< LFG buffer size (number of uint32 words in state).

Definition at line 82 of file lfg.c.

References ngc_lfg_ctx::buffer, lfg_forward(), NGC_LFG_K, and ngc_lfg_ctx::position_bytes.

Referenced by ngcw_regenerate_junk_sector(), and wii_reconstruct_group_junk().

◆ ngc_lfg_get_seed()

size_t ngc_lfg_get_seed ( const uint8_t * data,
size_t size,
size_t data_offset,
uint32_t seed_out[17] )

Try to extract the LFG seed from a chunk of data.

Attempts to reverse-engineer the 17-word seed from a buffer of suspected PRNG output. Requires at least NGC_LFG_K * 4 = 2084 bytes of contiguous PRNG output aligned to uint32 boundaries.

Parameters
dataPointer to the data to test.
sizeNumber of bytes available.
data_offsetByte offset of data[0] within its LFG block (0x8000-aligned for Wii, arbitrary for GC).
seed_outIf successful, receives the 17-word seed (big-endian).
Returns
The number of consecutive bytes from data[0] that match the LFG. Returns 0 if the data does not look like junk.

< LFG buffer size (number of uint32 words in state).

< LFG buffer size (number of uint32 words in state).

< LFG buffer size (number of uint32 words in state).

< LFG buffer size (number of uint32 words in state).

< LFG buffer size (number of uint32 words in state).

< LFG buffer size (number of uint32 words in state).

< LFG buffer size (number of uint32 words in state).

< LFG buffer size (number of uint32 words in state).

< LFG buffer size (number of uint32 words in state).

< LFG buffer size (number of uint32 words in state).

< LFG buffer size (number of uint32 words in state).

Definition at line 121 of file lfg.c.

References ngc_lfg_ctx::buffer, lfg_backward(), lfg_forward(), lfg_reinitialize(), NGC_LFG_K, NGC_LFG_SEED_SIZE, ngc_lfg_ctx::position_bytes, and swap32().

◆ ngc_lfg_set_seed()

void ngc_lfg_set_seed ( struct ngc_lfg_ctx * ctx,
const uint32_t seed[17] )

Initialize the LFG from a 17-word big-endian seed.

Parameters
ctxLFG context to initialize.
seedArray of 17 uint32 seed words (big-endian).

< Number of uint32 words needed to seed the LFG.

Definition at line 73 of file lfg.c.

References ngc_lfg_ctx::buffer, lfg_initialize(), NGC_LFG_SEED_SIZE, ngc_lfg_ctx::position_bytes, and swap32().

Referenced by ngcw_regenerate_junk_sector(), and wii_reconstruct_group_junk().