Skip to content

Make Crypt3's salt from SecureRandom - #346

Merged
trans merged 1 commit into
mainfrom
fix/crypt3-secure-salt
Nov 17, 2026
Merged

trans merged 1 commit into
mainfrom
fix/crypt3-secure-salt

Conversation

@trans

@trans trans commented Nov 17, 2026

Copy link
Copy Markdown
Member

Crypt3.generate_salt picked each character with rand, which isn't a cryptographic random source and repeats after srand. That salt is also the one Crypt3.crypt uses when it's given none. It now uses SecureRandom.random_number.

The salt's size and character set are unchanged, and so are hashes made with a given salt. securerandom ships with Ruby, and Facets already requires it in facets/digest/salted_digest.

Testing

  • A new test seeds srand twice and checks the two salts differ. It fails without the change and passes with it.
  • test/standard/test_crypt3.rb: 14 tests passing; rake test:standard and rake qed:code pass on Ruby 3.4.9.

🤖 Generated with Claude Code

generate_salt used rand, which isn't a cryptographic source and follows
srand. Facets already uses SecureRandom for salted digests.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@trans
trans merged commit 2e76920 into main Nov 17, 2026
16 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.

1 participant