Skip to content

Commit ba2c5fe

Browse files
committed
Fix CPUID subleaf iteration
1 parent b4a1da9 commit ba2c5fe

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/randomenv.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,23 @@ void AddAllCPUID(CSHA512& hasher)
198198
AddCPUID(hasher, 0, 0, ax, bx, cx, dx); // Returns max leaf in ax
199199
uint32_t max = ax;
200200
for (uint32_t leaf = 1; leaf <= max; ++leaf) {
201+
uint32_t maxsub = 0;
201202
for (uint32_t subleaf = 0;; ++subleaf) {
202203
AddCPUID(hasher, leaf, subleaf, ax, bx, cx, dx);
203-
// Iterate over subleaves for leaf 4, 11, 13
204-
if (leaf != 4 && leaf != 11 && leaf != 13) break;
205-
if ((leaf == 4 || leaf == 13) && ax == 0) break;
206-
if (leaf == 11 && (cx & 0xFF00) == 0) break;
204+
// Iterate subleafs for leaf values 4, 7, 11, 13
205+
if (leaf == 4) {
206+
if ((ax & 0x1f) == 0) break;
207+
} else if (leaf == 7) {
208+
if (subleaf == 0) maxsub = ax;
209+
if (subleaf == maxsub) break;
210+
} else if (leaf == 11) {
211+
if ((cx & 0xff00) == 0) break;
212+
} else if (leaf == 13) {
213+
if (ax == 0 && bx == 0 && cx == 0 && dx == 0) break;
214+
} else {
215+
// For any other leaf, stop after subleaf 0.
216+
break;
217+
}
207218
}
208219
}
209220
// Iterate over all extended leaves

0 commit comments

Comments
 (0)