2032
The example code is taken from the PRNG inside the buggy OpenPiton SoC of HACK@DAC'21
[REF-1370]. The SoC implements a pseudo-random number generator using a Linear Feedback
Shift Register (LFSR).
An example of LFSR with the polynomial function P(x) = x6+x4+x3+1 is shown in the figure.
Example Language: Verilog (Bad)
reg in_sr, entropy16_valid;
reg [15:0] entropy16;
assign entropy16_o = entropy16;
assign entropy16_valid_o = entropy16_valid;
always @ (*)
begin
in_sr = ^ (poly_i [15:0] & entropy16 [15:0]);
end
A LFSR's input bit is determined by the output of a linear function of two or more of its previous
states. Therefore, given a long cycle, a LFSR-based PRNG will enter a repeating cycle, which is
predictable.
Observed Examples
Reference Description
CVE-2021-3692 PHP framework uses mt_rand() function (Marsenne Twister) when generating
tokens
https://www.cve.org/CVERecord?id=CVE-2021-3692
MemberOf Relationships
This MemberOf relationships table shows additional CWE Catgeories and Views that reference this
weakness as a member. This information is often useful in understanding where a weakness fits
within the context of external information sources.
Nature Type ID Name Page
MemberOf 1205 Security Primitives and Cryptography Issues 1194 2473
MemberOf 1414 Comprehensive Categorization: Randomness 1400 2543
Notes
Maintenance
As of CWE 4.5, terminology related to randomness, entropy, and predictability can vary widely.
Within the developer and other communities, "randomness" is used heavily. However, within
cryptography, "entropy" is distinct, typically implied as a measurement. There are no commonlyused
definitions, even within standards documents and cryptography papers. Future versions of
CWE will attempt to define these terms and, if necessary, distinguish between them in ways that
are appropriate for different communities but do not reduce the usability of CWE for mapping,
understanding, or other scenarios.
Related Attack Patterns
CAPEC-ID Attack Pattern Name
97 Cryptanalysis
References
[REF-1370]"rng_16.v". 2021. < https://github.com/HACK-EVENT/hackatdac21/blob/main/piton/
design/chip/tile/ariane/src/rand_num/rng_16.v#L12-L22 >.2023-07-15.
CWE Version 4.14
CWE-1242: Inclusion of Undocumented Features or Chicken Bits
CWE-1242: Inclusion of Undocumented Features or Chicken Bits