libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
Loading...
Searching...
No Matches
lfg.h
Go to the documentation of this file.
1/*
2 * This file is part of the Aaru Data Preservation Suite.
3 * Copyright (c) 2019-2026 Natalia Portillo.
4 *
5 * This library is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation; version 2.1 of the License.
8 *
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see
16 * <https://www.gnu.org/licenses/>.
17 *
18 * Lagged Fibonacci Generator for Nintendo GameCube/Wii junk fill.
19 * Based on Dolphin emulator's LaggedFibonacciGenerator (CC0 licensed).
20 */
21
22#ifndef LIBAARUFORMAT_NGCW_LFG_H
23#define LIBAARUFORMAT_NGCW_LFG_H
24
25#include <stdbool.h>
26#include <stddef.h>
27#include <stdint.h>
28
29#ifdef __cplusplus
30extern "C"
31{
32#endif
33
34#define NGC_LFG_K 521
35#define NGC_LFG_J 32
36#define NGC_LFG_SEED_SIZE 17
37
42 {
43 uint32_t buffer[NGC_LFG_K];
45 };
46
53 void ngc_lfg_set_seed(struct ngc_lfg_ctx *ctx, const uint32_t seed[NGC_LFG_SEED_SIZE]);
54
62 void ngc_lfg_get_bytes(struct ngc_lfg_ctx *ctx, uint8_t *out, size_t count);
63
80 size_t ngc_lfg_get_seed(const uint8_t *data, size_t size, size_t data_offset, uint32_t seed_out[NGC_LFG_SEED_SIZE]);
81
82#ifdef __cplusplus
83}
84#endif
85
86#endif /* LIBAARUFORMAT_NGCW_LFG_H */
#define NGC_LFG_K
LFG buffer size (number of uint32 words in state).
Definition lfg.h:34
void ngc_lfg_get_bytes(struct ngc_lfg_ctx *ctx, uint8_t *out, size_t count)
Generate count bytes of junk data into out.
Definition lfg.c:82
#define NGC_LFG_SEED_SIZE
Number of uint32 words needed to seed the LFG.
Definition lfg.h:36
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.
Definition lfg.c:73
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.
Definition lfg.c:121
LFG context holding the 521-word circular buffer and byte position.
Definition lfg.h:42
size_t position_bytes
Definition lfg.h:44
uint32_t buffer[521]
Definition lfg.h:43