Commit e6eb850
committed
fix(security-cryptography-random): the CSPRNG works on Emscripten, and its two messages are .NET's (#2398)
RandomNumberGenerator threw PlatformNotSupportedException on Emscripten, above
a comment reading "No secure random source wired up under Emscripten yet".
THAT PREMISE HAD ALREADY BEEN MEASURED FALSE IN THIS REPOSITORY. Guid.cpp:377-388
records #2228's finding: Emscripten's libc declares getentropy() in <unistd.h>
and implements it as __wasi_random_get(), backed by the host's
crypto.getRandomValues. So Guid::NewGuid() has been drawing real entropy on
Emscripten through exactly the call this file refused to make -- two answers to
one question inside one runtime, and the type whose entire purpose is
cryptographic randomness was the one refusing.
.NET does not refuse either: RandomNumberGeneratorImplementation.Browser.cs
forwards to Interop.GetCryptographicallySecureRandomBytes, whose __EMSCRIPTEN__
arm is SystemJS_RandomBytes (src/native/minipal/random.c:83-93).
FOUR PLATFORM ARMS BECAME TWO, AND THAT IS WHAT MAKES THE REPAIR VERIFIABLE
RATHER THAN MERELY TIDY. getrandom() is Linux-only -- undeclared on Apple/BSD,
and Emscripten declares it but backs getentropy with __wasi_random_get -- so the
old file had one arm per platform and the Linux gate compiled exactly one of
them. With a single non-Windows getentropy() loop, the code Emscripten takes is
the code Linux takes, so the gate executes it on every run. An arm no gate could
compile became an arm every gate run exercises.
Failure still throws, and that differs from Guid deliberately: NewGuid() retries
because callers treat it as infallible and an escaping exception would reach
std::terminate, while .NET throws here too (Interop.GetRandomBytes.cs:22-26).
Neither ever falls back to a weaker source.
THE LIMITATION WAS ALSO UNDECLARED: CLAUDE.md's platform table lists eight
subsystems and never listed RandomNumberGenerator, so a caller reading it would
have concluded the type worked everywhere. After this change that is correct, so
no row is added.
Two messages moved onto .NET's exact text -- GetInt32's empty range
(RandomNumberGenerator.cs:105-106, SR.Argument_InvalidRandomRange) and
verifyGetBytes's truncated SR.Argument_InvalidOffLen (:438-446), the latter also
ending a disagreement INSIDE this port, since Console.hpp already spelled .NET's
full sentence. THE EXCEPTION TYPES WERE ALREADY RIGHT AND DID NOT MOVE: .NET
uses ArgumentException with NO parameter name for the empty range, because the
fault is the relationship between two arguments rather than either one's range,
and a case asserts that shape beside the ArgumentOutOfRangeException guards.
THE SHIPPED COVERAGE COULD NOT HAVE CAUGHT ANY OF THIS: two cases asserting
buffer.size() AFTER filling a buffer whose size was fixed before the call, both
of which pass against a generator that writes nothing. Thirteen cases replace
them, including #2228's fork() distinctness idiom (a userspace PRNG has state
and fork() duplicates it) and the 256-byte chunk boundary, which the Linux gate
could not reach before this change because getrandom() has no such limit.
Eight mutations, six caught, TWO NOT CAUGHT WITH STATED REASONS. Restoring the
Emscripten throw cannot be caught here -- that arm is not compiled and there is
no Emscripten toolchain in this container; what is verified is nevertheless
stronger than before, and the residual claim is #2228's, which shipped code has
relied on since. Ignoring a getentropy() failure is unobservable in isolation,
because with chunking intact the call does not fail. One mutation was INVALID AS
FIRST WRITTEN and was reformulated rather than counted: removing the chunk cap
left maxChunk unused, so -Werror=unused-variable rejected it and the verdict
said nothing about the tests.
Landed under SA-5. No layout, vtable, signature or noexcept change and NO
OUTLAWED SPELLING, so no negative fixture was owed; the set stays 48/245 and the
graph 41/93. Downstream, measured: zero sites in both consumers.
RNGCryptoServiceProvider is SPLIT OUT AS #2399 rather than bundled -- it is
public sealed and [Obsolete] in .NET and neither here, and three of .NET's four
constructors are absent (one of which, (CspParameters?), cannot be transcribed
because CspParameters does not exist in this port). Every part of that is a
public source break or new public surface.
Gate 17,625 / 38 executables: 17,625 run, 17,625 passed, 0 failed, 0 skipped,
recounted from the per-executable logs with every executable run separately and
continuing past failures. +13 on 17,612, all in SharpRuntimeIntegrationTests
(931 -> 944) = exactly the thirteen new Rng2398* cases; no other executable
moved. Zero build warnings at --parallel 2; module boundaries green.1 parent a805603 commit e6eb850
8 files changed
Lines changed: 496 additions & 62 deletions
File tree
- docs
- modules/security-cryptography-random
- include/System/Security/Cryptography
- src/System/Security/Cryptography
- tests/integration/System/Security/Cryptography
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
| 6 | + | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
21 | 17 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
26 | 41 | | |
27 | 42 | | |
28 | 43 | | |
| |||
130 | 145 | | |
131 | 146 | | |
132 | 147 | | |
133 | | - | |
| 148 | + | |
134 | 149 | | |
135 | 150 | | |
136 | 151 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
144 | 164 | | |
145 | 165 | | |
146 | 166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
Lines changed: 13 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
82 | 88 | | |
83 | 89 | | |
84 | 90 | | |
| |||
113 | 119 | | |
114 | 120 | | |
115 | 121 | | |
116 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
117 | 128 | | |
118 | 129 | | |
119 | 130 | | |
| |||
0 commit comments