Skip to content

Commit 575844f

Browse files
scgbckbonedoc-hex
authored andcommitted
Change: use combined-source RNG for security-sensitive values
1 parent cb6dca7 commit 575844f

4 files changed

Lines changed: 7 additions & 10 deletions

File tree

releases/Next-ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This lists the new changes that have not yet been published in a normal release.
44

55
# Shared Improvements - Both Mk and Q
66

7+
- Change: Use TRNG-seeded SHA-256 Hash-DRBG for backup passwords,
8+
encryption salt/IV, and 2FA secrets; use raw TRNG for non-secret uses only.
79
- Improvements to Entropy Generation:
810
- Master seed generation mixes entropy from both Secure Elements with
911
the STM32 TRNG (previously TRNG only).

shared/backups.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# backups.py - Save and restore backup data.
44
#
5-
import compat7z, stash, ckcc, chains, gc, sys, bip39, uos, ngu
5+
import compat7z, stash, chains, gc, sys, bip39, uos, ngu
66
from ubinascii import hexlify as b2a_hex
77
from ubinascii import unhexlify as a2b_hex
88
from utils import deserialize_secret, swab32, xfp2str
@@ -310,9 +310,8 @@ async def restore_from_dict(vals, raw):
310310
async def pick_backup_password(write_sflash=False, secret_opt=False, what="money for free"):
311311
# Pick a password: like bip39 but no checksum word
312312
#
313-
b = bytearray(32)
314313
while 1:
315-
ckcc.rng_bytes(b)
314+
b = ngu.random.bytes(32)
316315
# b2a_words(32 bytes) gives 24 BIP39 words. Keep the leading 12 by dropping the tail,
317316
# which includes checksum bits; this is a wordlist password, not a valid BIP39 mnemonic.
318317
# * keep pwd as a string for the encryption/settings paths

shared/compat7z.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# always does AES-256. Not really expecting to be able to read any 7z file, except
77
# those we created ourselves.
88
#
9-
import os, sys, ckcc, ngu
9+
import os, sys, ngu
1010
from ubinascii import hexlify as b2a_hex
1111
from ubinascii import unhexlify as a2b_hex
1212
from ubinascii import crc32
@@ -19,9 +19,7 @@ def masked_crc(bits):
1919
return crc32(bits) & 0xffffffff
2020

2121
def urandom(l):
22-
rv = bytearray(l)
23-
ckcc.rng_bytes(rv)
24-
return rv
22+
return ngu.random.bytes(l)
2523

2624
def encode_utf_16_le(s):
2725
# emulate: str.encode('utf-16-le')

shared/users.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ def delete(cls, username):
177177
def pick_secret(cls, auth_mode):
178178
# always 10 bytes for no reason => 80 bits of entropy
179179
# return binary secret, and encoded value for new user to see
180-
import ckcc
181-
b = bytearray(10)
182-
ckcc.rng_bytes(b)
180+
b = ngu.random.bytes(10)
183181
picked = b32encode(b)
184182

185183
if auth_mode == USER_AUTH_HMAC:

0 commit comments

Comments
 (0)