Skip to content

Generate ice_lite credentials with RAND_bytes() instead of random() - #195

Merged
sobomax merged 2 commits into
sippy:masterfrom
arfa-21:ice-lite-csprng-creds
Nov 27, 2026
Merged

sobomax merged 2 commits into
sippy:masterfrom
arfa-21:ice-lite-csprng-creds

Conversation

@arfa-21

@arfa-21 arfa-21 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

ice_lite takes its local ufrag/pwd from random() % 64, which can be predicted from credentials the module hands out to other callers:

  • random() is seeded once per process from 32 bits, and glibc's generator is r[i] = r[i-3] + r[i-31]. Each character exposes bits 1..6 of an output, and bit 0 is a 31-bit linear sequence whose carries show up in those bits.
  • With A the local credentials get the same length as the remote ones, so a caller who offers a 256-char ufrag and pwd gets 512 consecutive outputs back in their own answer. That is enough to solve for bit 0 and compute the ufrag/pwd of the next S/A exactly, however many random() calls the port table makes in between.
  • The local pwd is the only key for MESSAGE-INTEGRITY on binding requests, and a check that passes force-latches the stream to the sender. In the S-first flow, rufrag isn't checked until A arrives. RFC 8445 5.3 asks for at least 24 bits of randomness in the ufrag and 128 bits in the pwd. Right now the whole process has at most 32.

The bytes now come from RAND_bytes(), and the helper has moved into the module, which is its only user. ice_lite is only built with libcrypto, and dtls_gw already calls RAND_bytes(). With a 64-entry charset the 24-char pwd carries 144 bits.

Repro: a bit-exact model of glibc srandom()/random() (it matches srand(1) → 1804289383, 846930886, 1681692777) with a random seed, a random number of discarded outputs, an attacker A with 256+256 chars, then 0..15 unrelated calls and a victim S. From the attacker's 512 characters it predicts the victim's 4-char ufrag and 24-char pwd on every run, out of 16 candidates for the unknown gap. Fed RAND_bytes-style output, the same solver finds no consistent state. I compiled and exercised the new helper standalone with clang -Wall -Wextra -Werror, but couldn't build the full tree or run the test suite on this machine.

ice_lite_data_ctor() builds the local ICE ufrag and pwd with
generate_random_string(), which takes each character from random() % 64.
random() is seeded once per process from a 32-bit value and is an
additive lagged generator (r[i] = r[i-3] + r[i-31]), so the low bits of
its output are fully predictable from earlier output. The local pwd is
the only key for MESSAGE-INTEGRITY on incoming binding requests, and a
check that passes makes the module force-latch the stream to its source.

A caller who sends "A" with long ufrag/pwd gets local credentials of the
same length back in their own answer, which is enough random() % 64
output to recover the generator's low bits and compute the ufrag/pwd of
the sessions created after it, regardless of how many random() calls
the port table makes in between. RFC 8445 5.3 asks for at least 24 bits
of randomness in the ufrag and 128 bits in the pwd.

Move the helper into the module, its only user, and draw the bytes from
RAND_bytes(). The module is only built with libcrypto, and dtls_gw uses
RAND_bytes() the same way. Fail the allocation if RAND_bytes() fails.
@sobomax
sobomax force-pushed the ice-lite-csprng-creds branch 2 times, most recently from b784199 to 072c870 Compare November 26, 2026 23:46
Replace the charset[] table lookup in ice_random_string() with a
branch-light arithmetic mapping of 6 random bits onto 64 distinct
ice-chars (+, /, A-Z, a-z, 0-9), see RFC 8445 section 15.1.
@sobomax
sobomax force-pushed the ice-lite-csprng-creds branch from 072c870 to fc2ff9c Compare November 27, 2026 00:31
@sobomax
sobomax merged commit 52c03a1 into sippy:master Nov 27, 2026
167 of 168 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants