Skip to content

Add Generate Prime Number operation#2212

Open
p-leriche wants to merge 3 commits intogchq:masterfrom
p-leriche:random-prime
Open

Add Generate Prime Number operation#2212
p-leriche wants to merge 3 commits intogchq:masterfrom
p-leriche:random-prime

Conversation

@p-leriche
Copy link

Description

Generates cryptographically random probable prime numbers using the Miller-Rabin primality test, to teaching grade (7 rounds) or crypto grade (40 rounds)

Changes

  • Add GeneratePrime.mjs operation
  • Update BigIntUtils.mjs to include modPow helper function
  • Update Categories.json to include Generate Prime Number in Crypto category

Functionality

Generates random prime numbers of specified bit length (2-4096 bits) with configurable certainty levels:

Primality guarantee:

  • For numbers ≤ 3,317: Deterministic (guaranteed prime)
  • Crypto grade (40 rounds): Probability of composite < 2^-80 (~1 in 10^24)
  • Standard (7 rounds): Probability of composite < 2^-14 (~1 in 16,000)

Use Cases

  • RSA key generation (typically 1024 or 2048-bit primes)
  • Diffie-Hellman key exchange
  • Elliptic curve cryptography
  • General cryptographic applications requiring large primes

Features

  • Cryptographically secure random number generation
  • Configurable bit length (2-4096 bits)
  • Crypto grade vs. teaching grade (for educational purposes)
  • Output in decimal or hexadecimal format
  • Fully pipeable output (just the prime number)

Dependencies

Depends on BigIntUtils PR #2205

This operation uses modPow from the shared BigIntUtils library.

Testing

  • Tested with small bit lengths (8, 16, 32 bits)
  • Tested with cryptographic bit lengths (512, 1024, 2048 bits)
  • Tested both crypto grade and standard modes
  • Built successfully with npm run build

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