vtrng 0.5.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vtrng-0.5.3/CHANGELOG.md +66 -0
- vtrng-0.5.3/CONTRIBUTING.md +60 -0
- vtrng-0.5.3/LICENCE +21 -0
- vtrng-0.5.3/MANIFEST.in +18 -0
- vtrng-0.5.3/PKG-INFO +413 -0
- vtrng-0.5.3/README.md +373 -0
- vtrng-0.5.3/SECURITY.md +39 -0
- vtrng-0.5.3/docs/api_reference.md +473 -0
- vtrng-0.5.3/docs/applications.md +229 -0
- vtrng-0.5.3/docs/certification.md +106 -0
- vtrng-0.5.3/docs/faq.md +141 -0
- vtrng-0.5.3/docs/for_students.md +324 -0
- vtrng-0.5.3/docs/how_it_works.md +473 -0
- vtrng-0.5.3/docs/index.md +56 -0
- vtrng-0.5.3/docs/quickstart.md +136 -0
- vtrng-0.5.3/docs/visualization.md +322 -0
- vtrng-0.5.3/docs/vm_and_containers.md +100 -0
- vtrng-0.5.3/external/testu01_wrapper.c +133 -0
- vtrng-0.5.3/pyproject.toml +67 -0
- vtrng-0.5.3/scripts/run_dieharder.sh +39 -0
- vtrng-0.5.3/scripts/run_ent.sh +26 -0
- vtrng-0.5.3/scripts/run_testu01.sh +46 -0
- vtrng-0.5.3/setup.cfg +4 -0
- vtrng-0.5.3/setup.py +56 -0
- vtrng-0.5.3/src/vtrng/__init__.py +25 -0
- vtrng-0.5.3/src/vtrng/__main__.py +187 -0
- vtrng-0.5.3/src/vtrng/_compat.py +61 -0
- vtrng-0.5.3/src/vtrng/_fast.c +633 -0
- vtrng-0.5.3/src/vtrng/collector.py +138 -0
- vtrng-0.5.3/src/vtrng/conditioning.py +93 -0
- vtrng-0.5.3/src/vtrng/export.py +168 -0
- vtrng-0.5.3/src/vtrng/generator.py +540 -0
- vtrng-0.5.3/src/vtrng/health.py +87 -0
- vtrng-0.5.3/src/vtrng/nist.py +734 -0
- vtrng-0.5.3/src/vtrng/pool.py +140 -0
- vtrng-0.5.3/src/vtrng/py.typed +1 -0
- vtrng-0.5.3/src/vtrng/seedfile.py +100 -0
- vtrng-0.5.3/src/vtrng/sources.py +193 -0
- vtrng-0.5.3/src/vtrng/sp800_22.py +934 -0
- vtrng-0.5.3/src/vtrng/testrunner.py +327 -0
- vtrng-0.5.3/src/vtrng.egg-info/PKG-INFO +413 -0
- vtrng-0.5.3/src/vtrng.egg-info/SOURCES.txt +48 -0
- vtrng-0.5.3/src/vtrng.egg-info/dependency_links.txt +1 -0
- vtrng-0.5.3/src/vtrng.egg-info/entry_points.txt +2 -0
- vtrng-0.5.3/src/vtrng.egg-info/requires.txt +6 -0
- vtrng-0.5.3/src/vtrng.egg-info/top_level.txt +1 -0
- vtrng-0.5.3/tests/test_basic.py +103 -0
- vtrng-0.5.3/tests/test_distribution.py +0 -0
- vtrng-0.5.3/tests/test_nist.py +372 -0
- vtrng-0.5.3/tests/test_sp800_22.py +268 -0
vtrng-0.5.3/CHANGELOG.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to VTRNG are documented here.
|
|
4
|
+
Format based on [Keep a Changelog](https://keepachangelog.com/).
|
|
5
|
+
|
|
6
|
+
## [0.5.0] - 2026-03-
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
- PyPI package: `pip install vtrng`
|
|
10
|
+
- Full README with examples, architecture diagram, benchmarks
|
|
11
|
+
- GitHub Actions CI/CD (test on Windows/Linux/macOS)
|
|
12
|
+
- Auto-publish to PyPI on git tag
|
|
13
|
+
- Weekly certification workflow
|
|
14
|
+
- Issue and PR templates
|
|
15
|
+
- CONTRIBUTING.md, SECURITY.md
|
|
16
|
+
- Makefile for common operations
|
|
17
|
+
- Documentation (docs/)
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
- Updated pyproject.toml for PyPI metadata
|
|
21
|
+
- Version bumped to 0.5.0
|
|
22
|
+
|
|
23
|
+
## [0.4.0] - 2026-02-20
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
- NIST SP 800-22 statistical test suite (11 tests)
|
|
27
|
+
- Binary exporter for external tools (dieharder, ENT, TestU01)
|
|
28
|
+
- TestU01 C wrapper
|
|
29
|
+
- Automated test runner with tool detection
|
|
30
|
+
- CLI commands: test, certify, export, bench
|
|
31
|
+
- JSON certification report export
|
|
32
|
+
- Shell scripts for external tools
|
|
33
|
+
- 17 new test cases
|
|
34
|
+
|
|
35
|
+
## [0.3.0] - 2026-02-10
|
|
36
|
+
|
|
37
|
+
### Added
|
|
38
|
+
- NIST SP 800-90B entropy estimation (9 estimators)
|
|
39
|
+
- Continuous health testing (RCT + APT)
|
|
40
|
+
- Startup assessment with 1024-sample validation
|
|
41
|
+
- Min-entropy tracking
|
|
42
|
+
- Conservative min(all estimators) approach
|
|
43
|
+
|
|
44
|
+
## [0.2.0]
|
|
45
|
+
|
|
46
|
+
### Added
|
|
47
|
+
- C extension with RDTSC for cycle-accurate timing
|
|
48
|
+
- Background entropy collector daemon thread
|
|
49
|
+
- Package structure (src layout)
|
|
50
|
+
- Variable workload (prevents timing quantization)
|
|
51
|
+
- Delta-of-deltas entropy extraction
|
|
52
|
+
- Retry logic with backoff for health checks
|
|
53
|
+
|
|
54
|
+
### Fixed
|
|
55
|
+
- Repetition count test false positives on Windows
|
|
56
|
+
- Health check too aggressive for quantized timers
|
|
57
|
+
|
|
58
|
+
## [0.1.0]
|
|
59
|
+
|
|
60
|
+
### Added
|
|
61
|
+
- Initial prototype
|
|
62
|
+
- CPU jitter, memory timing, thread race sources
|
|
63
|
+
- Von Neumann debiasing + SHA-512 conditioning
|
|
64
|
+
- 512-byte entropy pool with forward secrecy
|
|
65
|
+
- Basic health monitoring
|
|
66
|
+
- API: random_bytes, random_int, random_float, shuffle, etc.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Contributing to VTRNG
|
|
2
|
+
|
|
3
|
+
Thanks for your interest! VTRNG aims to be the most transparent and
|
|
4
|
+
well-tested pure-software TRNG. Every contribution helps.
|
|
5
|
+
|
|
6
|
+
## How to Contribute
|
|
7
|
+
|
|
8
|
+
### Bug Reports
|
|
9
|
+
- Use the [bug report template](.github/ISSUE_TEMPLATE/bug_report.md)
|
|
10
|
+
- Include your OS, Python version, and CPU model
|
|
11
|
+
- Include the full error traceback
|
|
12
|
+
- Note if you're running in a VM/container
|
|
13
|
+
|
|
14
|
+
### Feature Requests
|
|
15
|
+
- Use the [feature request template](.github/ISSUE_TEMPLATE/feature_request.md)
|
|
16
|
+
|
|
17
|
+
### Code Contributions
|
|
18
|
+
|
|
19
|
+
1. Fork the repo
|
|
20
|
+
2. Create a feature branch: `git checkout -b my-feature`
|
|
21
|
+
3. Make your changes
|
|
22
|
+
4. Run tests: `make test`
|
|
23
|
+
5. Run certification: `make certify`
|
|
24
|
+
6. Submit a PR
|
|
25
|
+
|
|
26
|
+
### Development Setup
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
git clone https://github.com/YOUR_USERNAME/vtrng.git
|
|
30
|
+
cd vtrng
|
|
31
|
+
python -m venv .venv
|
|
32
|
+
source .venv/bin/activate # or .venv\Scripts\activate on Windows
|
|
33
|
+
pip install -e ".[dev]"
|
|
34
|
+
make test
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## Areas We Need Help
|
|
39
|
+
### 🔴 High Priority
|
|
40
|
+
- ARM/Apple Silicon optimization - CNTVCT_EL0 timing
|
|
41
|
+
- Windows high-resolution timer - QueryPerformanceCounter
|
|
42
|
+
- VM detection - auto-detect degraded environments
|
|
43
|
+
### 🟡 Medium Priority
|
|
44
|
+
- New entropy sources - GPU timing, disk I/O jitter, network jitter
|
|
45
|
+
- FIPS 140-3 alignment - documentation and testing
|
|
46
|
+
- Async API - await rng.random_bytes(32)
|
|
47
|
+
### 🟢 Nice to Have
|
|
48
|
+
- WebAssembly port - VTRNG in the browser
|
|
49
|
+
- Rust port — for embedded/systems use
|
|
50
|
+
- Benchmarks - more platforms, more CPUs
|
|
51
|
+
- Code Standards
|
|
52
|
+
- Type hints on all public functions
|
|
53
|
+
- Docstrings with explanation of the physics/math
|
|
54
|
+
- Tests for both positive cases (good data passes) and negative (bad data fails)
|
|
55
|
+
- No external dependencies in core (only stdlib)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## Security
|
|
59
|
+
If you find a security vulnerability, DO NOT open a public issue.
|
|
60
|
+
See [SECURITY.md](SECURITY.md).
|
vtrng-0.5.3/LICENCE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TheDicee Devs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
vtrng-0.5.3/MANIFEST.in
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
include LICENSE
|
|
2
|
+
include README.md
|
|
3
|
+
include CHANGELOG.md
|
|
4
|
+
include CONTRIBUTING.md
|
|
5
|
+
include SECURITY.md
|
|
6
|
+
include pyproject.toml
|
|
7
|
+
include setup.py
|
|
8
|
+
|
|
9
|
+
recursive-include src/vtrng *.py *.c *.pyi
|
|
10
|
+
recursive-include tests *.py
|
|
11
|
+
recursive-include docs *.md
|
|
12
|
+
recursive-include scripts *.sh
|
|
13
|
+
recursive-include external *.c
|
|
14
|
+
|
|
15
|
+
global-exclude __pycache__
|
|
16
|
+
global-exclude *.pyc
|
|
17
|
+
global-exclude *.pyo
|
|
18
|
+
global-exclude *.egg-info
|
vtrng-0.5.3/PKG-INFO
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vtrng
|
|
3
|
+
Version: 0.5.3
|
|
4
|
+
Summary: Very True Random Number Generator, pure-software TRNG from CPU jitter physics
|
|
5
|
+
Author-email: TheDicee Devs <thediceedeveloper@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/TheDiceeDev/vtrng
|
|
8
|
+
Project-URL: Documentation, https://github.com/TheDiceeDev/vtrng
|
|
9
|
+
Project-URL: Repository, https://github.com/TheDiceeDev/vtrng
|
|
10
|
+
Project-URL: Issues, https://github.com/TheDiceeDev/vtrng/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/TheDiceeDev/vtrng
|
|
12
|
+
Keywords: random,trng,rng,entropy,jitter,cryptography,security,nist,randomness,true-random,cpu-jitter,very true,very true rng
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Intended Audience :: Information Technology
|
|
17
|
+
Classifier: Topic :: Security :: Cryptography
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering
|
|
19
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
26
|
+
Classifier: Programming Language :: C
|
|
27
|
+
Classifier: Operating System :: OS Independent
|
|
28
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
29
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
30
|
+
Classifier: Operating System :: MacOS
|
|
31
|
+
Classifier: Typing :: Typed
|
|
32
|
+
Requires-Python: >=3.9
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENCE
|
|
35
|
+
Provides-Extra: fast
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
38
|
+
Requires-Dist: pytest-timeout>=2.0; extra == "dev"
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
<div align="center">
|
|
42
|
+
|
|
43
|
+
# 🎲 VTRNG
|
|
44
|
+
|
|
45
|
+
### Very True Random Number Generator
|
|
46
|
+
|
|
47
|
+
**Pure-software true randomness from CPU jitter physics.**
|
|
48
|
+
**No hardware dongles. No mouse wiggling. No lava lamps.**
|
|
49
|
+
|
|
50
|
+
[](https://pypi.org/project/vtrng/)
|
|
51
|
+
[](https://pypi.org/project/vtrng/)
|
|
52
|
+
[](LICENSE)
|
|
53
|
+
[](https://github.com/TheDiceeDev/vtrng/actions)
|
|
54
|
+
[](docs/certification.md)
|
|
55
|
+
[](docs/certification.md)
|
|
56
|
+
|
|
57
|
+
[Documentation](docs/index.md) •
|
|
58
|
+
[Installation](#installation) •
|
|
59
|
+
[Quick Start](#quick-start) •
|
|
60
|
+
[How It Works](#how-it-works) •
|
|
61
|
+
[Certification](#certification) •
|
|
62
|
+
[API Reference](#api-reference) •
|
|
63
|
+
[FAQ](docs/index.md#faq)
|
|
64
|
+
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## What Is This?
|
|
70
|
+
|
|
71
|
+
VTRNG is a **true random number generator** that runs entirely in
|
|
72
|
+
software. It exploits the physical non-determinism of your CPU -
|
|
73
|
+
thermal noise, cache timing jitter, pipeline hazards, and OS
|
|
74
|
+
scheduling chaos - to generate genuine randomness without any
|
|
75
|
+
special hardware.
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from vtrng import VTRNG
|
|
79
|
+
|
|
80
|
+
rng = VTRNG()
|
|
81
|
+
|
|
82
|
+
rng.random_bytes(32) # 32 truly random bytes
|
|
83
|
+
rng.random_int(1, 100) # unbiased integer [1, 100]
|
|
84
|
+
rng.random_float() # float in [0.0, 1.0)
|
|
85
|
+
rng.coin_flip() # "heads" or "tails"
|
|
86
|
+
rng.uuid4() # random UUID v4
|
|
87
|
+
rng.shuffle([1, 2, 3, 4, 5]) # Fisher-Yates shuffle
|
|
88
|
+
rng.dice(20, 4) # roll 4d20
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Quick links
|
|
94
|
+
|
|
95
|
+
* Full docs: [docs/index.md](/docs/index.md) (this contains the detailed docs, certification info, and API reference)
|
|
96
|
+
* Repo: `https://github.com/TheDiceeDev/vtrng`
|
|
97
|
+
* PyPI: `https://pypi.org/project/vtrng/`
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Why Not Just Use `random` or `os.urandom()`?
|
|
102
|
+
|
|
103
|
+
| Source | Type | How It Works |
|
|
104
|
+
| -------------- | -------- | ------------------------------------------------------- |
|
|
105
|
+
| `random` | ❌ PRNG | Mersenne Twister - deterministic, predictable |
|
|
106
|
+
| `os.urandom()` | ✅ CSPRNG | OS entropy pool - good, but opaque |
|
|
107
|
+
| `secrets` | ✅ CSPRNG | Wrapper around `os.urandom()` |
|
|
108
|
+
| **VTRNG** | ✅ TRNG | Direct physical noise → you control the entire pipeline |
|
|
109
|
+
|
|
110
|
+
VTRNG gives you:
|
|
111
|
+
|
|
112
|
+
* 🔍 **Full transparency** - every step from noise source to output is auditable
|
|
113
|
+
* 📊 **Built-in certification** - NIST SP 800-22 and SP 800-90B test suites included
|
|
114
|
+
* 🏥 **Continuous health monitoring** - refuses to output if entropy degrades
|
|
115
|
+
* 🔬 **Assessed entropy** - knows how much randomness it’s producing
|
|
116
|
+
* 🚫 **No trust required** - does not rely on an opaque OS implementation
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Installation
|
|
121
|
+
|
|
122
|
+
**From PyPI (recommended):**
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
pip install vtrng
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**With C extension (faster, uses RDTSC if available):**
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
pip install "vtrng[fast]"
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**From source (developer):**
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
git clone https://github.com/TheDiceeDev/vtrng.git
|
|
138
|
+
cd vtrng
|
|
139
|
+
pip install -e ".[dev]"
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Quick Start
|
|
145
|
+
|
|
146
|
+
### Basic usage
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from vtrng import VTRNG
|
|
150
|
+
|
|
151
|
+
# Initialize (collects entropy, runs health checks)
|
|
152
|
+
rng = VTRNG()
|
|
153
|
+
|
|
154
|
+
# Generate random values
|
|
155
|
+
secret_key = rng.random_bytes(32)
|
|
156
|
+
pin = rng.random_int(0, 9999)
|
|
157
|
+
probability = rng.random_float()
|
|
158
|
+
token = rng.random_hex(16)
|
|
159
|
+
session_id = rng.uuid4()
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Paranoia levels
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
# Fast - CPU jitter only (~50ms per call)
|
|
166
|
+
rng = VTRNG(paranoia=1)
|
|
167
|
+
|
|
168
|
+
# Moderate - + memory timing (default, ~100ms)
|
|
169
|
+
rng = VTRNG(paranoia=2)
|
|
170
|
+
|
|
171
|
+
# Maximum - + thread racing (~500ms, highest entropy)
|
|
172
|
+
rng = VTRNG(paranoia=3)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Sequences & choices
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
winner = rng.choice(["Alice", "Johntez", "Charlie"])
|
|
179
|
+
team = rng.sample(players, k=5) # 5 unique picks
|
|
180
|
+
colors = rng.choices(["R", "G", "B"], k=10) # with replacement
|
|
181
|
+
|
|
182
|
+
deck = list(range(52))
|
|
183
|
+
shuffled = rng.shuffle(deck)
|
|
184
|
+
|
|
185
|
+
damage = sum(rng.dice(6, 3)) # 3d6
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Diagnostics & Certification
|
|
191
|
+
|
|
192
|
+
Quick diagnostics:
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
rng.print_diagnostics()
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Full NIST SP 800-90B entropy assessment:
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
rng.nist_assessment(n_samples=4096)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Run SP 800-22 statistical test suite:
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
from vtrng import SP800_22Suite
|
|
208
|
+
suite = SP800_22Suite()
|
|
209
|
+
suite.print_report(rng.random_bytes(125000))
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Complete certification (SP 800-22 + dieharder + ENT):
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
from vtrng import TestRunner
|
|
216
|
+
runner = TestRunner(rng)
|
|
217
|
+
runner.run_all()
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## CLI
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
python -m vtrng # interactive demo
|
|
226
|
+
python -m vtrng test # SP 800-22 statistical tests
|
|
227
|
+
python -m vtrng assess # SP 800-90B entropy assessment
|
|
228
|
+
python -m vtrng certify # run ALL test suites
|
|
229
|
+
python -m vtrng export -o data.bin --size 10 # export 10MB
|
|
230
|
+
python -m vtrng bench # speed benchmark
|
|
231
|
+
python -m vtrng diag # full diagnostics
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Pipe to external tools
|
|
235
|
+
|
|
236
|
+
* `dieharder`:
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
python -m vtrng export --stdout --size 20 | dieharder -a -g 200
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
* `ENT`:
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
python -m vtrng export -o random.bin --size 1 && ent random.bin
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
* `TestU01`:
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
python -m vtrng export -o random.bin --size 100
|
|
252
|
+
./testu01_vtrng random.bin crush
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
> Notes: `dieharder`, `ENT`, and `TestU01` are useful external test tools. See [docs/certification.md](/docs/certification.md) for installation and integration notes.
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## How It Works
|
|
260
|
+
|
|
261
|
+
```
|
|
262
|
+
PHYSICAL REALITY (non-deterministic)
|
|
263
|
+
┌──────────────────────────────────┐
|
|
264
|
+
│ Thermal noise in silicon │
|
|
265
|
+
│ Cache hit/miss timing │
|
|
266
|
+
│ Branch predictor state │
|
|
267
|
+
│ OS scheduler decisions │
|
|
268
|
+
│ DRAM refresh interference │
|
|
269
|
+
│ Dynamic frequency scaling │
|
|
270
|
+
│ Interrupt timing │
|
|
271
|
+
└──────────┬───────────────────────┘
|
|
272
|
+
│
|
|
273
|
+
┌──────────▼───────────────────────┐
|
|
274
|
+
│ LAYER 1: Entropy Sources │
|
|
275
|
+
│ CPU jitter · Memory timing │
|
|
276
|
+
│ Thread race conditions │
|
|
277
|
+
└──────────┬───────────────────────┘
|
|
278
|
+
│ raw timing samples
|
|
279
|
+
┌──────────▼───────────────────────┐
|
|
280
|
+
│ LAYER 2: Conditioning │
|
|
281
|
+
│ Von Neumann debiasing │
|
|
282
|
+
│ SHA-512 compression │
|
|
283
|
+
└──────────┬───────────────────────┘
|
|
284
|
+
│ clean entropy
|
|
285
|
+
┌──────────▼───────────────────────┐
|
|
286
|
+
│ LAYER 3: Entropy Pool │
|
|
287
|
+
│ 512-byte XOR mixing pool │
|
|
288
|
+
│ SHA-512 extraction + feedback │
|
|
289
|
+
└──────────┬───────────────────────┘
|
|
290
|
+
│ random bytes
|
|
291
|
+
┌──────────▼───────────────────────┐
|
|
292
|
+
│ LAYER 4: Health Monitor │
|
|
293
|
+
│ Continuous: RCT + APT │
|
|
294
|
+
│ Periodic: 9 NIST estimators │
|
|
295
|
+
│ KILLS output if failing │
|
|
296
|
+
└──────────┬───────────────────────┘
|
|
297
|
+
│ verified random bytes
|
|
298
|
+
┌──────────▼───────────────────────┐
|
|
299
|
+
│ LAYER 5: Public API │
|
|
300
|
+
│ random_bytes() · random_int() │
|
|
301
|
+
│ random_float() · shuffle() · … │
|
|
302
|
+
└──────────────────────────────────┘
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
The key insight: identical code on the same CPU produces different
|
|
306
|
+
nanosecond-precision timings every execution. This isn't a bug - it's
|
|
307
|
+
physics. Cache state, thermal throttling, and OS interrupts create
|
|
308
|
+
genuine noise at the hardware level.
|
|
309
|
+
|
|
310
|
+
This is the same principle behind Linux kernel's jitterentropy RNG.
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
## Certification
|
|
315
|
+
|
|
316
|
+
VTRNG includes three levels of statistical validation.
|
|
317
|
+
|
|
318
|
+
**Built-in (always available)**
|
|
319
|
+
|
|
320
|
+
* **NIST SP 800-90B** - 9 entropy estimators (source produces genuine entropy)
|
|
321
|
+
* **NIST SP 800-22** - 11 statistical tests (output indistinguishable from random)
|
|
322
|
+
|
|
323
|
+
**External (install separately)**
|
|
324
|
+
|
|
325
|
+
* `dieharder` - ~115 tests (`apt install dieharder`)
|
|
326
|
+
* `ENT` - 6 metrics (`apt install ent`)
|
|
327
|
+
* `TestU01` - 15–160 tests (build from source)
|
|
328
|
+
|
|
329
|
+
Run everything with one command:
|
|
330
|
+
|
|
331
|
+
```bash
|
|
332
|
+
python -m vtrng certify
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
See [docs/certification.md](/docs/certification.md) for the full certification report and reproducible test runs.
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## Performance
|
|
340
|
+
|
|
341
|
+
VTRNG is designed for **high-value randomness** (keys, tokens, seeds), not bulk data. For bulk workloads, seed a CSPRNG with VTRNG:
|
|
342
|
+
|
|
343
|
+
```python
|
|
344
|
+
import hashlib, hmac
|
|
345
|
+
|
|
346
|
+
seed = rng.random_bytes(64) # true random seed
|
|
347
|
+
# use seed with HKDF, ChaCha20, or AES-CTR for bulk generation
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## Requirements
|
|
353
|
+
|
|
354
|
+
* Python >= 3.9
|
|
355
|
+
* OS: Windows, Linux, macOS (platforms with nanosecond timers)
|
|
356
|
+
* CPU: modern CPU (x86, x86_64, ARM64, RISC-V)
|
|
357
|
+
* No runtime pip dependencies (pure Python core), optional C extension for speed
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## Security Considerations
|
|
362
|
+
|
|
363
|
+
* ✅ Continuous entropy health monitoring
|
|
364
|
+
|
|
365
|
+
* ✅ Refuses to output if health checks fail
|
|
366
|
+
|
|
367
|
+
* ✅ Forward secrecy - pool state is mutated after extractions
|
|
368
|
+
|
|
369
|
+
* ✅ No seed-file - fresh entropy collected each startup
|
|
370
|
+
|
|
371
|
+
* ⚠️ Not constant-time - avoid for timing-sensitive crypto ops
|
|
372
|
+
|
|
373
|
+
* ⚠️ VM/container behavior varies - health monitor will warn as needed
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
## Contributing
|
|
378
|
+
|
|
379
|
+
See [CONTRIBUTING.md](/CONTRIBUTING.md). We welcome:
|
|
380
|
+
|
|
381
|
+
* Bug reports and fixes
|
|
382
|
+
* New entropy sources
|
|
383
|
+
* Performance improvements
|
|
384
|
+
* Additional statistical tests
|
|
385
|
+
* Platform-specific optimizations
|
|
386
|
+
|
|
387
|
+
---
|
|
388
|
+
|
|
389
|
+
## License
|
|
390
|
+
|
|
391
|
+
MIT License - see [LICENSE](/LICENCE).
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
```python
|
|
395
|
+
# Copyright (c) 2026 TheDicee Devs
|
|
396
|
+
# SPDX-License-Identifier: MIT
|
|
397
|
+
# See LICENSE in project root.
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
## Acknowledgments
|
|
403
|
+
|
|
404
|
+
* Stephan Müller - `jitterentropy` (pioneer of CPU jitter entropy)
|
|
405
|
+
* NIST SP 800-90B and SP 800-22 - test and estimator standards
|
|
406
|
+
* BSI AIS 31 - German certification methodology
|
|
407
|
+
* The Linux kernel random subsystem maintainers
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
<div align="center">
|
|
412
|
+
VTRNG - Because your CPU is already a noise source. We just had to listen.
|
|
413
|
+
</div>
|