Skip to content

Commit 20c535e

Browse files
Merge pull request #482 from marvin-hansen/main
feat(deep_causality_rand): Added hardware secure CSPRNG
2 parents e61a2f1 + 5a49354 commit 20c535e

12 files changed

Lines changed: 2160 additions & 85 deletions

File tree

Cargo.lock

Lines changed: 159 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deep_causality_rand/Cargo.toml

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ edition = { workspace = true }
55
rust-version = { workspace = true }
66
license = { workspace = true }
77
repository = "https://github.com/deepcausality/deep_causality.rs"
8-
authors = ["Marvin Hansen <marvin.hansen@gmail.com>", ]
8+
authors = ["Marvin Hansen <marvin.hansen@gmail.com>"]
99
description = "Random number utils for for deep_causality crate."
1010
documentation = "https://docs.rs/deep_causality"
1111
categories = ["development-tools"]
1212
keywords = ["random-numbers"]
1313
# Exclude all bazel files as these conflict with Bazel workspace when vendored.
14-
exclude = ["*.bazel", "*/*.bazel", "*.bazel.*", "BUILD", "BUILD.bazel", "MODULE.bazel", ".bazelignore",".bazelrc", "tests/**/*"]
14+
exclude = [
15+
"*.bazel",
16+
"*/*.bazel",
17+
"*.bazel.*",
18+
"BUILD",
19+
"BUILD.bazel",
20+
"MODULE.bazel",
21+
".bazelignore",
22+
".bazelrc",
23+
"tests/**/*",
24+
]
1525

1626

1727
[dependencies.deep_causality_num]
@@ -20,16 +30,70 @@ version = "0.3.0"
2030

2131

2232
[features]
23-
# Enables random number generator from the host OS for secure random numbers.
33+
# Enables a secure, fast, non-NIST software CSPRNG based on the chacha20poly1305 algorith.
34+
# The chacha20poly1305 was audited by NCC Group with no significant findings.
35+
# Strongly prefer this CSPRNG implementation over os-random
36+
# due to multiple known and potentially still unknown backdors in NIST cryptography
37+
# standards and even hardware implementations of NIST Standards.
38+
#
39+
# Authenticated Encryption with Associated Data (AEAD) Algorithms
40+
# https://docs.rs/aead/latest/aead/index.html
41+
# ChaCha20Poly1305
42+
# https://github.com/RustCrypto/AEADs/tree/master/chacha20poly1305
43+
#
44+
# Hybrid Entropy
45+
# Hardware Source: 32 bytes from getrandom (OS CSPRNG
46+
# Software Source: A 64-bit entropy pool derived from:
47+
# * SystemTime (absolute epoch time, nanosecond precision)
48+
# * Instant (monotonic uptime, nanosecond precision)
49+
# * ThreadId (hashed using RandomState)
50+
# * Stack Address (ASLR memory layout)
51+
#
52+
# Mixing Function:
53+
# * The hardware seed is split into four 64-bit chunks.
54+
# * The software entropy is XORed into each chunk, rotated by a prime multiple for each chunk to avoid pattern repetition.
55+
#
56+
# Security Guarantees
57+
#
58+
# Hardware Trust: If the hardware RNG is honest, the seed is 256-bit secure. This is the current gold standard for top-secret communication
59+
# Backdoor Resistance: If the hardware RNG is backdoored (predictable), the seed is XORed
60+
# with high-resolution timing and memory layout data (Unknown ^ Known = Unknown),
61+
# breaking the adversary's ability to predict the CSPRNG state because an estiamted ~65 - 70 bits residulate entropy remain.
62+
#
63+
# Source of non-hardware entropy:
64+
# * System Time (Nanosecond precision): ~10 bits
65+
# * ASLR (Stack + Heap Address): ~40 bits
66+
# * RDTSC (CPU Cycle Counter): ~20 bits
67+
# ## Total Estimate: ~70 - 80 bits
68+
#
69+
# Even in case of a fully compromised Hardware RNG, a ~70 - 80 bits seed remains computationally infeasible
70+
# to crack for a very long time as this would require multiple super computers for a single seed.
71+
#
72+
# Motivation:
73+
# NSA backdor in NIST AES hardware acceleration: https://www.youtube.com/watch?v=LvCXBO0Vx7Q
74+
# NSA backdor in NIST AES key generation: https://www.youtube.com/watch?v=mdsoWCry23Y
75+
# NSA backdor in NIST Dual_ec_drbg: https://www.youtube.com/watch?v=xanhbvtc5bY
76+
# NSA backdor in NIST DES cypher: https://www.youtube.com/watch?v=jwKCLmzRE6o
77+
aead-random = ["chacha20poly1305", "zeroize", "getrandom"]
78+
79+
# Enables random number generator from the host OS.
2480
# Enabling os-random adds an indirect depdency on getrandom and libc.
25-
# Disabled by default to use native Rust prng instead.
81+
# Disabled by default. Use aead-random instead to protect against hardware RNG attacks.
2682
os-random = ["getrandom"]
2783

2884

2985
[dependencies.getrandom]
3086
version = "0.4"
3187
optional = true
3288

89+
[dependencies.chacha20poly1305]
90+
version = "0.10"
91+
optional = true
92+
93+
[dependencies.zeroize]
94+
version = "1.8"
95+
features = ["derive"]
96+
optional = true
3397

3498
[package.metadata.docs.rs]
3599
all-features = true

0 commit comments

Comments
 (0)